hikyuu 2.1.5__cp38-none-win_amd64.whl → 2.2.1__cp38-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/analysis/analysis.py +20 -0
- hikyuu/cpp/boost_date_time-mt.dll +0 -0
- hikyuu/cpp/boost_serialization-mt.dll +0 -0
- hikyuu/cpp/boost_wserialization-mt.dll +0 -0
- hikyuu/cpp/core38.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/data/common.py +3 -3
- hikyuu/data/mysql_upgrade/0023.sql +4 -0
- hikyuu/data/pytdx_weight_to_mysql.py +14 -15
- hikyuu/data/pytdx_weight_to_sqlite.py +14 -15
- hikyuu/data/sqlite_upgrade/0024.sql +22 -0
- hikyuu/gui/HikyuuTDX.py +3 -2
- hikyuu/gui/data/ImportHistoryFinanceTask.py +7 -0
- hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -2
- hikyuu/gui/data/MainWindow.py +520 -424
- hikyuu/include/hikyuu/StockWeight.h +16 -10
- hikyuu/include/hikyuu/analysis/analysis_sys.h +42 -12
- hikyuu/include/hikyuu/data_driver/base_info/table/StockWeightTable.h +6 -4
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +5 -6
- hikyuu/include/hikyuu/indicator/crt/IC.h +7 -6
- hikyuu/include/hikyuu/indicator/crt/ICIR.h +7 -4
- hikyuu/include/hikyuu/indicator/imp/IIc.h +1 -1
- hikyuu/include/hikyuu/serialization/StockWeight_serialization.h +5 -2
- hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +27 -25
- hikyuu/include/hikyuu/strategy/Strategy.h +1 -2
- hikyuu/include/hikyuu/trade_manage/Performance.h +3 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +16 -6
- hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +0 -3
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +2 -2
- hikyuu/include/hikyuu/trade_sys/condition/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/condition/crt/CN_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/condition/imp/ManualCondition.h +23 -0
- hikyuu/include/hikyuu/trade_sys/condition/imp/{AddCondition.h → logic/AddCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{AndCondition.h → logic/AndCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{DivCondition.h → logic/DivCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{MultiCondition.h → logic/MultiCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{OrCondition.h → logic/OrCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -6
- hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/ManualEnvironment.h +23 -0
- hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +3 -2
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -2
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +2 -2
- hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +3 -1
- hikyuu/include/hikyuu/trade_sys/selector/build_in.h +2 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +26 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSelector.h → logic/OperatorSelector.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorValueSelector.h → logic/OperatorValueSelector.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/MaxFundsOptimalSelector.h +27 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +86 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +42 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/ManualSignal.h +23 -0
- hikyuu/include/hikyuu/trade_sys/system/System.h +30 -13
- hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +19 -11
- hikyuu/include/hikyuu/trade_sys/system/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/system/crt/SYS_WalkForward.h +27 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/DelegateSystem.h +51 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +70 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +465 -0
- hikyuu/include/hikyuu/utilities/base64.h +25 -31
- hikyuu/include/hikyuu/version.h +5 -5
- hikyuu/strategy/strategy_demo1.py +2 -1
- hikyuu/trade_sys/trade_sys.py +28 -9
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/METADATA +1 -1
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/RECORD +94 -75
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/top_level.txt +3 -0
- /hikyuu/include/hikyuu/trade_sys/selector/crt/{SE_Operator.h → SE_Logic.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddSelector.h → logic/OperatorAddSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddValueSelector.h → logic/OperatorAddValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivSelector.h → logic/OperatorDivSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivValueSelector.h → logic/OperatorDivValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertDivValueSelector.h → logic/OperatorInvertDivValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertSubValueSelector.h → logic/OperatorInvertSubValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulSelector.h → logic/OperatorMulSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulValueSelector.h → logic/OperatorMulValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubSelector.h → logic/OperatorSubSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubValueSelector.h → logic/OperatorSubValueSelector.h} +0 -0
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-19
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/trade_manage/TradeManagerBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class WalkForwardTradeManager : public TradeManagerBase {
|
|
15
|
+
public:
|
|
16
|
+
WalkForwardTradeManager() : TradeManagerBase("", TC_Zero()) {}
|
|
17
|
+
|
|
18
|
+
// 只允许执行>=run_start的实际交易
|
|
19
|
+
WalkForwardTradeManager(const TMPtr& tm, const Datetime& run_start) : m_run_start(run_start) {
|
|
20
|
+
HKU_ASSERT(tm);
|
|
21
|
+
m_tm = tm;
|
|
22
|
+
|
|
23
|
+
m_name = tm->name();
|
|
24
|
+
m_costfunc = m_tm->costFunc();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
virtual ~WalkForwardTradeManager() {}
|
|
28
|
+
|
|
29
|
+
virtual void _reset() override {
|
|
30
|
+
m_tm->_reset();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
virtual shared_ptr<TradeManagerBase> _clone() override {
|
|
34
|
+
WalkForwardTradeManager* p = new WalkForwardTradeManager();
|
|
35
|
+
p->m_tm = m_tm->clone();
|
|
36
|
+
p->m_run_start = m_run_start;
|
|
37
|
+
return shared_ptr<TradeManagerBase>(p);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 根据权息信息更新当前持仓与交易情况
|
|
42
|
+
* @note 必须按时间顺序调用
|
|
43
|
+
* @param datetime 当前时刻
|
|
44
|
+
*/
|
|
45
|
+
virtual void updateWithWeight(const Datetime& datetime) override {
|
|
46
|
+
m_tm->updateWithWeight(datetime);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 获取指定对象的保证金比率
|
|
51
|
+
* @param datetime 日期
|
|
52
|
+
* @param stock 指定对象
|
|
53
|
+
*/
|
|
54
|
+
virtual double getMarginRate(const Datetime& datetime, const Stock& stock) override {
|
|
55
|
+
return (datetime >= m_run_start) ? m_tm->getMarginRate(datetime, stock) : 0.0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 初始资金 */
|
|
59
|
+
virtual price_t initCash() const override {
|
|
60
|
+
return m_tm->initCash();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 账户建立日期 */
|
|
64
|
+
virtual Datetime initDatetime() const override {
|
|
65
|
+
return m_tm->initDatetime();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 第一笔买入交易发生日期,如未发生交易返回Null<Datetime>() */
|
|
69
|
+
virtual Datetime firstDatetime() const override {
|
|
70
|
+
return m_tm->firstDatetime();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期 */
|
|
74
|
+
virtual Datetime lastDatetime() const override {
|
|
75
|
+
return m_tm->lastDatetime();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 返回当前现金
|
|
80
|
+
* @note 仅返回当前信息,不会根据权息进行调整
|
|
81
|
+
*/
|
|
82
|
+
virtual price_t currentCash() const override {
|
|
83
|
+
return m_tm->currentCash();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 获取指定日期的现金
|
|
88
|
+
* @note 如果不带日期参数,无法根据权息信息调整持仓
|
|
89
|
+
*/
|
|
90
|
+
virtual price_t cash(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) override {
|
|
91
|
+
return m_tm->cash(datetime, ktype);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 当前是否持有指定的证券
|
|
96
|
+
* @note 这里未使用日期参数,必须保证是按日期顺序执行
|
|
97
|
+
* @param stock 指定证券
|
|
98
|
+
* @return true 是 | false 否
|
|
99
|
+
*/
|
|
100
|
+
virtual bool have(const Stock& stock) const override {
|
|
101
|
+
return m_tm->have(stock);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 当前空头仓位是否持有指定的证券
|
|
106
|
+
* @note 这里未使用日期参数,必须保证是按日期顺序执行
|
|
107
|
+
* @param stock 指定证券
|
|
108
|
+
* @return true 是 | false 否
|
|
109
|
+
*/
|
|
110
|
+
virtual bool haveShort(const Stock& stock) const override {
|
|
111
|
+
return m_tm->haveShort(stock);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 当前持有的证券种类数量 */
|
|
115
|
+
virtual size_t getStockNumber() const override {
|
|
116
|
+
return m_tm->getStockNumber();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 当前空头持有的证券种类数量 */
|
|
120
|
+
virtual size_t getShortStockNumber() const override {
|
|
121
|
+
return m_tm->getShortStockNumber();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 获取指定时刻的某证券持有数量 */
|
|
125
|
+
virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) override {
|
|
126
|
+
return m_tm->getHoldNumber(datetime, stock);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** 获取指定时刻的空头某证券持有数量 */
|
|
130
|
+
virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) override {
|
|
131
|
+
return m_tm->getShortHoldNumber(datetime, stock);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 获取指定时刻已借入的股票数量 */
|
|
135
|
+
virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) override {
|
|
136
|
+
return m_tm->getDebtNumber(datetime, stock);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 获取指定时刻已借入的现金额 */
|
|
140
|
+
virtual price_t getDebtCash(const Datetime& datetime) override {
|
|
141
|
+
return m_tm->getDebtCash(datetime);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 获取全部交易记录 */
|
|
145
|
+
virtual TradeRecordList getTradeList() const override {
|
|
146
|
+
return m_tm->getTradeList();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 获取指定日期范围内的交易记录[start, end)
|
|
151
|
+
* @param start 起始日期
|
|
152
|
+
* @param end 结束日期
|
|
153
|
+
* @return 交易记录列表
|
|
154
|
+
*/
|
|
155
|
+
virtual TradeRecordList getTradeList(const Datetime& start,
|
|
156
|
+
const Datetime& end) const override {
|
|
157
|
+
return m_tm->getTradeList(start, end);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 获取当前全部持仓记录 */
|
|
161
|
+
virtual PositionRecordList getPositionList() const override {
|
|
162
|
+
return m_tm->getPositionList();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 获取全部历史持仓记录,即已平仓记录 */
|
|
166
|
+
virtual PositionRecordList getHistoryPositionList() const override {
|
|
167
|
+
return m_tm->getHistoryPositionList();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 获取当前全部空头仓位记录 */
|
|
171
|
+
virtual PositionRecordList getShortPositionList() const override {
|
|
172
|
+
return m_tm->getShortPositionList();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 获取全部空头历史仓位记录 */
|
|
176
|
+
virtual PositionRecordList getShortHistoryPositionList() const override {
|
|
177
|
+
return m_tm->getShortHistoryPositionList();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 获取指定证券的持仓记录
|
|
182
|
+
* @param date 指定日期
|
|
183
|
+
* @param stock 指定的证券
|
|
184
|
+
*/
|
|
185
|
+
virtual PositionRecord getPosition(const Datetime& date, const Stock& stock) override {
|
|
186
|
+
return m_tm->getPosition(date, stock);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 获取指定证券的空头持仓记录
|
|
191
|
+
* @param stock 指定的证券
|
|
192
|
+
*/
|
|
193
|
+
virtual PositionRecord getShortPosition(const Stock& stock) const override {
|
|
194
|
+
return m_tm->getShortPosition(stock);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 获取当前借入的股票列表 */
|
|
198
|
+
virtual BorrowRecordList getBorrowStockList() const override {
|
|
199
|
+
return m_tm->getBorrowStockList();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 存入资金
|
|
204
|
+
* @param datetime 存入时间
|
|
205
|
+
* @param cash 存入的资金量
|
|
206
|
+
* @return true | false
|
|
207
|
+
*/
|
|
208
|
+
virtual bool checkin(const Datetime& datetime, price_t cash) override {
|
|
209
|
+
return (datetime >= m_run_start) ? m_tm->checkin(datetime, cash) : false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 取出资金
|
|
214
|
+
* @param datetime 取出时间
|
|
215
|
+
* @param cash 取出的资金量
|
|
216
|
+
* @return true | false
|
|
217
|
+
*/
|
|
218
|
+
virtual bool checkout(const Datetime& datetime, price_t cash) override {
|
|
219
|
+
return (datetime >= m_run_start) ? m_tm->checkout(datetime, cash) : false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 存入资产
|
|
224
|
+
* @param datetime 存入日期
|
|
225
|
+
* @param stock 待存入的股票
|
|
226
|
+
* @param price 存入股票的每股价格
|
|
227
|
+
* @param number 存入股票的数量
|
|
228
|
+
* @return true | false
|
|
229
|
+
*/
|
|
230
|
+
virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
231
|
+
double number) override {
|
|
232
|
+
return (datetime >= m_run_start) ? m_tm->checkinStock(datetime, stock, price, number)
|
|
233
|
+
: false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 取出当前资产
|
|
238
|
+
* @param datetime 取出日期
|
|
239
|
+
* @param stock 待取出的股票
|
|
240
|
+
* @param price 取出的每股价格
|
|
241
|
+
* @param number 取出的数量
|
|
242
|
+
* @return true | false
|
|
243
|
+
* @note 应该不会被用到
|
|
244
|
+
*/
|
|
245
|
+
virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
246
|
+
double number) override {
|
|
247
|
+
return (datetime >= m_run_start) ? m_tm->checkoutStock(datetime, stock, price, number)
|
|
248
|
+
: false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 买入操作
|
|
253
|
+
* @param datetime 买入时间
|
|
254
|
+
* @param stock 买入的证券
|
|
255
|
+
* @param realPrice 实际买入价格
|
|
256
|
+
* @param number 买入数量
|
|
257
|
+
* @param stoploss 止损价
|
|
258
|
+
* @param goalPrice 目标价格
|
|
259
|
+
* @param planPrice 计划买入价格
|
|
260
|
+
* @param from 记录是哪个系统部件发出的买入指示
|
|
261
|
+
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
|
262
|
+
*/
|
|
263
|
+
virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
264
|
+
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
|
265
|
+
price_t planPrice = 0.0, SystemPart from = PART_INVALID) override {
|
|
266
|
+
return (datetime >= m_run_start) ? m_tm->buy(datetime, stock, realPrice, number, stoploss,
|
|
267
|
+
goalPrice, planPrice, from)
|
|
268
|
+
: TradeRecord();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 卖出操作
|
|
273
|
+
* @param datetime 卖出时间
|
|
274
|
+
* @param stock 卖出的证券
|
|
275
|
+
* @param realPrice 实际卖出价格
|
|
276
|
+
* @param number 卖出数量,如果是 MAX_DOUBLE, 表示全部卖出
|
|
277
|
+
* @param stoploss 新的止损价
|
|
278
|
+
* @param goalPrice 新的目标价格
|
|
279
|
+
* @param planPrice 原计划卖出价格
|
|
280
|
+
* @param from 记录是哪个系统部件发出的卖出指示
|
|
281
|
+
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
|
282
|
+
*/
|
|
283
|
+
virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
284
|
+
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
|
285
|
+
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
|
286
|
+
SystemPart from = PART_INVALID) override {
|
|
287
|
+
return (datetime >= m_run_start) ? m_tm->sell(datetime, stock, realPrice, number, stoploss,
|
|
288
|
+
goalPrice, planPrice, from)
|
|
289
|
+
: TradeRecord();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 卖空
|
|
294
|
+
* @param datetime 卖空时间
|
|
295
|
+
* @param stock 卖空的证券
|
|
296
|
+
* @param realPrice 实际卖空价格
|
|
297
|
+
* @param number 卖出数量
|
|
298
|
+
* @param stoploss 止损价
|
|
299
|
+
* @param goalPrice 目标价格
|
|
300
|
+
* @param planPrice 计划卖空价格
|
|
301
|
+
* @param from 记录是哪个系统部件发出的买入指示
|
|
302
|
+
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
|
303
|
+
*/
|
|
304
|
+
virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
305
|
+
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
|
306
|
+
price_t planPrice = 0.0,
|
|
307
|
+
SystemPart from = PART_INVALID) override {
|
|
308
|
+
return (datetime >= m_run_start) ? m_tm->sellShort(datetime, stock, realPrice, number,
|
|
309
|
+
stoploss, goalPrice, planPrice, from)
|
|
310
|
+
: TradeRecord();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* 卖空后回补
|
|
315
|
+
* @param datetime 买入时间
|
|
316
|
+
* @param stock 买入的证券
|
|
317
|
+
* @param realPrice 实际买入价格
|
|
318
|
+
* @param number 卖出数量,如果是 MAX_DOUBLE, 表示全部卖出
|
|
319
|
+
* @param stoploss 止损价
|
|
320
|
+
* @param goalPrice 目标价格
|
|
321
|
+
* @param planPrice 计划买入价格
|
|
322
|
+
* @param from 记录是哪个系统部件发出的卖出指示
|
|
323
|
+
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
|
324
|
+
*/
|
|
325
|
+
virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
326
|
+
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
|
327
|
+
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
|
328
|
+
SystemPart from = PART_INVALID) override {
|
|
329
|
+
return (datetime >= m_run_start) ? m_tm->buyShort(datetime, stock, realPrice, number,
|
|
330
|
+
stoploss, goalPrice, planPrice, from)
|
|
331
|
+
: TradeRecord();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 借入资金,从其他来源借取的资金,如融资
|
|
336
|
+
* @param datetime 借入时间
|
|
337
|
+
* @param cash 借入的现金
|
|
338
|
+
* @return true | false
|
|
339
|
+
*/
|
|
340
|
+
virtual bool borrowCash(const Datetime& datetime, price_t cash) override {
|
|
341
|
+
return (datetime >= m_run_start) ? m_tm->borrowCash(datetime, cash) : false;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* 归还资金
|
|
346
|
+
* @param datetime 归还日期
|
|
347
|
+
* @param cash 归还现金
|
|
348
|
+
* @return true | false
|
|
349
|
+
*/
|
|
350
|
+
virtual bool returnCash(const Datetime& datetime, price_t cash) override {
|
|
351
|
+
return (datetime >= m_run_start) ? m_tm->returnCash(datetime, cash) : false;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 借入证券
|
|
356
|
+
* @param datetime 借入时间
|
|
357
|
+
* @param stock 借入的stock
|
|
358
|
+
* @param price 借入时单股价格
|
|
359
|
+
* @param number 借入时数量
|
|
360
|
+
* @return true | false
|
|
361
|
+
*/
|
|
362
|
+
virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
363
|
+
double number) override {
|
|
364
|
+
return (datetime >= m_run_start) ? m_tm->borrowStock(datetime, stock, price, number)
|
|
365
|
+
: false;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* 归还证券
|
|
370
|
+
* @param datetime 归还时间
|
|
371
|
+
* @param stock 归还的stock
|
|
372
|
+
* @param price 归还时单股价格
|
|
373
|
+
* @param number 归还数量
|
|
374
|
+
* @return true | false
|
|
375
|
+
*/
|
|
376
|
+
virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
377
|
+
double number) override {
|
|
378
|
+
return (datetime >= m_run_start) ? m_tm->returnStock(datetime, stock, price, number)
|
|
379
|
+
: false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* 获取账户当前时刻的资产详情
|
|
384
|
+
* @param ktype 日期的类型
|
|
385
|
+
* @return 资产详情
|
|
386
|
+
*/
|
|
387
|
+
virtual FundsRecord getFunds(KQuery::KType ktype = KQuery::DAY) const override {
|
|
388
|
+
return m_tm->getFunds(ktype);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 获取指定时刻的资产市值详情
|
|
393
|
+
* @param datetime 必须大于帐户建立的初始日期,或为Null<Datetime>()
|
|
394
|
+
* @param ktype 日期的类型
|
|
395
|
+
* @return 资产详情
|
|
396
|
+
* @note 当datetime等于Null<Datetime>()时,与getFunds(KType)同
|
|
397
|
+
*/
|
|
398
|
+
virtual FundsRecord getFunds(const Datetime& datetime,
|
|
399
|
+
KQuery::KType ktype = KQuery::DAY) override {
|
|
400
|
+
return m_tm->getFunds(datetime, ktype);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 直接加入交易记录
|
|
405
|
+
* @note 如果加入初始化账户记录,将清除全部已有交易及持仓记录
|
|
406
|
+
* @param tr 待加入的交易记录
|
|
407
|
+
* @return bool true 成功 | false 失败
|
|
408
|
+
*/
|
|
409
|
+
virtual bool addTradeRecord(const TradeRecord& tr) override {
|
|
410
|
+
return (tr.datetime >= m_run_start) ? m_tm->addTradeRecord(tr) : false;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* 直接加入持仓记录
|
|
415
|
+
* @param pr 持仓记录
|
|
416
|
+
* @return true 成功
|
|
417
|
+
* @return false 失败
|
|
418
|
+
*/
|
|
419
|
+
virtual bool addPosition(const PositionRecord& pr) override {
|
|
420
|
+
return m_tm->addPosition(pr);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** 字符串输出 */
|
|
424
|
+
virtual string str() const override {
|
|
425
|
+
return m_tm->str();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线
|
|
430
|
+
* @param path 输出文件所在目录
|
|
431
|
+
*/
|
|
432
|
+
virtual void tocsv(const string& path) override {
|
|
433
|
+
m_tm->tocsv(path);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* 从订单代理实例同步当前账户资产信息(包含资金、持仓等)
|
|
438
|
+
* @param broker 订单代理实例
|
|
439
|
+
*/
|
|
440
|
+
virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) override {
|
|
441
|
+
m_tm->fetchAssetInfoFromBroker(broker);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private:
|
|
445
|
+
TMPtr m_tm;
|
|
446
|
+
Datetime m_run_start;
|
|
447
|
+
|
|
448
|
+
//============================================
|
|
449
|
+
// 序列化支持
|
|
450
|
+
//============================================
|
|
451
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
452
|
+
friend class boost::serialization::access;
|
|
453
|
+
template <class Archive>
|
|
454
|
+
void serialize(Archive& ar, const unsigned int version) {
|
|
455
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(TradeManagerBase);
|
|
456
|
+
ar& BOOST_SERIALIZATION_NVP(m_tm);
|
|
457
|
+
}
|
|
458
|
+
#endif /* HKU_SUPPORT_SERIALIZATION */
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
inline TMPtr crtWalkForwardTM(const TMPtr& tm, const Datetime& run_start) {
|
|
462
|
+
return std::make_shared<WalkForwardTradeManager>(tm, run_start);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
} // namespace hku
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Author: fasiondog
|
|
6
|
-
*/
|
|
1
|
+
//
|
|
2
|
+
// base64 encoding and decoding with C++.
|
|
3
|
+
// Version: 2.rc.08 (release candidate)
|
|
4
|
+
//
|
|
7
5
|
|
|
8
6
|
#pragma once
|
|
9
7
|
#ifndef HKU_UTILS_BASE64_H
|
|
@@ -18,40 +16,36 @@
|
|
|
18
16
|
|
|
19
17
|
namespace hku {
|
|
20
18
|
|
|
21
|
-
/**
|
|
22
|
-
* 将二进制 bytes 数组编码成 base64 字符串
|
|
23
|
-
* @param bytes_to_encode 内存起始地址
|
|
24
|
-
* @param in_len 待计算的字节长度
|
|
25
|
-
*/
|
|
26
|
-
std::string HKU_UTILS_API base64_encode(unsigned char const* bytes_to_encode, size_t in_len);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 字符串编码为 base64
|
|
30
|
-
* @param src 输入字符串
|
|
31
|
-
* @note 通过 func(unsigned char *, unsigned int) 函数实现,而不是直接只提供 string_view
|
|
32
|
-
* 版本的原因是:c++17 string_view 处理 nullptr 时,程序会直接挂掉,无异常
|
|
33
|
-
*/
|
|
34
|
-
inline std::string base64_encode(string_view src) {
|
|
35
|
-
return base64_encode((unsigned char const*)src.data(), src.size());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
19
|
/**
|
|
39
20
|
* 将 base64 字符串解码
|
|
40
21
|
* @param encoded_string base64 编码的字符串
|
|
41
|
-
* @param
|
|
22
|
+
* @param remove_linebreaks 是否移除url中的分隔符
|
|
42
23
|
* @return string 实际解码后的二进制内容保存在返回的字符串对象中
|
|
43
24
|
* @note 如果传入的base64编码字符串中含有非法字符,不会告警,仅处理到能处理的字符
|
|
44
25
|
*/
|
|
45
|
-
std::string HKU_UTILS_API base64_decode(
|
|
26
|
+
std::string HKU_UTILS_API base64_decode(std::string const& encoded_string,
|
|
27
|
+
bool remove_linebreaks = false);
|
|
46
28
|
|
|
47
29
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
30
|
+
* 将二进制 bytes 数组编码成 base64 字符串
|
|
31
|
+
* @param bytes_to_encode 内存起始地址
|
|
32
|
+
* @param in_len 待计算的字节长度
|
|
33
|
+
* @param url 是否为在 url 中使用
|
|
51
34
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
std::string HKU_UTILS_API base64_encode(unsigned char const* bytes_to_encode, size_t in_len,
|
|
36
|
+
bool url = false);
|
|
37
|
+
|
|
38
|
+
std::string HKU_UTILS_API base64_encode(const std::string& s, bool url = false);
|
|
39
|
+
std::string HKU_UTILS_API base64_encode_pem(const std::string& s);
|
|
40
|
+
std::string HKU_UTILS_API base64_encode_mime(const std::string& s);
|
|
41
|
+
|
|
42
|
+
#if __cplusplus >= 201703L
|
|
43
|
+
std::string HKU_UTILS_API base64_encode(string_view s, bool url = false);
|
|
44
|
+
std::string HKU_UTILS_API base64_encode_pem(string_view s);
|
|
45
|
+
std::string HKU_UTILS_API base64_encode_mime(string_view s);
|
|
46
|
+
|
|
47
|
+
std::string HKU_UTILS_API base64_decode(string_view s, bool remove_linebreaks = false);
|
|
48
|
+
#endif // __cplusplus >= 201703L
|
|
55
49
|
|
|
56
50
|
} // namespace hku
|
|
57
51
|
|
hikyuu/include/hikyuu/version.h
CHANGED
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
#define HKU_VERSION_H
|
|
13
13
|
|
|
14
14
|
// clang-format off
|
|
15
|
-
#define HKU_VERSION "2.1
|
|
15
|
+
#define HKU_VERSION "2.2.1"
|
|
16
16
|
#define HKU_VERSION_MAJOR 2
|
|
17
|
-
#define HKU_VERSION_MINOR
|
|
18
|
-
#define HKU_VERSION_ALTER
|
|
19
|
-
#define HKU_VERSION_BUILD
|
|
17
|
+
#define HKU_VERSION_MINOR 2
|
|
18
|
+
#define HKU_VERSION_ALTER 1
|
|
19
|
+
#define HKU_VERSION_BUILD 202410011518
|
|
20
20
|
#define HKU_VERSION_MODE "RELEASE"
|
|
21
|
-
#define HKU_VERSION_GIT "2.1
|
|
21
|
+
#define HKU_VERSION_GIT "2.2.1 master.89f17bf1 (RELEASE)"
|
|
22
22
|
// clang-format on
|
|
23
23
|
|
|
24
24
|
#endif /* HKU_VERSION_H */
|
|
@@ -39,8 +39,9 @@ if __name__ == '__main__':
|
|
|
39
39
|
# 如需使用交易日历,请记得同时指定 sh000001
|
|
40
40
|
s = Strategy(['sh600000', 'sz000001'], [Query.MIN, Query.DAY])
|
|
41
41
|
|
|
42
|
-
#
|
|
42
|
+
# 当前自动延迟10秒/20秒后执行,忽略节假日限制
|
|
43
43
|
s.run_daily_at(my_func1, Datetime.now() - Datetime.today() + Seconds(10), False)
|
|
44
|
+
s.run_daily_at(my_func1, Datetime.now() - Datetime.today() + Seconds(20), False)
|
|
44
45
|
|
|
45
46
|
# 收到指定 stock 的行情更新
|
|
46
47
|
s.on_change(on_change)
|
hikyuu/trade_sys/trade_sys.py
CHANGED
|
@@ -59,7 +59,10 @@ def crtCN(func, params={}, name='crtCN'):
|
|
|
59
59
|
"""
|
|
60
60
|
meta_x = type(name, (ConditionBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
61
61
|
meta_x._calculate = func
|
|
62
|
-
|
|
62
|
+
# 强制引入全局空间,避免 hub 使用是自定义继承丢失虚拟函数接口
|
|
63
|
+
ret = meta_x(name, params)
|
|
64
|
+
globals().update(dict(_=ret))
|
|
65
|
+
return ret
|
|
63
66
|
|
|
64
67
|
|
|
65
68
|
# ------------------------------------------------------------------
|
|
@@ -76,7 +79,9 @@ def crtEV(func, params={}, name='crtEV'):
|
|
|
76
79
|
"""
|
|
77
80
|
meta_x = type(name, (EnvironmentBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
78
81
|
meta_x._calculate = func
|
|
79
|
-
|
|
82
|
+
ret = meta_x(name, params)
|
|
83
|
+
globals().update(dict(_=ret))
|
|
84
|
+
return ret
|
|
80
85
|
|
|
81
86
|
|
|
82
87
|
# ------------------------------------------------------------------
|
|
@@ -101,7 +106,9 @@ def crtMM(get_buy_num, get_sell_num, params={}, name='crtMM', buy_notify=None, s
|
|
|
101
106
|
meta_x._buy_notify = buy_notify
|
|
102
107
|
if sell_notify is not None:
|
|
103
108
|
meta_x._sell_notify = sell_notify
|
|
104
|
-
|
|
109
|
+
ret = meta_x(name, params)
|
|
110
|
+
globals().update(dict(_=ret))
|
|
111
|
+
return ret
|
|
105
112
|
|
|
106
113
|
|
|
107
114
|
# ------------------------------------------------------------------
|
|
@@ -118,7 +125,9 @@ def crtPG(func, params={}, name='crtPG'):
|
|
|
118
125
|
"""
|
|
119
126
|
meta_x = type(name, (ProfitGoalBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
120
127
|
meta_x._calculate = func
|
|
121
|
-
|
|
128
|
+
ret = meta_x(name, params)
|
|
129
|
+
globals().update(dict(_=ret))
|
|
130
|
+
return ret
|
|
122
131
|
|
|
123
132
|
|
|
124
133
|
# ------------------------------------------------------------------
|
|
@@ -156,7 +165,9 @@ def crtSE(calculate, get_selected, is_match_af=None, params={}, name='crtSE'):
|
|
|
156
165
|
meta_x._calculate = calculate
|
|
157
166
|
meta_x.get_selected = get_selected
|
|
158
167
|
meta_x.is_match_af = (lambda self, af: True) if is_match_af is None else is_match_af
|
|
159
|
-
|
|
168
|
+
ret = meta_x(name, params)
|
|
169
|
+
globals().update(dict(_=ret))
|
|
170
|
+
return ret
|
|
160
171
|
|
|
161
172
|
|
|
162
173
|
# ------------------------------------------------------------------
|
|
@@ -173,7 +184,9 @@ def crtAF(allocate_weight_func, params={}, name='crtAF'):
|
|
|
173
184
|
"""
|
|
174
185
|
meta_x = type(name, (AllocateFundsBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
175
186
|
meta_x._allocate_weight = allocate_weight_func
|
|
176
|
-
|
|
187
|
+
ret = meta_x(name, params)
|
|
188
|
+
globals().update(dict(_=ret))
|
|
189
|
+
return ret
|
|
177
190
|
|
|
178
191
|
|
|
179
192
|
# ------------------------------------------------------------------
|
|
@@ -190,7 +203,9 @@ def crtMF(calculate_func, params={}, name='crtMF'):
|
|
|
190
203
|
"""
|
|
191
204
|
meta_x = type(name, (MultiFactorBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
192
205
|
meta_x._calculate = calculate_func
|
|
193
|
-
|
|
206
|
+
ret = meta_x(name, params)
|
|
207
|
+
globals().update(dict(_=ret))
|
|
208
|
+
return ret
|
|
194
209
|
|
|
195
210
|
|
|
196
211
|
# ------------------------------------------------------------------
|
|
@@ -212,7 +227,9 @@ def crtSP(get_real_buy_price, get_real_sell_price, params={}, name='crtSP', calc
|
|
|
212
227
|
meta_x.get_real_sell_price = get_real_sell_price
|
|
213
228
|
if calculate is not None:
|
|
214
229
|
meta_x._calculate = calculate
|
|
215
|
-
|
|
230
|
+
ret = meta_x(name, params)
|
|
231
|
+
globals().update(dict(_=ret))
|
|
232
|
+
return ret
|
|
216
233
|
|
|
217
234
|
|
|
218
235
|
# ------------------------------------------------------------------
|
|
@@ -229,4 +246,6 @@ def crtST(func, params={}, name='crtST'):
|
|
|
229
246
|
"""
|
|
230
247
|
meta_x = type(name, (StoplossBase, ), {'__init__': part_init, '_clone': part_clone})
|
|
231
248
|
meta_x._calculate = func
|
|
232
|
-
|
|
249
|
+
ret = meta_x(name, params)
|
|
250
|
+
globals().update(dict(_=ret))
|
|
251
|
+
return ret
|