VeighNa量化社区
你的开源社区量化交易平台
xyz
Member
离线
39 帖子
声望: 0

没有找到 load_ticks函数

程序是基于 example 里的 no_ui 修改而来

诡异的是大约有一半的时候下是运行到一半自行停止运行

下面是代码

判断是不是处于交易时间

from datetime import datetime, time
from config.common import log
from config.const import WEEK_DICT

Chinese futures market trading period (day/night)

DAY_START = time(8, 45)
DAY_END = time(15, 0)

NIGHT_START = time(20, 45)
NIGHT_END = time(2, 45)

大于等于6 默认是周末

WEEKEND_START = 6
today = datetime.now().weekday() + 1

def is_trading_time():
""""""
current_time = datetime.now().time()
trading = False
if (today < WEEKEND_START):
if (
(current_time >= DAY_START and current_time <= DAY_END)
or (current_time >= NIGHT_START)
or (current_time <= NIGHT_END)
):
trading = True
time = current_time.strftime("%H:%M:%S")

log.info("time:" + time + ' trading:' + str(trading))
return trading



def run_child():
"""
Running in the child process.
"""
SETTINGS["log.file"] = True
SETTINGS.update()

event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
cta_engine = main_engine.add_app(CtaStrategyApp)
main_engine.write_log("主引擎创建成功")

log_engine = main_engine.get_engine("log")
event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event)
main_engine.write_log("注册日志事件监听")

main_engine.connect(ctp_setting, "CTP")
main_engine.write_log("连接CTP接口")

sleep(10)

cta_engine.init_engine()
main_engine.write_log("CTA策略初始化完成")

cta_engine.init_all_strategies()
sleep(60)  # Leave enough time to complete strategy initialization
main_engine.write_log("CTA策略全部初始化")

cta_engine.start_all_strategies()
main_engine.write_log("CTA策略全部启动")

while True:
    sleep(60)

    trading = time_util.is_trading_time()
    if not trading:
        cta_engine.stop_all_strategies()
        log.info("关闭子进程")
        sleep(60)
        main_engine.close()
        sleep(30)
        sys.exit(0)


haha

if name == "main":
run_child()

日志截图

从日志可以看到9.11后就不再打印

description

明白,是只做了一笔盈利的交易,谢谢解答

/Users/fourdirections_vincenttang/opt/miniconda3/lib/python3.7/site-packages/vnpy/app/cta_strategy/backtesting.py:472: RuntimeWarning: divide by zero encountered in double_scalars
return_drawdown_ratio = -total_return / max_ddpercent

遇到从由 tick 数据合成 分钟 bar 时,bar 数据没有成功取得最高价的问题
从 vnpy.trader.utility.py 中提取的代码
if new_minute:
self.bar = BarData(
symbol=tick.symbol,
exchange=tick.exchange,
interval=Interval.MINUTE,
datetime=tick.datetime,
gateway_name=tick.gateway_name,
open_price=tick.last_price,
high_price=tick.last_price,
low_price=tick.last_price,
close_price=tick.last_price,
open_interest=tick.open_interest
)
else:
self.bar.high_price = max(self.bar.high_price, tick.last_price)
if tick.high_price > self.last_tick.high_price:
self.bar.high_price = max(self.bar.high_price, tick.high_price)

        self.bar.low_price = min(self.bar.low_price, tick.last_price)
        if tick.low_price < self.last_tick.low_price:
            self.bar.low_price = min(self.bar.low_price, tick.low_price)

        self.bar.close_price = tick.last_price
        self.bar.open_interest = tick.open_interest
        self.bar.datetime = tick.datetime

按当前算法,当第一个 tick的 last_price < high_price ,并且该high_price是一分钟内最大值时,
合成的分钟 bar 的 high_price 将会小于 该一分钟内实际的最大值

同理,当第一个 tick 的 last_price < low_price ,并且该low_price是一分钟内的最小值时,
合成的分钟 bar 的 low_price 将会大于该一分钟内实际的最小值

自带的DualThrustStrategy
使用
if last_bar.datetime.date() != bar.datetime.date():
作为新的一天的 k 线的判断条件,是否和平常使用的不一样
平时新的一天的 k 线都是以从夜盘开始的

尝试把CincoStrategy 用 tick 回测
on_tick 没有回调
反而 on_bar 有回调,但传过来的是DbTickData的对象

回测异常:
AttributeError: 'DbTickData' object has no attribute 'close_price'

回测程序如果下:
def run_backtesting(strategy_class, setting, vt_symbol, interval, start, end, rate, slippage, size, pricetick, capital):
engine = BacktestingEngine()
engine.set_parameters(
vt_symbol=vt_symbol,
interval=interval,
start=start,
end=end,
rate=rate,
slippage=slippage,
size=size,
pricetick=pricetick,
mode=BacktestingMode.TICK,
capital=capital
)
engine.add_strategy(strategy_class, setting)
engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()
return df

if name == "main":
df = run_backtesting(
strategy_class=CincoStrategy,
setting={},
vt_symbol="IF1912.CFFEX",
interval=Interval.TICK,
start=datetime(2019, 11, 25),
end=datetime(2019, 11, 26),
rate=0.3 / 10000,
slippage=0.2,
size=300,
pricetick=0.2,
capital=1_000_000,

)

用cta写的策略,使用了停止单,跑多个品种,想换到组合策略来,支持这样的迁移吗

组合策略怎么实现停止单
portfolio_strategy 包的 template 没有提供 stop 参数选项

请问simnow的结果有多大的参考价值

好的,谢谢群主大哥解答

看FAQ时看到:停止单到触发价时会以市价发单以实现最大的可能成交
问题一:
停止单有提供非市价发单的接口吗? 还是要自己实现

问题二:
比如从rqdata 使用1m 的数据回测
回测时使用停止单,这是不是和实盘情况有较大的差别,
回测时会以开盘成交对吧,实盘时会在k线内触发

补充一下,在simnow 行情断开的中的时间内
策略没有发过单
description

description

description

description

simonw 行情中断过,然后的逻辑的就乱了(似乎bar的时间与pos的值都不对)
策略是此前分享的R_Breaker ,在update_bar 会调用cancel_all
问题
1:过程中连续开了两个1手多单,
2:有委托没找到
3:在最后收盘时也没有平仓

这些问题在实盘中可能遇到吗

self.tend_high, self.tend_low = am.donchian(self.donchian_window)

if bar.datetime.time() < self.exit_time:

if self.pos == 0:
    self.intra_trade_low = bar.low_price
    self.intra_trade_high = bar.high_price

    if self.tend_high > self.sell_setup:
        long_entry = max(self.buy_break, self.day_high)
        self.buy(long_entry, self.fixed_size, stop=True)

        self.short(self.sell_enter, self.multiplier * self.fixed_size, stop=True)

    elif self.tend_low < self.buy_setup:
        short_entry = min(self.sell_break, self.day_low)
        self.short(short_entry, self.fixed_size, stop=True)

        self.buy(self.buy_enter, self.multiplier * self.fixed_size, stop=True)

elif self.pos > 0:
    self.intra_trade_high = max(self.intra_trade_high, bar.high_price)
    long_stop = self.intra_trade_high * (1 - self.trailing_long / 100)
    self.sell(long_stop, abs(self.pos), stop=True)

elif self.pos < 0:
    self.intra_trade_low = min(self.intra_trade_low, bar.low_price)
    short_stop = self.intra_trade_low * (1 + self.trailing_short / 100)
    self.cover(short_stop, abs(self.pos), stop=True)

Close existing position

else:
if self.pos > 0:
self.sell(bar.close_price 0.99, abs(self.pos))
elif self.pos < 0:
self.cover(bar.close_price
1.01, abs(self.pos))

vnpy内集成的log 工具吗?
回测时使用write_log 没有输出日志,把level 为10 也不输出
有没有方便的工具把log 输出到文件的

ubuntu1.9.1 替换了,运行bash install.sh
在ctp_connect.json里加上appid和authcode了
但连接ctp没反应
vnpy/api/ctp
vnpy/trader/gateway/ctpGateway

已经把下面的文件夹更换为从v1.9.2-LTS
下载的了,然后运行bash install.sh 界面可以跑起来
但连接ctp没有反应,ctp_connect.json加上appid和authcode了
vnpy/api/ctp
vnpy/trader/gateway/ctpGateway

通过vn station使用 2.0.3,价差交易入口没找到.是去掉了吗

© 2015-2022 微信 18391752892
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】