都搜索不到了
Q:有微信群,QQ群吗?
A:vn.py框架学习群:666359421 ; vn.py框架交流群:262656087
自己写了一个策略,回测时总是没有回测起始日数据,请问可能是什么原因呢?按照策略逻辑,肯定是应该有交易的。比如下图,策略从19日开始,首个交易日就是22日,19日无交易,但是我把回测日期调到18日开始,19日就有交易了。
CSV分钟线也是从VNPY导出来的(另外一台电脑的),新导入了(2.9.0版本)就出错。
不用导入,直接用udata下载的话,也是报这个错误。VNPY是卸载了原来的2.5版本,新安装的2.9版本。请问是怎么回事呢?
Traceback (most recent call last):
File "c:\vnstudio\lib\site-packages\peewee.py", line 3160, in execute_sql
cursor.execute(sql, params or ())
sqlite3.OperationalError: table dbbardata has no column named turnover
写了一个网格交易的策略,回测的时候,最大回撤都无穷大了,请问是怎么回事呢?
from vnpy.app.cta_strategy import (
CtaTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
import math
class GridStrategy(CtaTemplate):
""""""
author = "Fighter"
#定义参数
initial_price = 1.0
step_price = 1.0
step_volume = 1.0
max_pos = 4
vt_orderid = ""
pos = 0
parameters = ["initial_price", "step_price", "step_volume", "max_pos"]
variables = ["pos", "vt_orderid"]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
""""""
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
self.bg = BarGenerator(self.on_bar)
self.am = ArrayManager()
def on_init(self):
"""
Callback when strategy is inited.
"""
self.write_log("策略初始化")
self.load_bar(1)
self.pos = 0
def on_start(self):
"""
Callback when strategy is started.
"""
self.write_log("策略启动")
self.put_event()
def on_stop(self):
"""
Callback when strategy is stopped.
"""
self.write_log("策略停止")
self.put_event()
def on_tick(self, tick: TickData):
"""
Callback of new tick data update.
"""
self.bg.update_tick(tick)
def on_bar(self, bar: BarData):
"""
Callback of new bar data update.
"""
#self.bg.update_bar(bar)
#self.cancel_all()
am = self.am
am.update_bar(bar)
if not am.inited:
return
if self.initial_price > bar.close_price:
# 价格在基准价之上时
# 计算当前K线收盘价与初始价的距离
target_buy_distance = (self.initial_price - bar.close_price) / self.step_price
# 计算当前价位应该持有的仓位,取整。再和最大仓位置比较
target_buy_position = min(math.floor(target_buy_distance) * self.step_volume, self.max_pos)
# 当前应该持有的仓位减去原有持仓就是该再买入的仓位
target_buy_volume = target_buy_position - self.pos
# Buy when price dropping
if target_buy_volume > 0:
self.buy(bar.close_price, target_buy_volume)
# Sell when price rising
elif target_buy_volume < 0:
self.sell(bar.close_price, target_buy_volume)
elif self.initial_price < bar.close_price:
# 价格在基准价之下时
target_buy_distance = (bar.close_price - self.initial_price) / self.step_price
target_buy_position = - min(math.floor(target_buy_distance) * self.step_volume, self.max_pos)
target_buy_volume = target_buy_position - self.pos
# Buy when price dropping
if target_buy_volume > 0:
self.buy(bar.close_price, target_buy_volume)
# Sell when price rising
elif target_buy_volume < 0:
self.sell(bar.close_price, target_buy_volume)
# Update UI
#self.put_variables_event()
def on_order(self, order: OrderData):
"""
Callback of new order data update.
"""
pass
def on_trade(self, trade: TradeData):
"""
Callback of new trade data update.
"""
self.put_event()
def on_stop_order(self, stop_order: StopOrder):
"""
Callback of stop order update.
"""
pass
GitHub安装后的功能要少一些呢
用行情记录来记录价差的tick。
谢谢指导!
buy_price/sell_price/cover_price/short_prie:四个方向的交易价格,比如buy_price 是看价差中的买价还是卖价呢?
实际建仓的时候,实际上是以建立的价差中的卖价成交的。平仓的时候,又是以建立的价差中的买价成交的。
查了一下,说可能是网络读失败,APP版本和服务器备案版本不对。
该怎么改呢?
我是按照教程填写的
用户名username:111111 (6位纯数字账号)
密码password:1111111 (需要修改一次密码用于盘后测试)
经纪商编号brokerid:9999 (SimNow默认经纪商编号)
交易服务器地址td_address:218.202.237.33 :10102 (盘中测试)
行情服务器地址md_address:218.202.237.33 :10112 (盘中测试)
授权码auth_code:0000000000000000(16个0)
名称app_id:simnow_client_test