Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Mar 5, 2022
2 parents 650814c + 0b583c4 commit 9a6f376
Show file tree
Hide file tree
Showing 49 changed files with 1,540 additions and 142 deletions.
12 changes: 11 additions & 1 deletion docs/source/indicator/indicator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
指数移动平均线(Exponential Moving Average)

:param data: 输入数据
:param int n: 计算均值的周期窗口,必须为大于0的整数
:param int|Indciator|IndParam n: 计算均值的周期窗口,必须为大于0的整数
:rtype: Indicator


Expand Down Expand Up @@ -771,6 +771,16 @@
:rtype: Indicator


.. py:function:: SLICE(data, start, end, result_index=0)
获取某指标中指定范围 [start, end) 的数据,生成新的指标

:param Indicator|PriceList data: 输入数据
:param int start: 起始位置
:param int end: 终止位置(不包含本身)
:param int result_index: 原输入数据中的结果集


.. py:function:: SMA([data, n=22, m=2])
求移动平均
Expand Down
38 changes: 19 additions & 19 deletions hikyuu/data/mysql_upgrade/0007.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220103);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220131);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220201);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220202);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220203);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220204);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220205);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220404);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220405);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220502);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220503);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220504);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220603);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20220912);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20221003);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20221004);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20221005);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20221006);
INSERT INTO `hku_base`."Holiday" (`date`) VALUES (20221007);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220103);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220131);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220201);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220202);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220203);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220204);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220205);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220404);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220405);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220502);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220503);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220504);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220603);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20220912);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20221003);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20221004);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20221005);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20221006);
INSERT INTO `hku_base`.`Holiday` (`date`) VALUES (20221007);
UPDATE `hku_base`.`version` set `version` = 7;
38 changes: 19 additions & 19 deletions hikyuu/data/sqlite_upgrade/0008.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
BEGIN TRANSACTION;
INSERT INTO "Holiday" (`date`) VALUES (20220103);
INSERT INTO "Holiday" (`date`) VALUES (20220131);
INSERT INTO "Holiday" (`date`) VALUES (20220201);
INSERT INTO "Holiday" (`date`) VALUES (20220202);
INSERT INTO "Holiday" (`date`) VALUES (20220203);
INSERT INTO "Holiday" (`date`) VALUES (20220204);
INSERT INTO "Holiday" (`date`) VALUES (20220205);
INSERT INTO "Holiday" (`date`) VALUES (20220404);
INSERT INTO "Holiday" (`date`) VALUES (20220405);
INSERT INTO "Holiday" (`date`) VALUES (20220502);
INSERT INTO "Holiday" (`date`) VALUES (20220503);
INSERT INTO "Holiday" (`date`) VALUES (20220504);
INSERT INTO "Holiday" (`date`) VALUES (20220603);
INSERT INTO "Holiday" (`date`) VALUES (20220912);
INSERT INTO "Holiday" (`date`) VALUES (20221003);
INSERT INTO "Holiday" (`date`) VALUES (20221004);
INSERT INTO "Holiday" (`date`) VALUES (20221005);
INSERT INTO "Holiday" (`date`) VALUES (20221006);
INSERT INTO "Holiday" (`date`) VALUES (20221007);
INSERT INTO `Holiday` (`date`) VALUES (20220103);
INSERT INTO `Holiday` (`date`) VALUES (20220131);
INSERT INTO `Holiday` (`date`) VALUES (20220201);
INSERT INTO `Holiday` (`date`) VALUES (20220202);
INSERT INTO `Holiday` (`date`) VALUES (20220203);
INSERT INTO `Holiday` (`date`) VALUES (20220204);
INSERT INTO `Holiday` (`date`) VALUES (20220205);
INSERT INTO `Holiday` (`date`) VALUES (20220404);
INSERT INTO `Holiday` (`date`) VALUES (20220405);
INSERT INTO `Holiday` (`date`) VALUES (20220502);
INSERT INTO `Holiday` (`date`) VALUES (20220503);
INSERT INTO `Holiday` (`date`) VALUES (20220504);
INSERT INTO `Holiday` (`date`) VALUES (20220603);
INSERT INTO `Holiday` (`date`) VALUES (20220912);
INSERT INTO `Holiday` (`date`) VALUES (20221003);
INSERT INTO `Holiday` (`date`) VALUES (20221004);
INSERT INTO `Holiday` (`date`) VALUES (20221005);
INSERT INTO `Holiday` (`date`) VALUES (20221006);
INSERT INTO `Holiday` (`date`) VALUES (20221007);
UPDATE `version` set `version` = 8;
COMMIT;
4 changes: 2 additions & 2 deletions hikyuu_cpp/demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
#endif

//配置文件的位置自行修改
hikyuu_init("C:\\Users\\Administrator\\.hikyuu\\hikyuu.ini");
hikyuu_init("C:\\Users\\admin\\.hikyuu\\hikyuu.ini");

StockManager& sm = StockManager::instance();

Expand All @@ -42,6 +42,6 @@ int main(int argc, char* argv[]) {

#if defined(_WIN32)
SetConsoleOutputCP(old_cp);
#endif
#endif
return 0;
}
4 changes: 2 additions & 2 deletions hikyuu_cpp/hikyuu/hikyuu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void hikyuu_init(const string& config_file_name, bool ignore_preload,
config.read(config_file_name);

} catch (std::invalid_argument& e) {
HKU_FATAL("Reading configure error!\n{}", e.what());
HKU_FATAL("Reading configure error! {}", e.what());
exit(1);
} catch (std::logic_error& e) {
HKU_FATAL("Reading configure error!\n{}", e.what());
HKU_FATAL("Reading configure error! {}", e.what());
exit(1);
} catch (...) {
HKU_WARN("Reading configure error! Don't know error!");
Expand Down
19 changes: 19 additions & 0 deletions hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ void IndicatorImp::_dyn_calculate(const Indicator &ind) {
size_t step = size_t(ind_param->get(i));
_dyn_run_one_step(ind, i, step);
}
_update_discard();
return;
}

Expand Down Expand Up @@ -1300,6 +1301,24 @@ void IndicatorImp::_dyn_calculate(const Indicator &ind) {
for (auto &task : tasks) {
task.get();
}

_update_discard();
}

void IndicatorImp::_update_discard() {
size_t total = size();
for (size_t result_index = 0; result_index < m_result_num; result_index++) {
size_t discard = m_discard;
for (size_t i = m_discard; i < total; i++) {
if (!std::isnan(get(i, result_index))) {
break;
}
discard++;
}
if (discard > m_discard) {
m_discard = discard;
}
}
}

} /* namespace hku */
3 changes: 3 additions & 0 deletions hikyuu_cpp/hikyuu/indicator/IndicatorImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class HKU_API IndicatorImp : public enable_shared_from_this<IndicatorImp> {
protected:
static size_t _get_step_start(size_t pos, size_t step, size_t discard);

// 用于动态参数时,更新 discard
void _update_discard();

protected:
string m_name;
size_t m_discard;
Expand Down
1 change: 1 addition & 0 deletions hikyuu_cpp/hikyuu/indicator/build_in.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "crt/ROUNDUP.h"
#include "crt/SAFTYLOSS.h"
#include "crt/SIN.h"
#include "crt/SLICE.h"
#include "crt/SGN.h"
#include "crt/SMA.h"
#include "crt/SQRT.h"
Expand Down
78 changes: 77 additions & 1 deletion hikyuu_cpp/hikyuu/indicator/crt/AMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ namespace hku {
* @ingroup Indicator 具有2个结果集,result(0)为AMA,result(1)为ER
*/
Indicator HKU_API AMA(int n = 10, int fast_n = 2, int slow_n = 30);
Indicator HKU_API AMA(int n, int fast_n, const IndParam& slow_n);
Indicator HKU_API AMA(int n, const IndParam& fast_n, int slow_n = 30);
Indicator HKU_API AMA(int n, const IndParam& fast_n, const IndParam& slow_n);

Indicator HKU_API AMA(const IndParam& n, int fast_n = 2, int slow_n = 30);
Indicator HKU_API AMA(const IndParam& n, int fast_n, const IndParam& slow_n);
Indicator HKU_API AMA(const IndParam& n, const IndParam& fast_n, int slow_n = 30);
Indicator HKU_API AMA(const IndParam& n, const IndParam& fast_n, const IndParam& slow_n);

/**
* 佩里.J 考夫曼(Perry J.Kaufman)自适应移动平均,参见《精明交易者》(2006年 广东经济出版社)
Expand All @@ -30,7 +38,75 @@ Indicator HKU_API AMA(int n = 10, int fast_n = 2, int slow_n = 30);
* @param slow_n 对应慢速EMA线的N值,默认为30,不过当超过60左右该指标会收敛不会有太大的影响
* @ingroup Indicator
*/
Indicator HKU_API AMA(const Indicator& indicator, int n = 10, int fast_n = 2, int slow_n = 30);
inline Indicator HKU_API AMA(const Indicator& ind, int n = 10, int fast_n = 2, int slow_n = 30) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, const IndParam& fast_n, int slow_n = 30) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, int fast_n, const IndParam& slow_n) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, const IndParam& fast_n,
const IndParam& slow_n) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const IndParam& n, int fast_n = 2,
int slow_n = 30) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const IndParam& n, const IndParam& fast_n,
int slow_n = 30) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const IndParam& n, int fast_n,
const IndParam& slow_n) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const IndParam& n, const IndParam& fast_n,
const IndParam& slow_n) {
return AMA(n, fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, const Indicator& fast_n, int slow_n) {
return AMA(n, IndParam(fast_n), slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, int fast_n, const Indicator& slow_n) {
return AMA(n, fast_n, IndParam(slow_n))(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, int n, const Indicator& fast_n,
const Indicator& slow_n) {
return AMA(n, IndParam(fast_n), IndParam(slow_n))(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const Indicator& n, int fast_n = 2,
int slow_n = 30) {
return AMA(IndParam(n), fast_n, slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const Indicator& n, const Indicator& fast_n,
int slow_n = 30) {
return AMA(IndParam(n), IndParam(fast_n), slow_n)(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const Indicator& n, int fast_n,
const Indicator& slow_n) {
return AMA(IndParam(n), fast_n, IndParam(slow_n))(ind);
}

inline Indicator HKU_API AMA(const Indicator& ind, const Indicator& n, const Indicator& fast_n,
const Indicator& slow_n) {
return AMA(IndParam(n), IndParam(fast_n), IndParam(slow_n))(ind);
}

} // namespace hku

Expand Down
13 changes: 12 additions & 1 deletion hikyuu_cpp/hikyuu/indicator/crt/ATR.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@ namespace hku {
* @ingroup Indicator
*/
Indicator HKU_API ATR(int n = 14);
Indicator HKU_API ATR(const IndParam& n);

/**
* 平均真实波幅(Average True Range)
* @param data 待计算的源数据
* @param n 计算均值的周期窗口,必须为大于1的整数
* @ingroup Indicator
*/
Indicator HKU_API ATR(const Indicator& data, int n = 14);
inline Indicator HKU_API ATR(const Indicator& data, int n = 14) {
return ATR(n)(data);
}

inline Indicator HKU_API ATR(const Indicator& data, const IndParam& n) {
return ATR(n)(data);
}

inline Indicator HKU_API ATR(const Indicator& data, const Indicator& n) {
return ATR(IndParam(n))(data);
}

} // namespace hku

Expand Down
13 changes: 12 additions & 1 deletion hikyuu_cpp/hikyuu/indicator/crt/EMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@ namespace hku {
* @ingroup Indicator
*/
Indicator HKU_API EMA(int n = 22);
Indicator HKU_API EMA(const IndParam& n);

/**
* 指数移动平均线(Exponential Moving Average)
* @param data 待计算的源数据
* @param n 计算均值的周期窗口,必须为大于0的整数
* @ingroup Indicator
*/
Indicator HKU_API EMA(const Indicator& data, int n = 22);
inline Indicator HKU_API EMA(const Indicator& data, int n = 22) {
return EMA(n)(data);
}

inline Indicator HKU_API EMA(const Indicator& data, const IndParam& n) {
return EMA(n)(data);
}

inline Indicator HKU_API EMA(const Indicator& data, const Indicator& n) {
return EMA(IndParam(n))(data);
}

} // namespace hku

Expand Down
Loading

0 comments on commit 9a6f376

Please sign in to comment.