关于现货期权合约交易所系统开发详细逻辑及方案分析
Want to know clearly what is a quantitative trading robot?First of all,we should clarify the basic concept of quantitative trading: Quantitative trading refers to an investment method that uses modern statistics and mathematical methods to trade through computer technology.Quantitative trading selects a variety of"high probability"events that can achieve excess returns from massive historical data to formulate strategies,uses quantitative models to verify and solidify these laws and strategies,and then strictly implements the solidified strategies to guide investment,in order to obtain sustained,stable and higher than average returns. 入口代码为vnpy.app.cta_backtester.ui.widget.BacktesterManager.start_backtesting()方法.获取界面配置的合约相关参数,弹窗vnpy.app.cta_backtester.ui.widget.BacktestingSettingEditor对话框,用户确认后,调用vnpy.app.cta_backtester.engine.BacktesterEngine.start_backtesting()开始回测,该方法开启新线程调用run_backtesting().此方法调用逻辑如下:开发详情I35设计7o98逻辑o7I8 1.获取vnpy.app.cta_strategy.backtesting.BacktestingEngine类对象,传入界面参数. 2.调用vnpy.app.cta_strategy.backtesting.BacktestingEngine.load_data()方法加载数据.根据是bar模式还是tick模式,调用load_bar_data()和load_tick_data()加载数据到self.history_data的list中。默认bar模式,进入vnpy.app.cta_strategy.backtesting.load_bar_data(),调用vnpy.trader.database.database_sql.SqlManager.load_bar_data(),它通过peewee的orm库读取数据库. 3.调用vnpy.app.cta_strategy.backtesting.BacktestingEngine.run_backtesting()开始回测. (1).根据bar还是tick模式,确认进入BacktestingEngine.new_bar()还是BacktestingEngine.new_tick()方法. (2).进入vnpy.app.cta_strategy.strategies.double_ma_strategy.DoubleMaStrategy.on_init()初始化策略.进入vnpy.app.cta_strategy.template.CtaTemplate.load_bar()初始化加载.案例分析:mrsfu123 (3).遍历历史K线数据,统计总天数.如果是一个月的分钟线,针对前10根K线(这块没看懂?),每一根K线都进入double_ma_strategy.DoubleMaStrategy.on_bar()方法处理。首先调用vnpy.trader.utility.ArrayManager.update_bar()更新当前K线信息.然后计算短期和长期均线价格,如果短期上穿长期均线,且当前仓位为0,则调用template.CtaTemplate.buy()方法下单买入.下单进入vnpy.app.cta_strategy.template.CtaTemplate.send_order()方法,回测期间该方法返回空.如果短期下穿长期均线,且当前仓位为0,调用vnpy.app.cta_strategy.template.CtaTemplate.short()做空. (4).调用double_ma_strategy