Skip to content

Commit

Permalink
Merge branch 'dev-v1.1.21' into fix-gateway-unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam authored and Cam committed Jul 27, 2019
2 parents d899802 + 7b56a3f commit e015aa3
Show file tree
Hide file tree
Showing 6 changed files with 605 additions and 92 deletions.
36 changes: 36 additions & 0 deletions example/run_ga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from vnpy.trader.app.ctaStrategy.ctaBacktesting import OptimizationSetting
from vnpy.trader.app.ctaStrategy import BacktestingEngine
from StrategyBollBand import BollBandsStrategy as Strategy
import json
from datetime import datetime

if __name__ == "__main__":
engine = BacktestingEngine()
# 设置回测用的数据起始日期
engine.setStartDate('20190401 23:00:00')
engine.setEndDate('20190430 23:00:00')
# 设置产品相关参数
contracts = [
{"symbol":"eos.usd.q:okef",
"size" : 10,
"priceTick" : 0.001,
"rate" : 5/10000,
"slippage" : 0.005
}]

engine.setContracts(contracts) # 设置回测合约相关数据

# 设置使用的历史数据库
engine.setDB_URI("mongodb://192.168.0.104:27017")
engine.setDatabase("VnTrader_1Min_Db")
engine.setCapital(100) # 设置起始资金,默认值是1,000,000

with open("CTA_setting.json") as parameterDict:
params = json.load(parameterDict)
engine.initStrategy(Strategy, params[0])

setting = OptimizationSetting()
setting.setOptimizeTarget("sharpe_ratio")
setting.addParameter('bBandPeriod', 12, 20, 2) # 增加第一个优化参数atrLength,起始12,结束20,步进2

engine.run_ga_optimization(setting)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ websocket-client==0.48.0
qdarkstyle
SortedContainers
pandas>=0.23
deap
flask-restful
flask-socketio
aiohttp
Expand Down
Loading

0 comments on commit e015aa3

Please sign in to comment.