add TURNOVER 换手率指标

This commit is contained in:
fasiondog 2024-04-06 23:54:06 +08:00
parent c698cb1ea6
commit 100e6d1d81
6 changed files with 65 additions and 4 deletions

View File

@ -62,8 +62,6 @@ Indicator.__getitem__ = indicator_getitem
Indicator.__iter__ = indicator_iter
VALUE = PRICELIST
try:
import numpy as np
import pandas as pd
@ -89,8 +87,6 @@ except:
"you can't use method Inidicator.to_np() and to_df!"
)
VALUE = PRICELIST
def concat_to_df(dates, ind_list, head_stock_code=True, head_ind_name=False):
"""将列表中的指标至合并在一张 pandas DataFrame 中
@ -143,3 +139,7 @@ HIGH = C_HIGH()
LOW = C_LOW()
AMO = C_AMO()
VOL = C_VOL()
# 同名指标
VALUE = PRICELIST
CAPITAL = LIUTONGPANG

View File

@ -98,6 +98,7 @@
#include "crt/TIME.h"
#include "crt/TIMELINE.h"
#include "crt/TIMELINEVOL.h"
#include "crt/TURNOVER.h"
#include "crt/UPNDAY.h"
#include "crt/VAR.h"
#include "crt/VARP.h"

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 hikyuu.org
*
* Created on: 2024-04-06
* Author: fasiondog
*/
#include "KDATA.h"
#include "SUM.h"
#include "LIUTONGPAN.h"
#include "TURNOVER.h"
namespace hku {
// 不需要乘以 100成交量已经是手数即100
Indicator HKU_API TURNOVER(int n) {
HKU_ASSERT(n >= 1);
return n == 1 ? (VOL() / LIUTONGPAN()) : (SUM(VOL(), n) / SUM(LIUTONGPAN(), n));
}
Indicator HKU_API TURNOVER(const KData& kdata, int n) {
HKU_ASSERT(n >= 1);
return n == 1 ? (kdata.vol() / LIUTONGPAN(kdata))
: (SUM(kdata.vol(), n) / SUM(LIUTONGPAN(kdata), n));
}
} // namespace hku

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 hikyuu.org
*
* Created on: 2024-04-06
* Author: fasiondog
*/
#include "../Indicator.h"
namespace hku {
/**
* @brief =/×100%
* @param n
* @return Indicator
*/
Indicator HKU_API TURNOVER(int n = 1);
Indicator HKU_API TURNOVER(const KData& kdata, int n = 1);
} // namespace hku

View File

@ -47,6 +47,11 @@ void ISum::_calculate(const Indicator& ind) {
}
m_discard = ind.discard();
if (n == 1) {
memcpy(dst, src, total * sizeof(value_t));
return;
}
price_t sum = 0.0;
for (size_t i = m_discard, len = (m_discard + n) >= total ? total : m_discard + n; i < len;
i++) {

View File

@ -1808,4 +1808,11 @@ void export_Indicator_build_in(py::module& m) {
:param float nsigma: 使 nsigma sigma 3.0
:param bool recursive: False
:rtype: Indicator)");
m.def("TURNOVER", py::overload_cast<int>(TURNOVER), py::arg("n") = 1);
m.def("TURNOVER", py::overload_cast<const KData&, int>(TURNOVER), py::arg("kdata"),
py::arg("n") = 1, R"(TURNOVER(data[,n=1])
=/×100%
:param int n: )");
}