掘金社区
-- coding: utf-8 --
from gmsdk.api import StrategyBase
LastClose = 0.0
class Mystrategy(StrategyBase):
def init(self, *args, **kwargs):
super(Mystrategy, self).init(*args, **kwargs)
def on_bar(self, bar):
print (bar.close)
print (LastClose)
if LastClose > bar.close :
self.open_long("SHFE", "rb00", bar.close, 3)
else :
self.close_long("SHFE", "rb00", bar.close, 3)
LastClose = bar.close
pass
if name == 'main':
myStrategy = Mystrategy(
username='18161903917',
password='Ma883125ma',
strategy_id='c85257d6-1756-11e6-a7c0-780cb8be7fa3',
subscribe_symbols='SHFE.rb00.bar.60',
mode=4,
td_addr='localhost:8001'
)
myStrategy.backtest_config(
start_time='2014-01-28 14:10:00',
end_time='2016-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)
请问这段代码中close价格上涨就开仓,下跌就平仓,为什么回测可以运行,但是结果中发现没有产生任何交易呢?