This commit is contained in:
msincenselee 2015-11-13 15:59:25 +08:00
parent a1050d84f6
commit 3f082b40f7
7 changed files with 19 additions and 17 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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))

View File

@ -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)

View File

@ -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:

View File

@ -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"
}

Binary file not shown.

View File

@ -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: