diff --git a/.gitignore b/.gitignore index dabaa9a9..82766f0e 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,5 @@ tk.csv vn.strategy/strategydemo/backtestingStrategy02.py vn.strategy/strategydemo/strategy01.py vn.strategy/strategydemo/strategy02.py +vn.trader/CTP_connect.json +*.vt diff --git a/vn.strategy/strategydemo/backtestingEngine.py b/vn.strategy/strategydemo/backtestingEngine.py index 95588403..1ccee708 100644 --- a/vn.strategy/strategydemo/backtestingEngine.py +++ b/vn.strategy/strategydemo/backtestingEngine.py @@ -440,7 +440,7 @@ class BacktestingEngine(object): self.writeLog(u'开始回测,{0}'.format(str(t1 ))) # 每次获取日期周期 - intervalDays = 30 + intervalDays = 20 for i in range (0,(self.endDate - self.startDate).days +1, intervalDays): d1 = self.startDate + timedelta(days = i ) @@ -476,8 +476,6 @@ class BacktestingEngine(object): # 保存交易到数据库中 self.saveTradeDataToMysql() - - t2 = datetime.now() self.writeLog(u'回测结束,{0},耗时:{1}秒'.format(str(t2),(t2-t1).seconds)) diff --git a/vn.strategy/strategydemo/demoBacktesting.py b/vn.strategy/strategydemo/demoBacktesting.py index ac210a5e..bf114ff3 100644 --- a/vn.strategy/strategydemo/demoBacktesting.py +++ b/vn.strategy/strategydemo/demoBacktesting.py @@ -8,7 +8,7 @@ import decimal def main(): """回测程序主函数""" # symbol = 'IF1506' - symbol = 'a' + symbol = 'au' # 创建回测引擎 be = BacktestingEngine() @@ -23,14 +23,14 @@ def main(): # be.loadMongoDataHistory(symbol, datetime(2015,5,1), datetime.today()) # be.loadMongoDataHistory(symbol, datetime(2012,1,9), datetime(2012,1,14)) - be.setDataHistory(symbol, datetime(2012,1,1), datetime(2012,12,31)) + be.setDataHistory(symbol, datetime(2015,7,3), datetime(2015,7,30)) # 创建策略对象 setting = {} setting['fastAlpha'] = 0.2 - setting['slowAlpha'] = 0.05 + setting['slowAlpha'] = 0.05 # setting['startDate'] = datetime(year=2015, month=5, day=20) - setting['startDate'] = datetime(year=2012, month=1, day=1) + setting['startDate'] = datetime(year=2015, month=7, day=3) se.createStrategy(u'EMA演示策略', symbol, SimpleEmaStrategy, setting) diff --git a/vn.strategy/strategydemo/demoStrategy.py b/vn.strategy/strategydemo/demoStrategy.py index 67fd4a6b..403a3412 100644 --- a/vn.strategy/strategydemo/demoStrategy.py +++ b/vn.strategy/strategydemo/demoStrategy.py @@ -337,17 +337,19 @@ class SimpleEmaStrategy(StrategyTemplate): #---------------------------------------------------------------------- def saveData(self, id): """保存过程数据""" + pass + # 保存K线 - print u'{0}保存K线'.format(self.name) - self.engine.saveBarToMysql(id, self.lineBar) + # print u'{0}保存K线'.format(self.name) + # self.engine.saveBarToMysql(id, self.lineBar) # 保存快速EMA和慢速EMA - self.engine.saveEmaToMysql(id, self.lineEMA) + # self.engine.saveEmaToMysql(id, self.lineEMA) #---------------------------------------------------------------------- def __dailyCloseMarket(self, o, t): """每日收市平仓""" - if not (t.hour == 14 and t.minute == 55): + if not ((t.hour == 14 and t.minute == 55) or (t.hour == 2 and t.minute == 25)): return if self.pos > 0: diff --git a/vn.trader/CTP_connect.json b/vn.trader/CTP_connect.json index ab85621c..4b6efa7b 100644 --- a/vn.trader/CTP_connect.json +++ b/vn.trader/CTP_connect.json @@ -1,7 +1,7 @@ { - "brokerID": "9999", - "tdAddress": "tcp://180.168.146.187:10000", - "password": "jiajia", - "mdAddress": "tcp://180.168.146.187:10010", - "userID": "033513" + "brokerID": "8070", + "tdAddress": "tcp://180.168.214.246:41213", + "password": "154815", + "mdAddress": "tcp://180.168.214.246:41205", + "userID": "887733" } \ No newline at end of file diff --git a/vn.trader/ContractData.vt b/vn.trader/ContractData.vt index b22359c6..1ba82750 100644 Binary files a/vn.trader/ContractData.vt and b/vn.trader/ContractData.vt differ diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index b6fee18e..fc07f250 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -773,7 +773,7 @@ class TradingWidget(QtGui.QFrame): vtSymbol = '.'.join([symbol, exchange]) contract = self.dataEngine.getContract(vtSymbol) else: - + vtSymbol = symbol contract = self.dataEngine.getContract(symbol) if contract: