@Channelchan
2018-12-04T16:20:26.000000Z
字数 2567
阅读 59808
min_data数据下载:
链接:https://pan.baidu.com/s/1OBTX-zc2GfsGutlEeoznJg
提取码:uz91
import warningswarnings.filterwarnings('ignore')from jaqs_fxdayu.data.dataservice import LocalDataServiceds = LocalDataService()from time import time## 加freq参数start = time()path = './min_data/VnTrader_1Min_Db'props = {'fields': 'open,high,low,close,volume','symbol':'EOSUSDT:binance','freq': '15Min,25Min','start_date':20180601000000}Time_dict = ds.bar_reader(path,props) #读取数据print(time()-start)
6.14521598815918
df = Time_dict['15Min'].dropna().set_index("datetime")
import matplotlib.pyplot as pltplt.figure(figsize=(20,10))plt.plot(df.close)plt.show()

import pandas as pdimport numpy as npimport osimport talib as taimport matplotlib.pyplot as pltdf1 = Time_dict['15Min'].dropna().set_index("datetime")
df1['upband'] = ta.MAX(df1['close'].values,16)df1['downband'] = ta.MIN(df1['close'].values,16)
df1['upband'] = df1['upband'].shift(1)df1['downband'] = df1['downband'].shift(1)
fig, ax1 = plt.subplots(figsize=(15, 7))plt.plot(df1[['close','upband','downband']].loc['20180901':'20180911',])plt.grid(True)plt.axis('tight')plt.xlabel('date')plt.ylabel('Price 1nd')plt.title('two stock')plt.show()

df1['signal1'] = np.where(df1['close']>df1['upband'],1,np.where(df1['close']<df1['downband'],-1,0))
fig, ax1 = plt.subplots(figsize=(15, 7))plt.plot(df1[['close']].loc['20180901':'20180911',])plt.grid(True)plt.axis('tight')plt.xlabel('date')plt.ylabel('Price 1nd')plt.title('two stock')ax2 = ax1.twinx() #双坐标plt.plot(df1[['signal1']].loc['20180901':'20180911',],'r')# plt.plot(df1[['signal6']].loc['20180801':'20180811',],'g')plt.ylabel('Price 2nd')plt.show()

df1['atr20'] = ta.ATR(df1['high'].values,df1['low'].values,df1['close'].values,14)df1['atr50'] = ta.ATR(df1['high'].values,df1['low'].values,df1['close'].values,76)
df1['signal2'] = np.where(df1['atr20']>=df1['atr50'],1,0)df1['signal3'] = np.where(df1['signal2']==1,df1['signal1'],0)
fig, ax1 = plt.subplots(figsize=(15, 7))plt.plot(df1[['close','upband','downband']].loc['20180901':'20180911',])plt.grid(True)plt.axis('tight')plt.xlabel('date')plt.ylabel('Price 1nd')plt.title('two stock')ax2 = ax1.twinx() #双坐标plt.plot(df1[['signal3']].loc['20180901':'20180911',],'r')# plt.plot(df1[['signal2']].loc['20180901':'20180911',],'g')plt.ylabel('Price 2nd')plt.show()

