hikyuu 2.1.1__cp39-none-win_amd64.whl → 2.1.2__cp39-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/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/core39.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/examples/notebook/006-TradeManager.ipynb +41 -39
- hikyuu/examples/notebook/008-Pickle.ipynb +27 -35
- hikyuu/fetcher/stock/zh_stock_a_qmt.py +49 -0
- hikyuu/gui/HikyuuTDX.py +2 -1
- hikyuu/gui/data/MainWindow.py +126 -126
- hikyuu/gui/spot_server.py +16 -7
- hikyuu/gui/start_qmt.py +36 -0
- hikyuu/include/hikyuu/Stock.h +1 -1
- hikyuu/include/hikyuu/StrategyContext.h +7 -2
- hikyuu/include/hikyuu/data_driver/base_info/table/HistoryFinanceTable.h +2 -2
- hikyuu/include/hikyuu/doc.h +2 -2
- hikyuu/include/hikyuu/global/GlobalSpotAgent.h +1 -0
- hikyuu/include/hikyuu/global/GlobalTaskGroup.h +4 -2
- hikyuu/include/hikyuu/global/SpotRecord.h +52 -0
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +14 -41
- hikyuu/include/hikyuu/hikyuu.h +1 -0
- hikyuu/include/hikyuu/strategy/{AccountTradeManager.h → BrokerTradeManager.h} +98 -98
- hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +36 -0
- hikyuu/include/hikyuu/strategy/RunSystemInStrategy.h +37 -0
- hikyuu/include/hikyuu/strategy/Strategy.h +174 -0
- hikyuu/include/hikyuu/trade_manage/FundsRecord.h +8 -8
- hikyuu/include/hikyuu/trade_manage/OrderBrokerBase.h +66 -14
- hikyuu/include/hikyuu/trade_manage/PositionRecord.h +12 -12
- hikyuu/include/hikyuu/trade_manage/TradeManager.h +9 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +19 -0
- hikyuu/include/hikyuu/utilities/TimerManager.h +23 -9
- hikyuu/include/hikyuu/utilities/arithmetic.h +2 -2
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +1 -0
- hikyuu/include/hikyuu/utilities/exception.h +15 -17
- hikyuu/include/hikyuu/utilities/http_client/HttpClient.h +1 -1
- hikyuu/include/hikyuu/utilities/mo/moFileReader.h +1 -1
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/interactive.py +42 -137
- hikyuu/strategy/__init__.py +0 -1
- hikyuu/strategy/strategy_demo1.py +53 -0
- hikyuu/strategy/strategy_demo2.py +47 -0
- hikyuu/strategy/strategy_demo3.py +24 -0
- hikyuu/trade_manage/broker.py +27 -11
- hikyuu/trade_manage/broker_easytrader.py +52 -6
- hikyuu/trade_manage/broker_mail.py +17 -20
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/METADATA +1 -1
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/RECORD +52 -46
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/top_level.txt +0 -1
- hikyuu/include/hikyuu/strategy/StrategyBase.h +0 -156
- hikyuu/strategy/demo/__init__.py +0 -3
- hikyuu/strategy/strategy.py +0 -27
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.1.dist-info → hikyuu-2.1.2.dist-info}/entry_points.txt +0 -0
|
@@ -9,49 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
#include <thread>
|
|
11
11
|
#include <functional>
|
|
12
|
-
#include "spot_generated.h"
|
|
13
12
|
#include "../../DataType.h"
|
|
14
13
|
#include "../../utilities/thread/ThreadPool.h"
|
|
14
|
+
#include "../SpotRecord.h"
|
|
15
15
|
|
|
16
|
-
namespace
|
|
16
|
+
namespace hikyuu {
|
|
17
|
+
namespace flat {
|
|
18
|
+
struct Spot;
|
|
19
|
+
}
|
|
20
|
+
} // namespace hikyuu
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
* 接收外部实时数据结构
|
|
20
|
-
* @ingroup Agent
|
|
21
|
-
*/
|
|
22
|
-
struct HKU_API SpotRecord {
|
|
23
|
-
string market; ///< 市场标识
|
|
24
|
-
string code; ///< 证券代码
|
|
25
|
-
string name; ///< 证券名称
|
|
26
|
-
Datetime datetime; ///< 数据时间
|
|
27
|
-
price_t yesterday_close; ///< 昨日收盘价
|
|
28
|
-
price_t open; ///< 开盘价
|
|
29
|
-
price_t high; ///< 最高价
|
|
30
|
-
price_t low; ///< 最低价
|
|
31
|
-
price_t close; ///< 收盘价
|
|
32
|
-
price_t amount; ///< 成交金额 (千元)
|
|
33
|
-
price_t volume; ///< 成交量(手)
|
|
34
|
-
price_t bid1; ///< 买一价
|
|
35
|
-
price_t bid1_amount; ///< 买一数量(手)
|
|
36
|
-
price_t bid2; ///< 买二价
|
|
37
|
-
price_t bid2_amount; ///< 买二数量
|
|
38
|
-
price_t bid3; ///< 买三价
|
|
39
|
-
price_t bid3_amount; ///< 买三数量
|
|
40
|
-
price_t bid4; ///< 买四价
|
|
41
|
-
price_t bid4_amount; ///< 买四数量
|
|
42
|
-
price_t bid5; ///< 买五价
|
|
43
|
-
price_t bid5_amount; ///< 买五数量
|
|
44
|
-
price_t ask1; ///< 卖一价
|
|
45
|
-
price_t ask1_amount; ///< 卖一数量
|
|
46
|
-
price_t ask2; ///< 卖二价
|
|
47
|
-
price_t ask2_amount; ///< 卖二数量
|
|
48
|
-
price_t ask3; ///< 卖三价
|
|
49
|
-
price_t ask3_amount; ///< 卖三数量
|
|
50
|
-
price_t ask4; ///< 卖四价
|
|
51
|
-
price_t ask4_amount; ///< 卖四数量
|
|
52
|
-
price_t ask5; ///< 卖五价
|
|
53
|
-
price_t ask5_amount; ///< 卖五数量
|
|
54
|
-
};
|
|
22
|
+
namespace hku {
|
|
55
23
|
|
|
56
24
|
/**
|
|
57
25
|
* 接收外部实时数据代理
|
|
@@ -77,6 +45,7 @@ public:
|
|
|
77
45
|
|
|
78
46
|
/** 设置是否打印数据接收进展情况,主要用于在交互环境下关闭打印 */
|
|
79
47
|
void setPrintFlag(bool print) {
|
|
48
|
+
std::lock_guard<std::mutex> lock(m_mutex);
|
|
80
49
|
m_print = print;
|
|
81
50
|
}
|
|
82
51
|
|
|
@@ -136,14 +105,18 @@ private:
|
|
|
136
105
|
enum STATUS { WAITING, RECEIVING }; // 等待新的批次数据,正在接收批次数据中
|
|
137
106
|
enum STATUS m_status = WAITING; // 当前内部状态
|
|
138
107
|
std::atomic_bool m_stop = true; // 结束代理工作标识
|
|
139
|
-
|
|
108
|
+
|
|
140
109
|
int m_revTimeout = 100; // 连接数据服务超时时长(毫秒)
|
|
141
110
|
size_t m_batch_count = 0; // 记录本次批次接收的数据数量
|
|
142
111
|
std::thread m_receiveThread; // 数据接收线程
|
|
143
112
|
ThreadPool m_tg; // 数据处理任务线程池
|
|
113
|
+
vector<std::future<void>> m_process_task_list;
|
|
114
|
+
|
|
115
|
+
// 下面属性被修改时需要加锁,以便可以使用多线程方式运行 strategy
|
|
116
|
+
std::mutex m_mutex;
|
|
117
|
+
bool m_print = true; // 是否打印接收进度,防止的交互模式的影响
|
|
144
118
|
list<std::function<void(const SpotRecord&)>> m_processList; // 已注册的 spot 处理函数列表
|
|
145
119
|
list<std::function<void(Datetime)>> m_postProcessList; // 已注册的批次后处理函数列表
|
|
146
|
-
vector<std::future<void>> m_process_task_list;
|
|
147
120
|
};
|
|
148
121
|
|
|
149
122
|
} // namespace hku
|
hikyuu/include/hikyuu/hikyuu.h
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright(
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Created on: 2024-08-16
|
|
5
|
+
* Author: fasiondog
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
#include <httplib.h>
|
|
12
|
-
#include "../trade_manage/TradeManagerBase.h"
|
|
10
|
+
#include "hikyuu/trade_manage/TradeManagerBase.h"
|
|
13
11
|
|
|
14
12
|
namespace hku {
|
|
15
13
|
|
|
16
|
-
class HKU_API
|
|
14
|
+
class HKU_API BrokerTradeManager : public TradeManagerBase {
|
|
17
15
|
public:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
BrokerTradeManager() = default;
|
|
17
|
+
explicit BrokerTradeManager(const OrderBrokerPtr& broker,
|
|
18
|
+
const TradeCostPtr& costfunc = TC_Zero(),
|
|
19
|
+
const string& name = "SYS");
|
|
20
|
+
virtual ~BrokerTradeManager() {}
|
|
21
21
|
|
|
22
|
-
virtual void _reset() override
|
|
22
|
+
virtual void _reset() override;
|
|
23
23
|
|
|
24
|
-
virtual shared_ptr<TradeManagerBase> _clone() override
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
virtual shared_ptr<TradeManagerBase> _clone() override;
|
|
25
|
+
|
|
26
|
+
virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) override;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 根据权息信息更新当前持仓与交易情况
|
|
30
|
+
* @note 必须按时间顺序调用
|
|
31
|
+
* @param datetime 当前时刻
|
|
32
|
+
*/
|
|
33
|
+
virtual void updateWithWeight(const Datetime& datetime) override {}
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
36
|
* 获取指定对象的保证金比率
|
|
@@ -37,26 +44,22 @@ public:
|
|
|
37
44
|
|
|
38
45
|
/** 初始资金 */
|
|
39
46
|
virtual price_t initCash() const override {
|
|
40
|
-
|
|
41
|
-
return 0.0;
|
|
47
|
+
return m_cash;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/** 账户建立日期 */
|
|
45
51
|
virtual Datetime initDatetime() const override {
|
|
46
|
-
|
|
47
|
-
return Datetime();
|
|
52
|
+
return m_datetime;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
/** 第一笔买入交易发生日期,如未发生交易返回Null<Datetime>() */
|
|
51
56
|
virtual Datetime firstDatetime() const override {
|
|
52
|
-
|
|
53
|
-
return Datetime();
|
|
57
|
+
return m_datetime;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/** 最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期 */
|
|
57
61
|
virtual Datetime lastDatetime() const override {
|
|
58
|
-
|
|
59
|
-
return Datetime();
|
|
62
|
+
return m_datetime;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
/**
|
|
@@ -64,8 +67,7 @@ public:
|
|
|
64
67
|
* @note 仅返回当前信息,不会根据权息进行调整
|
|
65
68
|
*/
|
|
66
69
|
virtual price_t currentCash() const override {
|
|
67
|
-
|
|
68
|
-
return 0.0;
|
|
70
|
+
return m_cash;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
@@ -73,8 +75,7 @@ public:
|
|
|
73
75
|
* @note 如果不带日期参数,无法根据权息信息调整持仓
|
|
74
76
|
*/
|
|
75
77
|
virtual price_t cash(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) override {
|
|
76
|
-
|
|
77
|
-
return 0.0;
|
|
78
|
+
return m_cash;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -84,8 +85,7 @@ public:
|
|
|
84
85
|
* @return true 是 | false 否
|
|
85
86
|
*/
|
|
86
87
|
virtual bool have(const Stock& stock) const override {
|
|
87
|
-
|
|
88
|
-
return false;
|
|
88
|
+
return m_position.count(stock.id()) ? true : false;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
@@ -94,49 +94,48 @@ public:
|
|
|
94
94
|
* @param stock 指定证券
|
|
95
95
|
* @return true 是 | false 否
|
|
96
96
|
*/
|
|
97
|
-
virtual bool haveShort(const Stock& stock) const
|
|
97
|
+
virtual bool haveShort(const Stock& stock) const {
|
|
98
98
|
HKU_WARN("The subclass does not implement this method");
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/** 当前持有的证券种类数量 */
|
|
103
|
-
virtual size_t getStockNumber() const
|
|
104
|
-
|
|
105
|
-
return 0;
|
|
103
|
+
virtual size_t getStockNumber() const {
|
|
104
|
+
return m_position.size();
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
/** 当前空头持有的证券种类数量 */
|
|
109
|
-
virtual size_t getShortStockNumber() const
|
|
108
|
+
virtual size_t getShortStockNumber() const {
|
|
110
109
|
HKU_WARN("The subclass does not implement this method");
|
|
111
110
|
return 0;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
/** 获取指定时刻的某证券持有数量 */
|
|
115
|
-
virtual double getHoldNumber(const Datetime& datetime, const Stock& stock)
|
|
114
|
+
virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) {
|
|
116
115
|
HKU_WARN("The subclass does not implement this method");
|
|
117
116
|
return 0.0;
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
/** 获取指定时刻的空头某证券持有数量 */
|
|
121
|
-
virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock)
|
|
120
|
+
virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) {
|
|
122
121
|
HKU_WARN("The subclass does not implement this method");
|
|
123
122
|
return 0.0;
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
/** 获取指定时刻已借入的股票数量 */
|
|
127
|
-
virtual double getDebtNumber(const Datetime& datetime, const Stock& stock)
|
|
126
|
+
virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) {
|
|
128
127
|
HKU_WARN("The subclass does not implement this method");
|
|
129
128
|
return 0.0;
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
/** 获取指定时刻已借入的现金额 */
|
|
133
|
-
virtual price_t getDebtCash(const Datetime& datetime)
|
|
132
|
+
virtual price_t getDebtCash(const Datetime& datetime) {
|
|
134
133
|
HKU_WARN("The subclass does not implement this method");
|
|
135
134
|
return 0.0;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
/** 获取全部交易记录 */
|
|
139
|
-
virtual TradeRecordList getTradeList() const
|
|
138
|
+
virtual TradeRecordList getTradeList() const {
|
|
140
139
|
HKU_WARN("The subclass does not implement this method");
|
|
141
140
|
return TradeRecordList();
|
|
142
141
|
}
|
|
@@ -147,50 +146,51 @@ public:
|
|
|
147
146
|
* @param end 结束日期
|
|
148
147
|
* @return 交易记录列表
|
|
149
148
|
*/
|
|
150
|
-
virtual TradeRecordList getTradeList(const Datetime& start,
|
|
151
|
-
const Datetime& end) const override {
|
|
149
|
+
virtual TradeRecordList getTradeList(const Datetime& start, const Datetime& end) const {
|
|
152
150
|
HKU_WARN("The subclass does not implement this method");
|
|
153
151
|
return TradeRecordList();
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
/** 获取当前全部持仓记录 */
|
|
157
|
-
virtual PositionRecordList getPositionList() const override
|
|
158
|
-
HKU_WARN("The subclass does not implement this method");
|
|
159
|
-
return PositionRecordList();
|
|
160
|
-
}
|
|
155
|
+
virtual PositionRecordList getPositionList() const override;
|
|
161
156
|
|
|
162
157
|
/** 获取全部历史持仓记录,即已平仓记录 */
|
|
163
|
-
virtual PositionRecordList getHistoryPositionList() const
|
|
158
|
+
virtual PositionRecordList getHistoryPositionList() const {
|
|
164
159
|
HKU_WARN("The subclass does not implement this method");
|
|
165
160
|
return PositionRecordList();
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
/** 获取当前全部空头仓位记录 */
|
|
169
|
-
virtual PositionRecordList getShortPositionList() const
|
|
164
|
+
virtual PositionRecordList getShortPositionList() const {
|
|
170
165
|
HKU_WARN("The subclass does not implement this method");
|
|
171
166
|
return PositionRecordList();
|
|
172
167
|
}
|
|
173
168
|
|
|
174
169
|
/** 获取全部空头历史仓位记录 */
|
|
175
|
-
virtual PositionRecordList getShortHistoryPositionList() const
|
|
170
|
+
virtual PositionRecordList getShortHistoryPositionList() const {
|
|
176
171
|
HKU_WARN("The subclass does not implement this method");
|
|
177
172
|
return PositionRecordList();
|
|
178
173
|
}
|
|
179
174
|
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
/**
|
|
176
|
+
* 获取指定证券的持仓记录
|
|
177
|
+
* @param date 指定日期
|
|
178
|
+
* @param stock 指定的证券
|
|
179
|
+
*/
|
|
180
|
+
virtual PositionRecord getPosition(const Datetime& date, const Stock& stock) override;
|
|
185
181
|
|
|
186
|
-
/**
|
|
187
|
-
|
|
182
|
+
/**
|
|
183
|
+
* 获取指定证券的空头持仓记录
|
|
184
|
+
* @param date 指定日期
|
|
185
|
+
* @param stock 指定的证券
|
|
186
|
+
*/
|
|
187
|
+
virtual PositionRecord getShortPosition(const Stock&) const {
|
|
188
188
|
HKU_WARN("The subclass does not implement this method");
|
|
189
189
|
return PositionRecord();
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
/** 获取当前借入的股票列表 */
|
|
193
|
-
virtual BorrowRecordList getBorrowStockList() const
|
|
193
|
+
virtual BorrowRecordList getBorrowStockList() const {
|
|
194
194
|
HKU_WARN("The subclass does not implement this method");
|
|
195
195
|
return BorrowRecordList();
|
|
196
196
|
}
|
|
@@ -201,10 +201,7 @@ public:
|
|
|
201
201
|
* @param cash 存入的资金量
|
|
202
202
|
* @return true | false
|
|
203
203
|
*/
|
|
204
|
-
virtual bool checkin(const Datetime& datetime, price_t cash) override
|
|
205
|
-
HKU_WARN("The subclass does not implement this method");
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
204
|
+
virtual bool checkin(const Datetime& datetime, price_t cash) override;
|
|
208
205
|
|
|
209
206
|
/**
|
|
210
207
|
* 取出资金
|
|
@@ -213,8 +210,8 @@ public:
|
|
|
213
210
|
* @return true | false
|
|
214
211
|
*/
|
|
215
212
|
virtual bool checkout(const Datetime& datetime, price_t cash) override {
|
|
216
|
-
|
|
217
|
-
return
|
|
213
|
+
m_cash = (cash > m_cash) ? 0.0 : m_cash - cash;
|
|
214
|
+
return true;
|
|
218
215
|
}
|
|
219
216
|
|
|
220
217
|
/**
|
|
@@ -226,7 +223,7 @@ public:
|
|
|
226
223
|
* @return true | false
|
|
227
224
|
*/
|
|
228
225
|
virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
229
|
-
double number)
|
|
226
|
+
double number) {
|
|
230
227
|
HKU_WARN("The subclass does not implement this method");
|
|
231
228
|
return false;
|
|
232
229
|
}
|
|
@@ -241,7 +238,7 @@ public:
|
|
|
241
238
|
* @note 应该不会被用到
|
|
242
239
|
*/
|
|
243
240
|
virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
244
|
-
double number)
|
|
241
|
+
double number) {
|
|
245
242
|
HKU_WARN("The subclass does not implement this method");
|
|
246
243
|
return false;
|
|
247
244
|
}
|
|
@@ -260,10 +257,7 @@ public:
|
|
|
260
257
|
*/
|
|
261
258
|
virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
262
259
|
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
|
263
|
-
price_t planPrice = 0.0, SystemPart from = PART_INVALID) override
|
|
264
|
-
HKU_WARN("The subclass does not implement this method");
|
|
265
|
-
return TradeRecord();
|
|
266
|
-
}
|
|
260
|
+
price_t planPrice = 0.0, SystemPart from = PART_INVALID) override;
|
|
267
261
|
|
|
268
262
|
/**
|
|
269
263
|
* 卖出操作
|
|
@@ -280,10 +274,7 @@ public:
|
|
|
280
274
|
virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
281
275
|
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
|
282
276
|
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
|
283
|
-
SystemPart from = PART_INVALID) override
|
|
284
|
-
HKU_WARN("The subclass does not implement this method");
|
|
285
|
-
return TradeRecord();
|
|
286
|
-
}
|
|
277
|
+
SystemPart from = PART_INVALID) override;
|
|
287
278
|
|
|
288
279
|
/**
|
|
289
280
|
* 卖空
|
|
@@ -299,8 +290,7 @@ public:
|
|
|
299
290
|
*/
|
|
300
291
|
virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
301
292
|
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
|
302
|
-
price_t planPrice = 0.0,
|
|
303
|
-
SystemPart from = PART_INVALID) override {
|
|
293
|
+
price_t planPrice = 0.0, SystemPart from = PART_INVALID) {
|
|
304
294
|
HKU_WARN("The subclass does not implement this method");
|
|
305
295
|
return TradeRecord();
|
|
306
296
|
}
|
|
@@ -320,7 +310,7 @@ public:
|
|
|
320
310
|
virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
|
321
311
|
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
|
322
312
|
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
|
323
|
-
SystemPart from = PART_INVALID)
|
|
313
|
+
SystemPart from = PART_INVALID) {
|
|
324
314
|
HKU_WARN("The subclass does not implement this method");
|
|
325
315
|
return TradeRecord();
|
|
326
316
|
}
|
|
@@ -331,7 +321,7 @@ public:
|
|
|
331
321
|
* @param cash 借入的现金
|
|
332
322
|
* @return true | false
|
|
333
323
|
*/
|
|
334
|
-
virtual bool borrowCash(const Datetime& datetime, price_t cash)
|
|
324
|
+
virtual bool borrowCash(const Datetime& datetime, price_t cash) {
|
|
335
325
|
HKU_WARN("The subclass does not implement this method");
|
|
336
326
|
return false;
|
|
337
327
|
}
|
|
@@ -342,7 +332,7 @@ public:
|
|
|
342
332
|
* @param cash 归还现金
|
|
343
333
|
* @return true | false
|
|
344
334
|
*/
|
|
345
|
-
virtual bool returnCash(const Datetime& datetime, price_t cash)
|
|
335
|
+
virtual bool returnCash(const Datetime& datetime, price_t cash) {
|
|
346
336
|
HKU_WARN("The subclass does not implement this method");
|
|
347
337
|
return false;
|
|
348
338
|
}
|
|
@@ -356,7 +346,7 @@ public:
|
|
|
356
346
|
* @return true | false
|
|
357
347
|
*/
|
|
358
348
|
virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
359
|
-
double number)
|
|
349
|
+
double number) {
|
|
360
350
|
HKU_WARN("The subclass does not implement this method");
|
|
361
351
|
return false;
|
|
362
352
|
}
|
|
@@ -370,11 +360,18 @@ public:
|
|
|
370
360
|
* @return true | false
|
|
371
361
|
*/
|
|
372
362
|
virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price,
|
|
373
|
-
double number)
|
|
363
|
+
double number) {
|
|
374
364
|
HKU_WARN("The subclass does not implement this method");
|
|
375
365
|
return false;
|
|
376
366
|
}
|
|
377
367
|
|
|
368
|
+
/**
|
|
369
|
+
* 获取账户当前时刻的资产详情
|
|
370
|
+
* @param ktype 日期的类型
|
|
371
|
+
* @return 资产详情
|
|
372
|
+
*/
|
|
373
|
+
virtual FundsRecord getFunds(KQuery::KType ktype = KQuery::DAY) const override;
|
|
374
|
+
|
|
378
375
|
/**
|
|
379
376
|
* 获取指定时刻的资产市值详情
|
|
380
377
|
* @param datetime 必须大于帐户建立的初始日期,或为Null<Datetime>()
|
|
@@ -383,10 +380,7 @@ public:
|
|
|
383
380
|
* @note 当datetime等于Null<Datetime>()时,与getFunds(KType)同
|
|
384
381
|
*/
|
|
385
382
|
virtual FundsRecord getFunds(const Datetime& datetime,
|
|
386
|
-
KQuery::KType ktype = KQuery::DAY) override
|
|
387
|
-
HKU_WARN("The subclass does not implement this method");
|
|
388
|
-
return FundsRecord();
|
|
389
|
-
}
|
|
383
|
+
KQuery::KType ktype = KQuery::DAY) override;
|
|
390
384
|
|
|
391
385
|
/**
|
|
392
386
|
* 直接加入交易记录
|
|
@@ -394,38 +388,44 @@ public:
|
|
|
394
388
|
* @param tr 待加入的交易记录
|
|
395
389
|
* @return bool true 成功 | false 失败
|
|
396
390
|
*/
|
|
397
|
-
virtual bool addTradeRecord(const TradeRecord& tr)
|
|
391
|
+
virtual bool addTradeRecord(const TradeRecord& tr) {
|
|
398
392
|
HKU_WARN("The subclass does not implement this method");
|
|
399
393
|
return false;
|
|
400
394
|
}
|
|
401
395
|
|
|
402
|
-
/**
|
|
403
|
-
|
|
396
|
+
/**
|
|
397
|
+
* 直接加入持仓记录
|
|
398
|
+
* @param pr 持仓记录
|
|
399
|
+
* @return true 成功
|
|
400
|
+
* @return false 失败
|
|
401
|
+
*/
|
|
402
|
+
virtual bool addPosition(const PositionRecord& pr) {
|
|
404
403
|
HKU_WARN("The subclass does not implement this method");
|
|
405
|
-
return
|
|
404
|
+
return false;
|
|
406
405
|
}
|
|
407
406
|
|
|
407
|
+
/** 字符串输出 */
|
|
408
|
+
virtual string str() const override;
|
|
409
|
+
|
|
408
410
|
/**
|
|
409
411
|
* 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线
|
|
410
412
|
* @param path 输出文件所在目录
|
|
411
413
|
*/
|
|
412
|
-
virtual void tocsv(const string& path)
|
|
414
|
+
virtual void tocsv(const string& path) {
|
|
413
415
|
HKU_WARN("The subclass does not implement this method");
|
|
414
416
|
}
|
|
415
417
|
|
|
416
418
|
private:
|
|
417
|
-
|
|
419
|
+
Datetime m_datetime; // 当前日期
|
|
418
420
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
string m_token;
|
|
421
|
+
price_t m_cash{0.0}; // 当前可用现金
|
|
422
|
+
|
|
423
|
+
typedef map<uint64_t, PositionRecord> position_map_type;
|
|
424
|
+
position_map_type m_position; // 当前持仓交易对象的持仓记录
|
|
424
425
|
};
|
|
425
426
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
TradeManagerPtr HKU_API crtBrokerTM(const OrderBrokerPtr& broker,
|
|
428
|
+
const TradeCostPtr& costfunc = TC_Zero(),
|
|
429
|
+
const string& name = "SYS");
|
|
429
430
|
|
|
430
|
-
} // namespace hku
|
|
431
|
-
#endif
|
|
431
|
+
} // namespace hku
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-08-25
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/trade_sys/portfolio/Portfolio.h"
|
|
11
|
+
#include "Strategy.h"
|
|
12
|
+
|
|
13
|
+
namespace hku {
|
|
14
|
+
|
|
15
|
+
class HKU_API RunPortfolioInStrategy {
|
|
16
|
+
public:
|
|
17
|
+
RunPortfolioInStrategy() = default;
|
|
18
|
+
RunPortfolioInStrategy(const PFPtr& pf, const KQuery& query, int adjust_cycle,
|
|
19
|
+
const OrderBrokerPtr& broker, const TradeCostPtr& costfunc);
|
|
20
|
+
virtual ~RunPortfolioInStrategy() = default;
|
|
21
|
+
|
|
22
|
+
void run();
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
PFPtr m_pf;
|
|
26
|
+
OrderBrokerPtr m_broker;
|
|
27
|
+
KQuery m_query;
|
|
28
|
+
int m_adjust_cycle;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
StrategyPtr HKU_API crtPFStrategy(const PFPtr& pf, const KQuery& query, int adjust_cycle,
|
|
32
|
+
const OrderBrokerPtr& broker, const TradeCostPtr& costfunc,
|
|
33
|
+
const string& name = "PFStrategy",
|
|
34
|
+
const string& config_file = "");
|
|
35
|
+
|
|
36
|
+
} // namespace hku
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-08-24
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#include "hikyuu/trade_sys/system/System.h"
|
|
10
|
+
#include "Strategy.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API RunSystemInStrategy {
|
|
15
|
+
public:
|
|
16
|
+
RunSystemInStrategy() = default;
|
|
17
|
+
RunSystemInStrategy(const SYSPtr& sys, const OrderBrokerPtr& broker, const KQuery& query,
|
|
18
|
+
const TradeCostPtr& costfunc);
|
|
19
|
+
virtual ~RunSystemInStrategy() = default;
|
|
20
|
+
|
|
21
|
+
void run(const Stock& stock);
|
|
22
|
+
|
|
23
|
+
private:
|
|
24
|
+
SYSPtr m_sys;
|
|
25
|
+
OrderBrokerPtr m_broker;
|
|
26
|
+
KQuery m_query;
|
|
27
|
+
|
|
28
|
+
TradeRequest m_buyRequest;
|
|
29
|
+
TradeRequest m_sellRequest;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
StrategyPtr HKU_API crtSysStrategy(const SYSPtr& sys, const string& stk_market_code,
|
|
33
|
+
const KQuery& query, const OrderBrokerPtr& broker,
|
|
34
|
+
const TradeCostPtr& costfunc, const string& name = "SYSStrategy",
|
|
35
|
+
const string& config_file = "");
|
|
36
|
+
|
|
37
|
+
} // namespace hku
|