mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
add TURNOVER 换手率指标
This commit is contained in:
parent
c698cb1ea6
commit
100e6d1d81
@ -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
|
||||
|
@ -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"
|
||||
|
27
hikyuu_cpp/hikyuu/indicator/crt/TURNOVER.cpp
Normal file
27
hikyuu_cpp/hikyuu/indicator/crt/TURNOVER.cpp
Normal 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
|
21
hikyuu_cpp/hikyuu/indicator/crt/TURNOVER.h
Normal file
21
hikyuu_cpp/hikyuu/indicator/crt/TURNOVER.h
Normal 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
|
@ -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++) {
|
||||
|
@ -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: 时间窗口)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user