掘金社区

回测时没有交易,如何解决?Pinned highlighted

181619***917 发表在掘金2 2016-05-12 06:56:09

掘金2
558
1
0

-- coding: utf-8 --

from gmsdk.api import StrategyBase

class Mystrategy(StrategyBase):
def init(self, *args, **kwargs):
super(Mystrategy, self).init(*args, **kwargs)
#self.LastClose = 0.0
self.oc = True

def on_bar(self, bar):
    print ("test")
    if self.oc :
        self.open_long("SHFE", "rb1409", bar.close, 3)
    else :
        self.close_long("SHFE", "rb1409", bar.close, 3)
    self.oc = not self.oc
    
    pass

if name == 'main':
myStrategy = Mystrategy(
username='',
password='
',
strategy_id='c85257d6-1756-11e6-a7c0-780cb8be7fa3',
subscribe_symbols='SHFE.rb1409.bar.60',
mode=4,
td_addr='localhost:8001'
)
myStrategy.backtest_config(
start_time='2015-01-28 14:10:00',
end_time='2015-05-11 13:05:00',
initial_cash=10000,
transaction_ratio=1,
commission_ratio=0.01,
slippage_ratio=0.1,
price_type=0)
ret = myStrategy.run()
print('exit code: ', ret)

请问这段代码在回测时没有任何交易,怎么办呢?

------编辑下。。已解决是由于品种日期设置问题。

评论: 1

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.