hikyuu 2.3.1__py3-none-win_amd64.whl → 2.5.0__py3-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/__init__.py +438 -6
- hikyuu/__init__.pyi +647 -496
- hikyuu/analysis/__init__.pyi +478 -466
- hikyuu/analysis/analysis.pyi +500 -486
- hikyuu/core.pyi +480 -468
- hikyuu/cpp/__init__.pyi +2 -2
- hikyuu/cpp/core310.pyd +0 -0
- hikyuu/cpp/core311.pyd +0 -0
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/core312.pyi +431 -67
- hikyuu/cpp/core313.pyd +0 -0
- hikyuu/cpp/core38.pyd +0 -0
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/hikyuu.lib +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/data/common_mysql.py +24 -7
- hikyuu/data/common_pytdx.py +17 -1
- hikyuu/data/em_block_to_mysql.py +3 -2
- hikyuu/data/em_block_to_sqlite.py +8 -3
- hikyuu/data/mysql_upgrade/0026.sql +9 -0
- hikyuu/data/sqlite_upgrade/0026.sql +10 -0
- hikyuu/draw/__init__.pyi +35 -0
- hikyuu/draw/drawplot/__init__.pyi +134 -0
- hikyuu/draw/drawplot/bokeh_draw.pyi +796 -0
- hikyuu/draw/drawplot/common.pyi +10 -0
- hikyuu/draw/drawplot/echarts_draw.py +5 -12
- hikyuu/draw/drawplot/echarts_draw.pyi +682 -0
- hikyuu/draw/drawplot/matplotlib_draw.py +18 -3
- hikyuu/draw/drawplot/matplotlib_draw.pyi +1101 -0
- hikyuu/draw/elder.pyi +44 -0
- hikyuu/draw/kaufman.pyi +38 -0
- hikyuu/draw/volume.pyi +31 -0
- hikyuu/examples/notebook/Demo/Demo2.ipynb +1 -1
- hikyuu/extend.py +9 -3
- hikyuu/extend.pyi +524 -504
- hikyuu/fetcher/stock/zh_block_em.py +118 -51
- hikyuu/gui/data/EscapetimeThread.py +4 -4
- hikyuu/gui/data/ImportBlockInfoTask.py +3 -2
- hikyuu/gui/data/ImportHistoryFinanceTask.py +2 -0
- hikyuu/gui/data/MainWindow.py +48 -42
- hikyuu/gui/importdata.py +13 -26
- hikyuu/hub.py +2 -4
- hikyuu/hub.pyi +52 -58
- hikyuu/include/hikyuu/DataType.h +5 -0
- hikyuu/include/hikyuu/Stock.h +7 -0
- hikyuu/include/hikyuu/indicator/Indicator.h +1 -1
- hikyuu/include/hikyuu/indicator/Indicator2InImp.h +65 -0
- hikyuu/include/hikyuu/indicator/IndicatorImp.h +1 -3
- hikyuu/include/hikyuu/indicator/build_in.h +7 -0
- hikyuu/include/hikyuu/indicator/crt/COST.h +3 -0
- hikyuu/include/hikyuu/indicator/crt/CYCLE.h +24 -0
- hikyuu/include/hikyuu/indicator/crt/DISCARD.h +27 -0
- hikyuu/include/hikyuu/indicator/crt/HSL.h +1 -13
- hikyuu/include/hikyuu/indicator/crt/INBLOCK.h +31 -0
- hikyuu/include/hikyuu/indicator/crt/INDEX.h +35 -23
- hikyuu/include/hikyuu/indicator/crt/JUMPDOWN.h +24 -0
- hikyuu/include/hikyuu/indicator/crt/JUMPUP.h +24 -0
- hikyuu/include/hikyuu/indicator/crt/LASTVALUE.h +29 -0
- hikyuu/include/hikyuu/indicator/crt/LIUTONGPAN.h +1 -0
- hikyuu/include/hikyuu/indicator/crt/WINNER.h +38 -0
- hikyuu/include/hikyuu/indicator/imp/ICorr.h +6 -21
- hikyuu/include/hikyuu/indicator/imp/ICost.h +31 -0
- hikyuu/include/hikyuu/indicator/imp/ICycle.h +30 -0
- hikyuu/include/hikyuu/indicator/imp/IDiscard.h +28 -0
- hikyuu/include/hikyuu/indicator/imp/IDma.h +6 -23
- hikyuu/include/hikyuu/indicator/imp/IHsl.h +30 -0
- hikyuu/include/hikyuu/indicator/imp/IInBlock.h +30 -0
- hikyuu/include/hikyuu/indicator/imp/IIndex.h +26 -0
- hikyuu/include/hikyuu/indicator/imp/IJumpDown.h +24 -0
- hikyuu/include/hikyuu/indicator/imp/IJumpUp.h +24 -0
- hikyuu/include/hikyuu/indicator/imp/ILastValue.h +26 -0
- hikyuu/include/hikyuu/indicator/imp/ISpearman.h +5 -20
- hikyuu/include/hikyuu/indicator/imp/IWinner.h +26 -0
- hikyuu/include/hikyuu/indicator_talib/imp/TaMavp.h +5 -19
- hikyuu/include/hikyuu/indicator_talib/imp/ta_defines.h +12 -63
- hikyuu/include/hikyuu/indicator_talib/imp/ta_imp.h +7 -53
- hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +3 -4
- hikyuu/include/hikyuu/strategy/Strategy.h +4 -5
- hikyuu/include/hikyuu/trade_manage/TradeRecord.h +5 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_FixedWeightList.h +22 -0
- hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/FixedWeightListAllocateFunds.h +25 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +17 -4
- hikyuu/include/hikyuu/trade_sys/moneymanager/build_in.h +2 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapital.h +6 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapitalFunds.h +26 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCountTps.h +27 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedRisk.h +6 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedUnits.h +6 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_WilliamsFixedRisk.h +7 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCapitalFundsMM.h +28 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCountTpsMM.h +44 -0
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +38 -37
- hikyuu/include/hikyuu/trade_sys/portfolio/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_Simple.h +25 -1
- hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_WithoutAF.h +50 -0
- hikyuu/include/hikyuu/trade_sys/portfolio/imp/SimplePortfolio.h +53 -0
- hikyuu/include/hikyuu/trade_sys/portfolio/imp/WithoutAFPortfolio.h +57 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +7 -0
- hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +51 -5
- hikyuu/include/hikyuu/trade_sys/signal/build_in.h +2 -0
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Bool.h +2 -1
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Logic.h +37 -0
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_OneSide.h +28 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/OneSideSignal.h +46 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddValueSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivValueSignal.h +22 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulValueSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +68 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +67 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubSignal.h +19 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubValueSignal.h +22 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/stoploss/crt/ST_Indicator.h +1 -1
- hikyuu/include/hikyuu/trade_sys/stoploss/imp/IndicatorStoploss.h +3 -4
- hikyuu/include/hikyuu/utilities/FilterNode.h +2 -2
- hikyuu/include/hikyuu/utilities/Log.h +42 -15
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +1 -1
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +4 -0
- hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +5 -1
- hikyuu/include/hikyuu/utilities/node/NodeServer.h +4 -4
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +2 -2
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +2 -2
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +5 -5
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +2 -2
- hikyuu/include/hikyuu/utilities/thread/algorithm.h +16 -10
- hikyuu/include/hikyuu/version.h +5 -5
- hikyuu/indicator/indicator.py +1 -0
- hikyuu/interactive.py +1 -318
- hikyuu/trade_manage/__init__.pyi +492 -478
- hikyuu/trade_manage/broker.pyi +18 -19
- hikyuu/trade_manage/broker_easytrader.pyi +4 -6
- hikyuu/trade_manage/broker_mail.pyi +24 -22
- hikyuu/trade_manage/trade.pyi +492 -478
- hikyuu/util/check.pyi +15 -17
- hikyuu/util/mylog.pyi +7 -8
- hikyuu/util/notebook.pyi +11 -9
- hikyuu/util/singleton.pyi +6 -8
- hikyuu/util/slice.pyi +2 -1
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/METADATA +2 -2
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/RECORD +151 -105
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/top_level.txt +1 -0
- hikyuu/cpp/core310.pyi +0 -12503
- hikyuu/cpp/core311.pyi +0 -12503
- hikyuu/cpp/core313.pyi +0 -12494
- hikyuu/cpp/core38.pyi +0 -12503
- hikyuu/cpp/core39.pyi +0 -12503
- hikyuu/deprecated.py +0 -651
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/LICENSE +0 -0
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/WHEEL +0 -0
- {hikyuu-2.3.1.dist-info → hikyuu-2.5.0.dist-info}/entry_points.txt +0 -0
|
@@ -448,40 +448,16 @@
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
#define TA_IN2_OUT1_IMP(func, func_lookback) \
|
|
451
|
-
Cls_##func::Cls_##func() :
|
|
452
|
-
setParam<bool>("fill_null", true); \
|
|
453
|
-
} \
|
|
451
|
+
Cls_##func::Cls_##func() : Indicator2InImp(#func, 1) {} \
|
|
454
452
|
Cls_##func::Cls_##func(const Indicator &ref_ind, bool fill_null) \
|
|
455
|
-
:
|
|
456
|
-
setParam<bool>("fill_null", fill_null); \
|
|
457
|
-
} \
|
|
453
|
+
: Indicator2InImp(#func, ref_ind, fill_null, 1) {} \
|
|
458
454
|
Cls_##func::~Cls_##func() {} \
|
|
459
|
-
IndicatorImpPtr Cls_##func::_clone() { \
|
|
460
|
-
auto p = make_shared<Cls_##func>(); \
|
|
461
|
-
p->m_ref_ind = m_ref_ind.clone(); \
|
|
462
|
-
return p; \
|
|
463
|
-
} \
|
|
464
455
|
\
|
|
465
456
|
void Cls_##func::_calculate(const Indicator &ind) { \
|
|
466
457
|
size_t total = ind.size(); \
|
|
467
458
|
HKU_IF_RETURN(total == 0, void()); \
|
|
468
459
|
\
|
|
469
|
-
|
|
470
|
-
\
|
|
471
|
-
auto k = getContext(); \
|
|
472
|
-
m_ref_ind.setContext(k); \
|
|
473
|
-
Indicator ref = m_ref_ind; \
|
|
474
|
-
auto dates = ref.getDatetimeList(); \
|
|
475
|
-
if (dates.empty()) { \
|
|
476
|
-
if (ref.size() > ind.size()) { \
|
|
477
|
-
ref = SLICE(ref, ref.size() - ind.size(), ref.size()); \
|
|
478
|
-
} else if (ref.size() < ind.size()) { \
|
|
479
|
-
ref = CVAL(ind, 0.) + ref; \
|
|
480
|
-
} \
|
|
481
|
-
} else if (m_ref_ind.size() != ind.size()) { \
|
|
482
|
-
ref = ALIGN(m_ref_ind, ind, getParam<bool>("fill_null")); \
|
|
483
|
-
} \
|
|
484
|
-
\
|
|
460
|
+
Indicator ref = prepare(ind); \
|
|
485
461
|
int lookback = func_lookback(); \
|
|
486
462
|
if (lookback < 0) { \
|
|
487
463
|
m_discard = total; \
|
|
@@ -517,20 +493,18 @@
|
|
|
517
493
|
}
|
|
518
494
|
|
|
519
495
|
#define TA_IN2_OUT1_N_IMP(func, func_lookback, period, period_min, period_max) \
|
|
520
|
-
Cls_##func::Cls_##func() :
|
|
496
|
+
Cls_##func::Cls_##func() : Indicator2InImp(#func, 1) { \
|
|
521
497
|
setParam<int>("n", period); \
|
|
522
|
-
setParam<bool>("fill_null", true); \
|
|
523
498
|
} \
|
|
524
499
|
\
|
|
525
|
-
Cls_##func::Cls_##func(int n, bool fill_null) :
|
|
500
|
+
Cls_##func::Cls_##func(int n, bool fill_null) : Indicator2InImp(#func, 1) { \
|
|
526
501
|
setParam<int>("n", n); \
|
|
527
502
|
setParam<bool>("fill_null", fill_null); \
|
|
528
503
|
} \
|
|
529
504
|
\
|
|
530
505
|
Cls_##func::Cls_##func(const Indicator &ref_ind, int n, bool fill_null) \
|
|
531
|
-
:
|
|
506
|
+
: Indicator2InImp(#func, ref_ind, fill_null, 1) { \
|
|
532
507
|
setParam<int>("n", n); \
|
|
533
|
-
setParam<bool>("fill_null", fill_null); \
|
|
534
508
|
} \
|
|
535
509
|
\
|
|
536
510
|
Cls_##func::~Cls_##func() {} \
|
|
@@ -542,31 +516,11 @@
|
|
|
542
516
|
} \
|
|
543
517
|
} \
|
|
544
518
|
\
|
|
545
|
-
IndicatorImpPtr Cls_##func::_clone() { \
|
|
546
|
-
auto p = make_shared<Cls_##func>(); \
|
|
547
|
-
p->m_ref_ind = m_ref_ind.clone(); \
|
|
548
|
-
return p; \
|
|
549
|
-
} \
|
|
550
|
-
\
|
|
551
519
|
void Cls_##func::_calculate(const Indicator &ind) { \
|
|
552
520
|
size_t total = ind.size(); \
|
|
553
521
|
HKU_IF_RETURN(total == 0, void()); \
|
|
554
522
|
\
|
|
555
|
-
|
|
556
|
-
\
|
|
557
|
-
auto k = getContext(); \
|
|
558
|
-
m_ref_ind.setContext(k); \
|
|
559
|
-
Indicator ref = m_ref_ind; \
|
|
560
|
-
auto dates = ref.getDatetimeList(); \
|
|
561
|
-
if (dates.empty()) { \
|
|
562
|
-
if (ref.size() > ind.size()) { \
|
|
563
|
-
ref = SLICE(ref, ref.size() - ind.size(), ref.size()); \
|
|
564
|
-
} else if (ref.size() < ind.size()) { \
|
|
565
|
-
ref = CVAL(ind, 0.) + ref; \
|
|
566
|
-
} \
|
|
567
|
-
} else if (m_ref_ind.size() != ind.size()) { \
|
|
568
|
-
ref = ALIGN(m_ref_ind, ind, getParam<bool>("fill_null")); \
|
|
569
|
-
} \
|
|
523
|
+
Indicator ref = prepare(ind); \
|
|
570
524
|
\
|
|
571
525
|
int n = getParam<int>("n"); \
|
|
572
526
|
int lookback = func_lookback(n); \
|
|
@@ -15,8 +15,8 @@ namespace hku {
|
|
|
15
15
|
class HKU_API RunPortfolioInStrategy {
|
|
16
16
|
public:
|
|
17
17
|
RunPortfolioInStrategy() = default;
|
|
18
|
-
RunPortfolioInStrategy(const PFPtr& pf, const KQuery& query,
|
|
19
|
-
const
|
|
18
|
+
RunPortfolioInStrategy(const PFPtr& pf, const KQuery& query, const OrderBrokerPtr& broker,
|
|
19
|
+
const TradeCostPtr& costfunc);
|
|
20
20
|
virtual ~RunPortfolioInStrategy() = default;
|
|
21
21
|
|
|
22
22
|
void run();
|
|
@@ -25,10 +25,9 @@ private:
|
|
|
25
25
|
PFPtr m_pf;
|
|
26
26
|
OrderBrokerPtr m_broker;
|
|
27
27
|
KQuery m_query;
|
|
28
|
-
int m_adjust_cycle = 1;
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
StrategyPtr HKU_API crtPFStrategy(const PFPtr& pf, const KQuery& query,
|
|
30
|
+
StrategyPtr HKU_API crtPFStrategy(const PFPtr& pf, const KQuery& query,
|
|
32
31
|
const OrderBrokerPtr& broker, const TradeCostPtr& costfunc,
|
|
33
32
|
const string& name = "PFStrategy",
|
|
34
33
|
const std::vector<OrderBrokerPtr>& other_brokers = {},
|
|
@@ -133,8 +133,8 @@ private:
|
|
|
133
133
|
|
|
134
134
|
/** 向线程池提交任务 */
|
|
135
135
|
template <typename FunctionType>
|
|
136
|
-
|
|
137
|
-
typedef typename std::
|
|
136
|
+
auto event(FunctionType f) {
|
|
137
|
+
typedef typename std::invoke_result<FunctionType>::type result_type;
|
|
138
138
|
std::packaged_task<result_type()> task(f);
|
|
139
139
|
event_handle<result_type> res(task.get_future());
|
|
140
140
|
m_event_queue.push(std::move(task));
|
|
@@ -169,13 +169,12 @@ void HKU_API runInStrategy(const SYSPtr& sys, const Stock& stk, const KQuery& qu
|
|
|
169
169
|
* @note 目前仅支持 buy_delay| sell_delay 均为 false 的系统,即 close 时执行交易
|
|
170
170
|
* @param pf 资产组合
|
|
171
171
|
* @param query 查询条件
|
|
172
|
-
* @param adjust_cycle 调仓周期
|
|
173
172
|
* @param broker 订单代理(专用与和账户资产同步的订单代理)
|
|
174
173
|
* @param costfunc 成本函数
|
|
175
174
|
* @param other_brokers 其他的订单代理
|
|
176
175
|
*/
|
|
177
|
-
void HKU_API runInStrategy(const PFPtr& pf, const KQuery& query,
|
|
178
|
-
const
|
|
176
|
+
void HKU_API runInStrategy(const PFPtr& pf, const KQuery& query, const OrderBrokerPtr& broker,
|
|
177
|
+
const TradeCostPtr& costfunc,
|
|
179
178
|
const std::vector<OrderBrokerPtr>& other_brokers = {});
|
|
180
179
|
|
|
181
180
|
/**
|
|
@@ -78,7 +78,7 @@ public:
|
|
|
78
78
|
CostRecord cost; ///< 交易成本
|
|
79
79
|
price_t stoploss; ///< 止损价
|
|
80
80
|
price_t cash; ///< 现金余额
|
|
81
|
-
SystemPart from;
|
|
81
|
+
SystemPart from; ///< 辅助记录交易系统部件,区别是哪个部件发出的指示,Null<int>()表示无效
|
|
82
82
|
|
|
83
83
|
#if HKU_SUPPORT_SERIALIZATION
|
|
84
84
|
private:
|
|
@@ -141,6 +141,10 @@ HKU_API std::ostream& operator<<(std::ostream&, const TradeRecord&);
|
|
|
141
141
|
|
|
142
142
|
bool HKU_API operator==(const TradeRecord& d1, const TradeRecord& d2);
|
|
143
143
|
|
|
144
|
+
inline bool operator!=(const TradeRecord& d1, const TradeRecord& d2) {
|
|
145
|
+
return !(d1 == d2);
|
|
146
|
+
}
|
|
147
|
+
|
|
144
148
|
} /* namespace hku */
|
|
145
149
|
|
|
146
150
|
#if FMT_VERSION >= 90000
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2018年2月8日
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../AllocateFundsBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @brief 固定比例资产分配
|
|
16
|
+
* @param weights 指定的资产比例列表
|
|
17
|
+
* @return AFPtr
|
|
18
|
+
* @ingroup AllocateFunds
|
|
19
|
+
*/
|
|
20
|
+
AFPtr HKU_API AF_FixedWeightList(const vector<double>& weights);
|
|
21
|
+
|
|
22
|
+
} /* namespace hku */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-02-07
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../AllocateFundsBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class FixedWeightListAllocateFunds : public AllocateFundsBase {
|
|
15
|
+
ALLOCATEFUNDS_IMP(FixedWeightListAllocateFunds)
|
|
16
|
+
ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
FixedWeightListAllocateFunds();
|
|
20
|
+
explicit FixedWeightListAllocateFunds(const PriceList& weights);
|
|
21
|
+
virtual ~FixedWeightListAllocateFunds();
|
|
22
|
+
virtual void _checkParam(const string& name) const override;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
} /* namespace hku */
|
|
@@ -71,11 +71,17 @@ public:
|
|
|
71
71
|
/** 克隆操作 */
|
|
72
72
|
MoneyManagerPtr clone();
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
74
|
+
/** 接收实际交易变化情况 */
|
|
75
|
+
void buyNotify(const TradeRecord& tr);
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
virtual void
|
|
77
|
+
/** 子类接收实际交易变化情况接口,一般存在多次增减仓的情况才需要重载 */
|
|
78
|
+
virtual void _buyNotify(const TradeRecord&) {}
|
|
79
|
+
|
|
80
|
+
/** 接收实际交易变化情况 */
|
|
81
|
+
void sellNotify(const TradeRecord& tr);
|
|
82
|
+
|
|
83
|
+
/** 子类接收实际交易变化情况接口,一般存在多次增减仓的情况才需要重载 */
|
|
84
|
+
virtual void _sellNotify(const TradeRecord&) {}
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
87
|
* 获取指定交易对象可卖出的数量
|
|
@@ -122,6 +128,12 @@ public:
|
|
|
122
128
|
double getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
|
123
129
|
SystemPart from);
|
|
124
130
|
|
|
131
|
+
/** 当前买入交易次数, 连续买入计数,一旦接收卖出将恢复置0 */
|
|
132
|
+
size_t currentBuyCount(const Stock&) const;
|
|
133
|
+
|
|
134
|
+
/** 当前卖出交易次数,连续卖出计数,一旦接收买入将恢复置0 */
|
|
135
|
+
size_t currentSellCount(const Stock&) const;
|
|
136
|
+
|
|
125
137
|
virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
|
126
138
|
price_t risk, SystemPart from) = 0;
|
|
127
139
|
|
|
@@ -144,6 +156,7 @@ protected:
|
|
|
144
156
|
string m_name;
|
|
145
157
|
KQuery m_query;
|
|
146
158
|
TradeManagerPtr m_tm;
|
|
159
|
+
unordered_map<Stock, std::pair<size_t, size_t>> m_buy_sell_counts;
|
|
147
160
|
|
|
148
161
|
//============================================
|
|
149
162
|
// 序列化支持
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
#include "crt/MM_FixedPercent.h"
|
|
14
14
|
#include "crt/MM_FixedRisk.h"
|
|
15
15
|
#include "crt/MM_FixedCapital.h"
|
|
16
|
+
#include "crt/MM_FixedCapitalFunds.h"
|
|
16
17
|
#include "crt/MM_FixedCount.h"
|
|
18
|
+
#include "crt/MM_FixedCountTps.h"
|
|
17
19
|
#include "crt/MM_FixedUnits.h"
|
|
18
20
|
#include "crt/MM_WilliamsFixedRisk.h"
|
|
19
21
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-02-19
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_
|
|
10
|
+
#define TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_
|
|
11
|
+
|
|
12
|
+
#include "../MoneyManagerBase.h"
|
|
13
|
+
|
|
14
|
+
namespace hku {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 固定资本管理策略
|
|
18
|
+
* 公式: 买入数量 = 当前总资产 / capital
|
|
19
|
+
* @param capital
|
|
20
|
+
* @return MoneyManagerPtr
|
|
21
|
+
*/
|
|
22
|
+
MoneyManagerPtr HKU_API MM_FixedCapitalFunds(double capital = 10000.00);
|
|
23
|
+
|
|
24
|
+
} /* namespace hku */
|
|
25
|
+
|
|
26
|
+
#endif /* TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_ */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MM_FixedCapital.h
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2016年5月3日
|
|
5
|
+
* Author: Administrator
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_
|
|
10
|
+
#define TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_
|
|
11
|
+
|
|
12
|
+
#include "../MoneyManagerBase.h"
|
|
13
|
+
|
|
14
|
+
namespace hku {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @brief 连续买入/卖出固定数量资金管理策略。
|
|
18
|
+
* @param buy_counts 依次买入数量
|
|
19
|
+
* @param sell_counts 依次卖出数量
|
|
20
|
+
* @return MoneyManagerPtr
|
|
21
|
+
*/
|
|
22
|
+
MoneyManagerPtr HKU_API MM_FixedCountTps(const vector<double>& buy_counts,
|
|
23
|
+
const vector<double>& sell_counts);
|
|
24
|
+
|
|
25
|
+
} /* namespace hku */
|
|
26
|
+
|
|
27
|
+
#endif /* TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_ */
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
|
|
14
14
|
namespace hku {
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 固定风险资金管理策略对每笔交易限定一个预先确定的或者固定的资金风险,如每笔交易固定风险1000元。
|
|
18
|
+
* 公式:交易数量 = 固定风险 / 交易风险。
|
|
19
|
+
* @param risk
|
|
20
|
+
* @return MoneyManagerPtr
|
|
21
|
+
*/
|
|
16
22
|
MoneyManagerPtr HKU_API MM_FixedRisk(double risk = 1000.00);
|
|
17
23
|
|
|
18
24
|
} /* namespace hku */
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
|
|
14
14
|
namespace hku {
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @brief 威廉斯固定风险资金管理策略
|
|
18
|
+
* 买入数量 =(账户余额 × 风险百分比p)÷ 最大损失(max_loss)
|
|
19
|
+
* @param p 风险百分比
|
|
20
|
+
* @param max_loss 最大损失
|
|
21
|
+
* @return MoneyManagerPtr
|
|
22
|
+
*/
|
|
16
23
|
MoneyManagerPtr HKU_API MM_WilliamsFixedRisk(double p = 0.1, price_t max_loss = 1000.0);
|
|
17
24
|
|
|
18
25
|
} // namespace hku
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-02-19
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
|
|
10
|
+
#define TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
|
|
11
|
+
|
|
12
|
+
#include "../MoneyManagerBase.h"
|
|
13
|
+
|
|
14
|
+
namespace hku {
|
|
15
|
+
|
|
16
|
+
class FixedCapitalFundsMM : public MoneyManagerBase {
|
|
17
|
+
MONEY_MANAGER_IMP(FixedCapitalFundsMM)
|
|
18
|
+
MONEY_MANAGER_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
FixedCapitalFundsMM();
|
|
22
|
+
virtual ~FixedCapitalFundsMM();
|
|
23
|
+
virtual void _checkParam(const string& name) const override;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
} /* namespace hku */
|
|
27
|
+
|
|
28
|
+
#endif /* TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_ */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-02-20
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
|
|
10
|
+
#define TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
|
|
11
|
+
|
|
12
|
+
#include "../MoneyManagerBase.h"
|
|
13
|
+
|
|
14
|
+
namespace hku {
|
|
15
|
+
|
|
16
|
+
class FixedCountTpsMM : public MoneyManagerBase {
|
|
17
|
+
public:
|
|
18
|
+
FixedCountTpsMM();
|
|
19
|
+
FixedCountTpsMM(const vector<double>& buy_counts, const vector<double>& sell_counts);
|
|
20
|
+
virtual ~FixedCountTpsMM();
|
|
21
|
+
|
|
22
|
+
virtual MoneyManagerPtr _clone() override;
|
|
23
|
+
virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
|
24
|
+
price_t risk, SystemPart from) override;
|
|
25
|
+
virtual double _getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
|
26
|
+
price_t risk, SystemPart from) override;
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
vector<double> m_buy_counts;
|
|
30
|
+
vector<double> m_sell_counts;
|
|
31
|
+
|
|
32
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
33
|
+
private:
|
|
34
|
+
friend class boost::serialization::access;
|
|
35
|
+
template <class Archive>
|
|
36
|
+
void serialize(Archive& ar, const unsigned int version) {
|
|
37
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(MoneyManagerBase);
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} /* namespace hku */
|
|
43
|
+
|
|
44
|
+
#endif /* TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_ */
|
|
@@ -33,11 +33,13 @@ public:
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* @brief 构造函数
|
|
36
|
+
* @param name 组合名称
|
|
36
37
|
* @param tm 账户
|
|
37
38
|
* @param se 选择器
|
|
38
39
|
* @param af 资产分配算法
|
|
39
40
|
*/
|
|
40
|
-
Portfolio(const
|
|
41
|
+
Portfolio(const string& name, const TradeManagerPtr& tm, const SelectorPtr& se,
|
|
42
|
+
const AFPtr& af);
|
|
41
43
|
|
|
42
44
|
/** 析构函数 */
|
|
43
45
|
virtual ~Portfolio();
|
|
@@ -50,28 +52,10 @@ public:
|
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* @brief 运行资产组合
|
|
53
|
-
* @details
|
|
54
|
-
* <pre>
|
|
55
|
-
* 调仓模式 adjust_mode 说明:
|
|
56
|
-
* - "query" 模式,跟随输入参数 query 中的 ktype,此时 adjust_cycle 为以 query 中的 ktype
|
|
57
|
-
* 决定周期间隔;
|
|
58
|
-
* - "day" 模式,adjust_cycle 为调仓间隔天数
|
|
59
|
-
* - "week" | "month" | "quarter" | "year" 模式时,adjust_cycle
|
|
60
|
-
* 为对应的每周第N日、每月第n日、每季度第n日、每年第n日,在 delay_to_trading_day 为 false 时
|
|
61
|
-
* 如果当日不是交易日将会被跳过调仓;当 delay_to_trading_day 为 true时,如果当日不是交易日
|
|
62
|
-
* 将会顺延至当前周期内的第一个交易日,如指定每月第1日调仓,但当月1日不是交易日,则将顺延至当月
|
|
63
|
-
* 的第一个交易日
|
|
64
|
-
* </pre>
|
|
65
|
-
* @note
|
|
66
|
-
* 由于各个组件可能存在参数变化的情况,无法自动感知判断是否需要重新计算,此时需要手工指定强制计算
|
|
67
55
|
* @param query 查询条件, 其 KType 必须为 KQuery::DAY
|
|
68
|
-
* @param adjust_cycle 调仓周期(受 adjust_mode 影响), 默认为1
|
|
69
56
|
* @param force 是否强制重计算
|
|
70
|
-
* @param adjust_mode 调仓模式 "query" | "day" | "week" | "month" | "year"
|
|
71
|
-
* @param delay_to_trading_day true 时,如果当日不是交易日将会被顺延至当前周期内的第一个交易日
|
|
72
57
|
*/
|
|
73
|
-
void run(const KQuery& query,
|
|
74
|
-
const string& adjust_mode = "query", bool delay_to_trading_day = true);
|
|
58
|
+
void run(const KQuery& query, bool force = false);
|
|
75
59
|
|
|
76
60
|
/** 修改查询条件 */
|
|
77
61
|
void setQuery(const KQuery& query);
|
|
@@ -97,33 +81,43 @@ public:
|
|
|
97
81
|
/** 设置资产分配算法 */
|
|
98
82
|
void setAF(const AFPtr& af);
|
|
99
83
|
|
|
84
|
+
const SystemList& getRealSystemList() const;
|
|
85
|
+
|
|
100
86
|
/** 复位操作 */
|
|
101
87
|
void reset();
|
|
102
88
|
|
|
89
|
+
/** 克隆操作 */
|
|
103
90
|
typedef shared_ptr<Portfolio> PortfolioPtr;
|
|
91
|
+
PortfolioPtr clone() const;
|
|
104
92
|
|
|
105
|
-
/**
|
|
106
|
-
|
|
93
|
+
/** 运行前准备 */
|
|
94
|
+
void readyForRun();
|
|
107
95
|
|
|
108
|
-
|
|
109
|
-
const SystemList& getSystemList() const;
|
|
96
|
+
void runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust);
|
|
110
97
|
|
|
111
|
-
/**
|
|
112
|
-
|
|
98
|
+
/** 用于打印输出 */
|
|
99
|
+
virtual string str() const;
|
|
113
100
|
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
virtual void _reset() {}
|
|
102
|
+
virtual PortfolioPtr _clone() const {
|
|
103
|
+
return std::make_shared<Portfolio>();
|
|
104
|
+
}
|
|
116
105
|
|
|
117
|
-
|
|
118
|
-
void
|
|
106
|
+
virtual void _readyForRun() {}
|
|
107
|
+
virtual void _runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust) {}
|
|
119
108
|
|
|
120
|
-
|
|
109
|
+
private:
|
|
110
|
+
void initParam();
|
|
121
111
|
|
|
122
112
|
void _runOnMode(const DatetimeList& datelist, int adjust_cycle, const string& mode);
|
|
123
113
|
|
|
124
114
|
void _runOnModeDelayToTradingDay(const DatetimeList& datelist, int adjust_cycle,
|
|
125
115
|
const string& mode);
|
|
126
116
|
|
|
117
|
+
protected:
|
|
118
|
+
// 跟踪打印当前TM持仓情况
|
|
119
|
+
void traceMomentTM(const Datetime& date);
|
|
120
|
+
|
|
127
121
|
protected:
|
|
128
122
|
string m_name;
|
|
129
123
|
TMPtr m_tm;
|
|
@@ -138,10 +132,6 @@ protected:
|
|
|
138
132
|
|
|
139
133
|
// 用于中间计算的临时数据
|
|
140
134
|
std::unordered_set<SYSPtr> m_running_sys_set;
|
|
141
|
-
SystemList m_dlist_sys_list; // 因证券退市,无法执行买入的系统(资产全部损失)
|
|
142
|
-
SystemWeightList m_delay_adjust_sys_list; // 延迟调仓卖出的系统列表
|
|
143
|
-
SystemWeightList m_tmp_selected_list;
|
|
144
|
-
SystemWeightList m_tmp_will_remove_sys;
|
|
145
135
|
|
|
146
136
|
//============================================
|
|
147
137
|
// 序列化支持
|
|
@@ -158,7 +148,6 @@ private:
|
|
|
158
148
|
ar& BOOST_SERIALIZATION_NVP(m_se);
|
|
159
149
|
ar& BOOST_SERIALIZATION_NVP(m_af);
|
|
160
150
|
ar& BOOST_SERIALIZATION_NVP(m_query);
|
|
161
|
-
ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
|
|
162
151
|
}
|
|
163
152
|
|
|
164
153
|
template <class Archive>
|
|
@@ -170,13 +159,25 @@ private:
|
|
|
170
159
|
ar& BOOST_SERIALIZATION_NVP(m_se);
|
|
171
160
|
ar& BOOST_SERIALIZATION_NVP(m_af);
|
|
172
161
|
ar& BOOST_SERIALIZATION_NVP(m_query);
|
|
173
|
-
ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
|
|
174
162
|
}
|
|
175
163
|
|
|
176
164
|
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
|
177
165
|
#endif /* HKU_SUPPORT_SERIALIZATION */
|
|
178
166
|
};
|
|
179
167
|
|
|
168
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
169
|
+
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Portfolio)
|
|
170
|
+
#endif
|
|
171
|
+
|
|
172
|
+
#define PORTFOLIO_IMP(classname) \
|
|
173
|
+
public: \
|
|
174
|
+
virtual PortfolioPtr _clone() const override { \
|
|
175
|
+
return std::make_shared<classname>(); \
|
|
176
|
+
} \
|
|
177
|
+
virtual void _reset() override; \
|
|
178
|
+
virtual void _readyForRun() override; \
|
|
179
|
+
virtual void _runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust) override;
|
|
180
|
+
|
|
180
181
|
/**
|
|
181
182
|
* 客户程序都应使用该指针类型
|
|
182
183
|
* @ingroup Selector
|
|
@@ -15,8 +15,32 @@
|
|
|
15
15
|
|
|
16
16
|
namespace hku {
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @brief 创建资产组合
|
|
20
|
+
* @details
|
|
21
|
+
* <pre>
|
|
22
|
+
* 调仓模式 adjust_mode 说明:
|
|
23
|
+
* - "query" 模式,跟随输入参数 query 中的 ktype,此时 adjust_cycle 为以 query 中的 ktype
|
|
24
|
+
* 决定周期间隔;
|
|
25
|
+
* - "day" 模式,adjust_cycle 为调仓间隔天数
|
|
26
|
+
* - "week" | "month" | "quarter" | "year" 模式时,adjust_cycle
|
|
27
|
+
* 为对应的每周第N日、每月第n日、每季度第n日、每年第n日,在 delay_to_trading_day 为 false 时
|
|
28
|
+
* 如果当日不是交易日将会被跳过调仓;当 delay_to_trading_day 为 true时,如果当日不是交易日
|
|
29
|
+
* 将会顺延至当前周期内的第一个交易日,如指定每月第1日调仓,但当月1日不是交易日,则将顺延至当月
|
|
30
|
+
* 的第一个交易日
|
|
31
|
+
* </pre>
|
|
32
|
+
* @param tm 交易账户
|
|
33
|
+
* @param se 系统选择器
|
|
34
|
+
* @param af 资金分配算法
|
|
35
|
+
* @param adjust_cycle 调仓周期(受 adjust_mode 影响), 默认为1
|
|
36
|
+
* @param adjust_mode 调仓模式 "query" | "day" | "week" | "month" | "year"
|
|
37
|
+
* @param delay_to_trading_day true 时,如果调仓日不是交易日将会被顺延至当前周期内的第一个交易日
|
|
38
|
+
* @return 组合实例
|
|
39
|
+
*/
|
|
18
40
|
PortfolioPtr HKU_API PF_Simple(const TMPtr& tm = TradeManagerPtr(), const SEPtr& se = SE_Fixed(),
|
|
19
|
-
const AFPtr& af = AF_EqualWeight()
|
|
41
|
+
const AFPtr& af = AF_EqualWeight(), int adjust_cycle = 1,
|
|
42
|
+
const string& adjust_mode = "query",
|
|
43
|
+
bool delay_to_trading_day = true);
|
|
20
44
|
|
|
21
45
|
} /* namespace hku */
|
|
22
46
|
|