2015-05-28 05:52:59 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
from strategyEngine import *
|
|
|
|
from backtestingEngine import *
|
|
|
|
from demoStrategy import SimpleEmaStrategy
|
2015-10-07 16:27:06 +00:00
|
|
|
import decimal
|
2015-05-28 05:52:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 回测脚本
|
|
|
|
if __name__ == '__main__':
|
2015-10-07 16:27:06 +00:00
|
|
|
#symbol = 'IF1506'
|
|
|
|
symbol = 'a'
|
2015-05-28 05:52:59 +00:00
|
|
|
|
|
|
|
# 创建回测引擎
|
|
|
|
be = BacktestingEngine()
|
|
|
|
|
|
|
|
# 创建策略引擎对象
|
|
|
|
se = StrategyEngine(be.eventEngine, be, backtesting=True)
|
|
|
|
be.setStrategyEngine(se)
|
|
|
|
|
|
|
|
# 初始化回测引擎
|
2015-10-07 16:27:06 +00:00
|
|
|
#be.connectMongo()
|
|
|
|
be.connectMysql()
|
|
|
|
#be.loadMongoDataHistory(symbol, datetime(2015,5,1), datetime.today())
|
|
|
|
#be.loadMongoDataHistory(symbol, datetime(2012,1,9), datetime(2012,1,14))
|
|
|
|
be.loadMysqlDataHistory(symbol, datetime(2012,1,9), datetime(2012,1,20))
|
|
|
|
|
2015-05-28 05:52:59 +00:00
|
|
|
# 创建策略对象
|
|
|
|
setting = {}
|
|
|
|
setting['fastAlpha'] = 0.2
|
2015-10-07 16:27:06 +00:00
|
|
|
setting['slowAlpha'] = 0.05
|
|
|
|
#setting['startDate'] = datetime(year=2015, month=5, day=20)
|
|
|
|
setting['startDate'] = datetime(year=2012, month=1, day=9)
|
|
|
|
|
2015-05-28 05:52:59 +00:00
|
|
|
se.createStrategy(u'EMA演示策略', symbol, SimpleEmaStrategy, setting)
|
2015-10-07 16:27:06 +00:00
|
|
|
|
2015-05-28 05:52:59 +00:00
|
|
|
# 启动所有策略
|
|
|
|
se.startAll()
|
2015-10-07 16:27:06 +00:00
|
|
|
|
2015-05-28 05:52:59 +00:00
|
|
|
# 开始回测
|
|
|
|
be.startBacktesting()
|
2015-10-07 16:27:06 +00:00
|
|
|
|
2015-05-28 05:52:59 +00:00
|
|
|
|