vn.py量化社区
By Traders, For Traders.
Administrator
avatar
加入于:
帖子: 163
声望: 21

策略开发的第一步,永远是对行情数据进行画图。

from datetime import datetime
from vnpy.trader.constant import Exchange,Interval
from vnpy.trader.database import database_manager
import matplotlib.pyplot as plt

# Load history data
bars =database_manager.load_bar_data(    
    symbol="XBTUSD", 
    exchange=Exchange.BITMEX, 
    interval=Interval.MINUTE, 
    start=datetime(2017, 4, 1), 
    end=datetime(2019, 10, 30)
    )

# Generate x, y
y = []
for bar in bars:
    close_price = bar.close_price
    y.append(close_price)  
x = list(range(1,len(y)+1))

# Show foto
plt.figure(figsize=(40, 20))
plt.plot(x, y)  

plt.show()

description

 

附:若是24小时交易,需要查看是否有缺失数据,x轴和y轴数据可以改成下面这样

# generate x, y
x=[]
y = []
for bar in bars:
    time = bar.datetime
    close_price = bar.close_price

    x.append(time)
    y.append(close_price)
Member
加入于:
帖子: 84
声望: 19

借花献佛吧,我最近也是用Jupyter Notebook做数据初分析多,这里接受下加入ta-lib分析数据方法,
直接在代码后面加入就可以使用,当然也可以自己加上更多

logdata = pd.DataFrame()
logdata['close'] =(y)
logdata['std20'] = talib.STDDEV( np.array(dfrb8888['close']) ,20)
logdata['rsi30'] = talib.RSI(np.array(dfrb8888['close']) ,30)
logdata['sma5'] = talib.SMA(np.array(dfrb8888['close']) ,5)
logdata['sma40'] = talib.SMA(np.array(dfrb8888['close']) ,40)
logdata.plot(subplots=True,figsize=(18,16))

description

Member
加入于:
帖子: 84
声望: 19

还有一个,是加入卖出买入标志,这里用简单快慢均线穿插,接着上面的代码如下
description

listup,listdown = [],[]
for i in range(1,len(logdata['close'])):
    if logdata.loc[i,'sma5'] > logdata.loc[i,'sma40'] and logdata.loc[i-1,'sma5'] < logdata.loc[i-1,'sma40']:
        listup.append(i)
    elif logdata.loc[i,'sma5'] < logdata.loc[i,'sma40'] and logdata.loc[i-1,'sma5'] > logdata.loc[i-1,'sma40']:
        listdown.append(i)
fig=plt.figure(figsize=(18,6))
plt.plot(closeArray, color='y', lw=2.)
plt.plot(closeArray, '^', markersize=5, color='r', label='UP signal', markevery=listup)
plt.plot(closeArray, 'v', markersize=5, color='g', label='DOWN signal', markevery=listdown)
plt.legend()
plt.show()
Member
avatar
加入于:
帖子: 27
声望: 0

用停止单进场的话,不太好标记入场点吧

Member
avatar
加入于:
帖子: 17
声望: 0

王大雷 wrote:

用停止单进场的话,不太好标记入场点吧
标记应该用的是成交信息

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3