现货期权合约交易所开发需求丨现货期权合约交易所系统开发(实现技术及代码)
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().此方法调用逻辑如下:
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()初始化加载.
(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.DoubleMaStrategy.on_start()触发start事件.
(5).调用BacktestingEngine.new_bar()从第10根K线开始回放历史数据.该方法处理逻辑如下:
(5.1)调用BacktestingEngine.cross_limit_order()撮合本地限价单委托,将最新的行情K线或者TICK和策略之前下达的所有委托进行检查,如果能够撮合成交,则返回并记录数据。
(5.2)撮合本地停止单(条件单)委托.
K线图表
入口代码为BacktesterManager.show_candle_chart().获取之前加载的数据库里面的bar数据。
1.调用CandleChartDialog.update_history(),调用vnpy.chart.manager.BarManager.update_history(),调用vnpy.chart.item.ChartItem.update_history()遍历所有K线,调用vnpy.chart.item.CandleItem._draw_bar_picture()通过QT画K线图.
2.获取所有交易记录,调用widget.CandleChartDialog.update_trades()在K线图上标记买卖记录.
相关文章
- 使用 Amazon Textract 与 Amazon Comprehend 从文档中提取自定义实体
- SNCF Réseau 和 Olexya 如何将 Caffe2 计算机视觉流水线任务迁移至 Amazon SageMaker 中的 Managed Spot Training
- 使用 Amazon SageMaker 与 Deep Graph Library 在异构网络中检测欺诈活动
- 在 Amazon SageMaker Service 中使用 R 绘制统计过程控制图(SPC)实现流程稳定性预警
- 用自己的数据在 AWS DeepComposer 中创建音乐流派模型
- 将 Amazon SageMaker 与 Amazon Augmented AI 结合使用以人工查看表格数据和机器学习预测
- Verizon Media Group 如何从本地 Apache Hadoop 与 Spark 迁移至 Amazon EMR
- 通过 Amazon Forecast 建立 MLOps 体系,实现 AI 赋能的预测自动化
- 在 Amazon SageMaker Ground Truth 中标记数据,以实现 3D 对象跟踪与传感器融合
- 如何使用 Apache Spark 与 Amazon EMR 改善 FRTB 的内部模型方法实现
- Amazon Managed Streaming for Apache Kafka (MSK) 迎来通用版本
- Drop 如何使用 Amazon EMR for Spark 实现成本减半,并将处理速度提升5.4倍
- 使用 Amazon SageMaker Model Monitor 与 Debugger 检测并分析不正确的模型预测结果
- 使用 AWS WAF 完整日志、Amazon Athena 以及 Amazon QuickSight 实现无服务器安全分析
- 如何使用 Amazon Elasticsearch Service 分析 AWS WAF 日志
- 使用 Spark 与 Apache Arrow 同时训练多个机器学习模型
- 使用 Amazon AppFlow 与 Amazon Athena 分析 Google Analytics 数据
- 了解并使用13款 AWS 安全工具,遵循 SEC 建议保护云端客户数据
- 使用角色链限制 Amazon Redshift IAM 角色和组对 Amazon Redshift Spectrum 外部表访问
- 使用 Amazon Forecast 自动补全机制管理目标与相关数据集中的缺失值