-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed https://gitee.com/fasiondog/hikyuu/issues/I5EJ0I 订单代理失效
- Loading branch information
Showing
6 changed files
with
90 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,11 @@ Python中的订单代理包装 | |
my_tm = crtTM(init_cash = 300000) | ||
|
||
#注册实盘交易订单代理 | ||
my_tm.regBroker(crtOB(TestOrderBroker())) #TestOerderBroker是测试用订单代理对象,只打印 | ||
#my_tm.regBroker(crtOB(Puppet())) #Puppet为内建的扯线木偶实盘下单对象 | ||
#my_tm.regBroker(crtOB(MailOrderBroker("smtp.sina.com", "[email protected]", "yourpwd", "[email protected]))) | ||
my_tm.reg_broker(crtOB(TestOrderBroker())) #TestOerderBroker是测试用订单代理对象,只打印 | ||
#my_tm.reg_broker(crtOB(MailOrderBroker("smtp.sina.com", "[email protected]", "yourpwd", "[email protected]))) | ||
|
||
#根据需要修改订单代理最后的时间戳,后续只有大于该时间戳时,订单代理才会实际发出订单指令 | ||
my_tm.brokeLastDatetime=Datetime(201706010000) | ||
my_tm.broke_last_datetime=Datetime(201706010000) | ||
|
||
#创建信号指示器(以5日EMA为快线,5日EMA自身的10日EMA作为慢线,快线向上穿越慢线时买入,反之卖出) | ||
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,17 @@ | |
"text": [ | ||
"std::cout are redirected to python::stdout\n", | ||
"std::cerr are redirected to python::stderr\n", | ||
"2021-02-12 17:02:02.409 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n", | ||
"2021-02-12 17:02:02.411 [HKU-I] - Loading market information... (StockManager.cpp:473)\n", | ||
"2021-02-12 17:02:02.412 [HKU-I] - Loading stock type information... (StockManager.cpp:486)\n", | ||
"2021-02-12 17:02:02.413 [HKU-I] - Loading stock information... (StockManager.cpp:422)\n", | ||
"2021-02-12 17:02:02.501 [HKU-I] - Loading stock weight... (StockManager.cpp:503)\n", | ||
"2021-02-12 17:02:03.904 [HKU-I] - Loading KData... (StockManager.cpp:138)\n", | ||
"2021-02-12 17:02:03.909 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:161)\n", | ||
"2021-02-12 17:02:03.931 [HKU-I] - 0.03s Loaded Data. (StockManager.cpp:149)\n", | ||
"Wall time: 2.78 s\n" | ||
"2022-06-30 00:49:42.300 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n", | ||
"2022-06-30 00:49:42.301 [HKU-I] - Loading market information... (StockManager.cpp:497)\n", | ||
"2022-06-30 00:49:42.301 [HKU-I] - Loading stock type information... (StockManager.cpp:510)\n", | ||
"2022-06-30 00:49:42.301 [HKU-I] - Loading stock information... (StockManager.cpp:424)\n", | ||
"2022-06-30 00:49:42.348 [HKU-I] - Loading stock weight... (StockManager.cpp:527)\n", | ||
"2022-06-30 00:49:42.714 [HKU-I] - Loading KData... (StockManager.cpp:139)\n", | ||
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:162)\n", | ||
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all week kdata to buffer! (StockManager.cpp:165)\n", | ||
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all month kdata to buffer! (StockManager.cpp:168)\n", | ||
"2022-06-30 00:49:42.729 [HKU-I] - 0.01s Loaded Data. (StockManager.cpp:150)\n", | ||
"Wall time: 1.08 s\n" | ||
] | ||
} | ||
], | ||
|
@@ -56,7 +58,7 @@ | |
"output_type": "stream", | ||
"text": [ | ||
"TradeManager {\n", | ||
" params: params[precision(int): 2, reinvest(bool): 0, save_action(bool): 1, support_borrow_cash(bool): 0, support_borrow_stock(bool): 0, ],\n", | ||
" params: params[precision(int): 2, save_action(bool): 1, support_borrow_cash(bool): 0, support_borrow_stock(bool): 0, ],\n", | ||
" name: SYS,\n", | ||
" init_date: 2017-01-01 00:00:00,\n", | ||
" init_cash: 100000.00,\n", | ||
|
@@ -71,7 +73,7 @@ | |
" current borrow_cash: 0.00,\n", | ||
" current borrow_asset: 0.00,\n", | ||
" Position: \n", | ||
" SZ000001 平安银行 2017-01-03 00:00:00 999 100.00 911.00 2493.00 1582.00 173.66% 1.58%\n", | ||
" SZ000001 平安银行 2017-01-03 00:00:00 1333 100.00 911.00 1464.00 553.00 60.70% 0.55%\n", | ||
" Short Position: \n", | ||
" Borrow Stock: \n", | ||
"}\n" | ||
|
@@ -141,21 +143,21 @@ | |
" <th>SZ000001</th>\n", | ||
" <td>平安银行</td>\n", | ||
" <td>2017-01-03</td>\n", | ||
" <td>999</td>\n", | ||
" <td>1333</td>\n", | ||
" <td>100</td>\n", | ||
" <td>911.0</td>\n", | ||
" <td>2493.0</td>\n", | ||
" <td>1582.0</td>\n", | ||
" <td>173.655324</td>\n", | ||
" <td>1464.0</td>\n", | ||
" <td>553.0</td>\n", | ||
" <td>60.702525</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" 证券名称 买入日期 已持仓天数 持仓数量 投入金额 当前市值 盈亏金额 盈亏比例\n", | ||
"证券代码 \n", | ||
"SZ000001 平安银行 2017-01-03 999 100 911.0 2493.0 1582.0 173.655324" | ||
" 证券名称 买入日期 已持仓天数 持仓数量 投入金额 当前市值 盈亏金额 盈亏比例\n", | ||
"证券代码 \n", | ||
"SZ000001 平安银行 2017-01-03 1333 100 911.0 1464.0 553.0 60.702525" | ||
] | ||
}, | ||
"execution_count": 3, | ||
|
@@ -178,7 +180,7 @@ | |
"data": { | ||
"text/plain": [ | ||
"TradeManager {\n", | ||
" params: params[precision(int): 2, reinvest(bool): 0, save_action(bool): 1, support_borrow_cash(bool): 0, support_borrow_stock(bool): 0, ],\n", | ||
" params: params[precision(int): 2, save_action(bool): 1, support_borrow_cash(bool): 0, support_borrow_stock(bool): 0, ],\n", | ||
" name: SYS,\n", | ||
" init_date: 2017-01-01 00:00:00,\n", | ||
" init_cash: 100000.00,\n", | ||
|
@@ -282,6 +284,60 @@ | |
"<img src=\"images/008_03_pickle.png\" align=\"left\">" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# 4 使用订单代理" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"买入:SZ000001 18.300 1000\n", | ||
"卖出:SZ000001 17.510 1000\n", | ||
"买入:SZ000001 17.410 1000\n", | ||
"卖出:SZ000001 17.000 1000\n", | ||
"买入:SZ000001 17.340 1000\n", | ||
"卖出:SZ000001 16.500 1000\n", | ||
"买入:SZ000001 17.030 1000\n", | ||
"卖出:SZ000001 16.350 1000\n", | ||
"买入:SZ000001 15.110 1000\n", | ||
"卖出:SZ000001 14.880 1000\n", | ||
"买入:SZ000001 14.740 1000\n", | ||
"卖出:SZ000001 14.090 1000\n", | ||
"买入:SZ000001 14.470 1000\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#创建模拟交易账户进行回测,初始资金30万\n", | ||
"my_tm = crtTM(init_cash=300000, date=Datetime(201701010000))\n", | ||
"\n", | ||
"#注册实盘交易订单代理\n", | ||
"my_tm.reg_broker(crtOB(TestOrderBroker(), False)) #TestOerderBroker是测试用订单代理对象,只打印\n", | ||
"#my_tm.regBroker(crtOB(MailOrderBroker(\"smtp.sina.com\", \"[email protected]\", \"yourpwd\", \"[email protected])))\n", | ||
"\n", | ||
"#根据需要修改订单代理最后的时间戳,后续只有大于该时间戳时,订单代理才会实际发出订单指令\n", | ||
"my_tm.broker_last_datetime=Datetime(201701010000)\n", | ||
"\n", | ||
"#创建信号指示器(以5日EMA为快线,5日EMA自身的10日EMA作为慢线,快线向上穿越慢线时买入,反之卖出)\n", | ||
"my_sg = SG_Flex(EMA(n=5), slow_n=10)\n", | ||
"\n", | ||
"#固定每次买入1000股\n", | ||
"my_mm = MM_FixedCount(1000)\n", | ||
"\n", | ||
"#创建交易系统并运行\n", | ||
"sys = SYS_Simple(tm = my_tm, sg = my_sg, mm = my_mm)\n", | ||
"sys.run(sm['sz000001'], Query(-150))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
|
@@ -292,7 +348,7 @@ | |
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
|
@@ -306,7 +362,7 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
"version": "3.9.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters