diff --git a/Config/demo_config.yaml b/Config/demo_config.yaml index e4f2f48..54a35f5 100644 --- a/Config/demo_config.yaml +++ b/Config/demo_config.yaml @@ -33,6 +33,8 @@ Trade: open_score_tolerance: 0.03 # absolute chan_begin_date: 2015-01-01 latest_ipo_date: 2021-01-01 + touch_sl_cnt: 1 + touch_sw_cnt: 1 Notion: cn_id: xxx @@ -41,8 +43,21 @@ Notion: token: xxx Model: - model_tag: bsp_label-scale - model_type: normal # normal/area/bs_type + model_tag: label-scale # 开仓/后验如果没配置才取这个值 + model_type: bs_type # normal/area/bs_type, 开仓/后验时不起作用 Chan: - debug: false \ No newline at end of file + debug: false + +COS: + cos_type: xxx # tencent/minio + tencent_cos: + secretid: xxx + secretkey: xxx + region: ap-xxx + bucket: chan-xxx + minio: + endpoint: xxxx.com + access_key: xxx + secret_key: xxx + bucket: xxx \ No newline at end of file diff --git a/Image/chan.py_image_10.png b/Image/chan.py_image_10.png index 5d03346..5990be0 100644 Binary files a/Image/chan.py_image_10.png and b/Image/chan.py_image_10.png differ diff --git a/Image/chan.py_image_11.png b/Image/chan.py_image_11.png index 1a4677f..97f2568 100644 Binary files a/Image/chan.py_image_11.png and b/Image/chan.py_image_11.png differ diff --git a/Image/chan.py_image_12.png b/Image/chan.py_image_12.png index 8998ceb..392aab9 100644 Binary files a/Image/chan.py_image_12.png and b/Image/chan.py_image_12.png differ diff --git a/Image/chan.py_image_13.png b/Image/chan.py_image_13.png index 3834524..1905bb8 100644 Binary files a/Image/chan.py_image_13.png and b/Image/chan.py_image_13.png differ diff --git a/Image/chan.py_image_14.png b/Image/chan.py_image_14.png index e52f0b3..7ebf017 100644 Binary files a/Image/chan.py_image_14.png and b/Image/chan.py_image_14.png differ diff --git a/Image/chan.py_image_15.png b/Image/chan.py_image_15.png index e62e8ed..b3956c2 100644 Binary files a/Image/chan.py_image_15.png and b/Image/chan.py_image_15.png differ diff --git a/Image/chan.py_image_16.png b/Image/chan.py_image_16.png index 3527790..bf2448b 100644 Binary files a/Image/chan.py_image_16.png and b/Image/chan.py_image_16.png differ diff --git a/Image/chan.py_image_17.png b/Image/chan.py_image_17.png index 32f0b1f..d3591ad 100644 Binary files a/Image/chan.py_image_17.png and b/Image/chan.py_image_17.png differ diff --git a/Image/chan.py_image_18.png b/Image/chan.py_image_18.png index 8ce7c6c..50c227d 100644 Binary files a/Image/chan.py_image_18.png and b/Image/chan.py_image_18.png differ diff --git a/Image/chan.py_image_2.png b/Image/chan.py_image_2.png index 211fe48..82fa1c5 100644 Binary files a/Image/chan.py_image_2.png and b/Image/chan.py_image_2.png differ diff --git a/Image/chan.py_image_3.png b/Image/chan.py_image_3.png index a246cb0..0a40484 100644 Binary files a/Image/chan.py_image_3.png and b/Image/chan.py_image_3.png differ diff --git a/Image/chan.py_image_4.png b/Image/chan.py_image_4.png index 17b027d..d7bcdb9 100644 Binary files a/Image/chan.py_image_4.png and b/Image/chan.py_image_4.png differ diff --git a/Image/chan.py_image_5.png b/Image/chan.py_image_5.png index 965dfac..d63018a 100644 Binary files a/Image/chan.py_image_5.png and b/Image/chan.py_image_5.png differ diff --git a/Image/chan.py_image_6.gif b/Image/chan.py_image_6.gif index baa4fd6..aa37fb1 100644 Binary files a/Image/chan.py_image_6.gif and b/Image/chan.py_image_6.gif differ diff --git a/Image/chan.py_image_7.png b/Image/chan.py_image_7.png index b23d49b..e8683f8 100644 Binary files a/Image/chan.py_image_7.png and b/Image/chan.py_image_7.png differ diff --git a/Image/chan.py_image_8.png b/Image/chan.py_image_8.png index 51e980d..73b7d8d 100644 Binary files a/Image/chan.py_image_8.png and b/Image/chan.py_image_8.png differ diff --git a/Image/chan.py_image_9.png b/Image/chan.py_image_9.png index 323640a..48f0f13 100644 Binary files a/Image/chan.py_image_9.png and b/Image/chan.py_image_9.png differ diff --git a/Image/chan_bilibili.png b/Image/chan_bilibili.png index 5a381c4..ade07f7 100644 Binary files a/Image/chan_bilibili.png and b/Image/chan_bilibili.png differ diff --git a/Image/chan_coding_time.png b/Image/chan_coding_time.png index 14ca2ce..efc1fef 100644 Binary files a/Image/chan_coding_time.png and b/Image/chan_coding_time.png differ diff --git a/Image/chan_commit_cnt.png b/Image/chan_commit_cnt.png index 1f721d8..8098a49 100644 Binary files a/Image/chan_commit_cnt.png and b/Image/chan_commit_cnt.png differ diff --git a/Image/chan_gotify_info.png b/Image/chan_gotify_info.png index e15ac13..dcff656 100644 Binary files a/Image/chan_gotify_info.png and b/Image/chan_gotify_info.png differ diff --git a/Image/chan_issue_cnt.png b/Image/chan_issue_cnt.png index d31d813..2804903 100644 Binary files a/Image/chan_issue_cnt.png and b/Image/chan_issue_cnt.png differ diff --git a/Image/chan_qujiantao.png b/Image/chan_qujiantao.png index 4ceb147..8b55141 100644 Binary files a/Image/chan_qujiantao.png and b/Image/chan_qujiantao.png differ diff --git a/Image/chan_trendline.png b/Image/chan_trendline.png index cbcb7ba..4722260 100644 Binary files a/Image/chan_trendline.png and b/Image/chan_trendline.png differ diff --git a/Image/feature_cnt.png b/Image/feature_cnt.png index 57972f7..e470ad4 100644 Binary files a/Image/feature_cnt.png and b/Image/feature_cnt.png differ diff --git a/Image/futu_sim_snapshot.png b/Image/futu_sim_snapshot.png index c25c9ee..09d4dfe 100644 Binary files a/Image/futu_sim_snapshot.png and b/Image/futu_sim_snapshot.png differ diff --git a/Image/notion_table.png b/Image/notion_table.png new file mode 100644 index 0000000..e13d920 Binary files /dev/null and b/Image/notion_table.png differ diff --git a/Image/open_send_msg.png b/Image/open_send_msg.png new file mode 100644 index 0000000..252a440 Binary files /dev/null and b/Image/open_send_msg.png differ diff --git a/Image/plot_cbsp.png b/Image/plot_cbsp.png index 2e0c2db..1a1f855 100644 Binary files a/Image/plot_cbsp.png and b/Image/plot_cbsp.png differ diff --git a/Image/summary_b_us_test.png b/Image/summary_b_us_test.png new file mode 100644 index 0000000..cb24c19 Binary files /dev/null and b/Image/summary_b_us_test.png differ diff --git a/README.md b/README.md index 21ee79e..642f345 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,10 @@ - [外部接口](#外部接口) - [模型接入](#模型接入) - [Automl](#automl) - - [其他优化](#其他优化) + - [其他](#其他) + - [COS](#cos) + - [Notion](#notion) + - [其他不值一提的优化](#其他不值一提的优化) - [碎碎念](#碎碎念) ## 功能介绍 @@ -213,6 +216,10 @@ │   ├── 📄 query_marketvalue.py: 计算股票市值分位数 │   └── 📄 run_market_value_query.sh 调度脚本 ├── 📁 Plot: 画图类 +│ ├── 📁 CosApi: COS文件上传类 +│   │ ├── 📄 minio_api.py: minio上传接口 +│   │ ├── 📄 tencent_cos_api.py: 腾讯云cos上传接口 +│   │ └── 📄 cos_config.py: 读取项目配置里面的cos配置参数 │   ├── 📄 AnimatePlotDriver.py: 动画画图类 │   ├── 📄 PlotDriver.py: matplotlib画图引擎 │   └── 📄 PlotMeta.py: 图元数据 @@ -244,6 +251,14 @@ ├── 📁 Script: 脚本汇总 │   ├── 📁 cprofile_analysis: 性能分析 │   │   └── 📄 cprofile_analysis.sh 性能分析脚本 +│   ├── 📁 Notion: Notion数据表同步脚本 +│   │ ├── 📁 notion: Notion API +│   │ │ ├── 📄 notion_api.py: Notion统一API接口 +│   │ │ ├── 📄 block_driver.py: Notion块操作类 +│   │ │ ├── 📄 prop_driver.py.py: Notion数据表属性操作类 +│   │ │ ├── 📄 text.py: Notion 富文本操作类 +│   │ │ └── 📄 notion_config.py: notion读取配置文件里面的参数 +│   │   └── 📄 DB_sync_Notion.py 交易数据库同步Notion脚本 │   ├── 📄 InitDB.py: 数据库初始化 │   ├── 📄 Install.sh 安装本框架脚本 │   ├── 📄 requirements.txt: pip requirements文件 @@ -308,6 +323,25 @@ Model: # 模型配置,可自定义 Chan: debug: false # 是否开启debug模式 + +Notion: # Notion同步配置 + cn_id: xxx + hk_id: xxx + us_id: xxx + token: xxx + +COS: # COS上传图片配置 + cos_type: xxx # tencent/minio + tencent_cos: + secretid: xxx + secretkey: xxx + region: ap-xxx + bucket: chan-xxx + minio: + endpoint: xxxx.com + access_key: xxx + secret_key: xxx + bucket: xxx ``` ### 自行开发必要工具类 @@ -463,7 +497,7 @@ else: # 绘制动画 运行后,可通过 `CChan[KL_TYPE]` 的 bi_list,seg_list,bs_point_lst,cbsp_stragety 等属性获得笔,线段,bsp,cbsp 信息; -> 如果只有一个级别,可以省去 KL_TYPE,直接使用 `CChan.bi_list` 这种调用方法 +> 如果只有一个级别,可以省去 KL_TYPE,直接使用 `CChan[0].bi_list` 这种调用方法 ### CChanConfig 配置 该参数主要用于配置计算逻辑,通过字典初始化 `CChanConfig` 即可,支持配置参数如下: @@ -836,6 +870,7 @@ create table if not exists {table_name}( quota int default 0, --- 提交订单时 open_date datetime(6), --- 开仓信号突破时 open_order_id varchar(32), --- 提交订单时 + open_image_url varchar(64),--- 开仓信号突破时 peak_price_after_open float, --- 更新peak_price时 cover_avg_price float, -- 平仓成交时 @@ -884,6 +919,7 @@ create table if not exists {table_name}( - 轮询间隔 - 是否需要微调未成交订单 - 是否实时推送成交订单,未成交订单状态 +- 各种关键信息的推送 ### 典型流程 一个典型的交易流程(即本框架 `Trade/Script` 下实现的)包括以下步骤: @@ -1152,7 +1188,9 @@ class CXGB_DataSet(CDataSet): ##### 外部接口 实现了上面两个类之后: - 调用 `CModelGenerator.trainProcess()` 即可实现对买卖类型,不同地区股票不同买卖类型,不同买卖点进行训练生成模型和评估结果; - + + + - 调用 `CModelGenerator.PredictProcess()` 即可实现对回测特征文件全部或部分进行预测 - 调用 `CModelGenerator.predictAllProcess()` 即可用所有模型对回测特征文件进行打分,并生成所需要的分数,特征文件,可以直接对接到本框架提供的 automl 方法中; @@ -1196,7 +1234,41 @@ class CCommModel: 对于 `para_automl.py` 的返回结果(包含所有探索过的配置和结果),可以借助 `parse_automl_result.py` 生成线上交易引擎可以直接使用的配置 yaml; -## 其他优化 +## 其他 +### COS +交易引擎在开仓时会推送股票,止损点,价格,分数之类的信息;为了方便在推送时附带上缠论绘制的图片,所以需要一个可以上传图片的地方,所以本项目实现了两个基于cos的上传接口,即项目中`Plot/CosApi`下的实现; + +首选需要在`config.yaml`中配置上COS相关的信息(设计账号密码,桶名称之类的),自己开发使用时,可以直接调用`CPlotDriver.Upload2COS(path=None)`实现自动上传并获得url; + +```python +chan = CChan( + code=code, + begin_time=begin_time, + end_time=end_time, + data_src=data_src, + lv_list=lv_list, + config=config, + autype=AUTYPE.QFQ, + extra_kl=None, + ) + +plot_driver = CPlotDriver( + chan, + plot_config=plot_config, + plot_para=plot_para, +) +print(plot_driver.Upload2COS()) +``` + +交易引擎已内嵌实现了该调用: + + +### Notion +如果在`config.yaml`中配置了Notion相关的信息,例行脚本中会调用`Script/Notion/DB_sync_Notion.py`将已开仓过的股票的操作数据同步至Notion制定的表中;并且会把开仓图片嵌入对应的页面中; + + + +## 其他不值一提的优化 除去上面所说的,还有很多细节的东西没有展开讲,比如 - 交易系统频率如何控制 - 离线数据更新复权时处理逻辑 diff --git a/Script/InitDB.py b/Script/InitDB.py index 9ff73ca..585ad77 100644 --- a/Script/InitDB.py +++ b/Script/InitDB.py @@ -37,6 +37,7 @@ quota int default 0, open_date timestamp, open_order_id TEXT, + open_image_url TEXT, peak_price_after_open float, cover_avg_price float, cover_quota int default 0, @@ -79,6 +80,7 @@ quota int default 0, --- 提交订单时 open_date datetime(6), --- 开仓信号突破时 open_order_id varchar(32), --- 提交订单时 + open_image_url varchar(64),--- 开仓信号突破时 peak_price_after_open float, --- 更新peak_price时 cover_avg_price float, -- 平仓成交时