IC, ICIR及相关MultiFactor 增加 spearman 参数,控制是否使用 spearman 计算相关系数

This commit is contained in:
fasiondog 2024-09-26 11:51:21 +08:00
parent b7fa7f66e3
commit ed7be6c4a6
17 changed files with 106 additions and 71 deletions

View File

@ -18,23 +18,24 @@ namespace hku {
* @param query
* @param ref_stk sh000300 300
* @param n ( n )
* @param spearman 使 spearman pearson
* @return Indicator
* @ingroup Indicator
*/
Indicator HKU_API IC(const StockList& stks, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1);
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
Indicator HKU_API IC(const Block& blk, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1);
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
inline Indicator IC(const Indicator& ind, const StockList& stks, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1) {
return IC(stks, query, ref_stk, n)(ind);
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
return IC(stks, query, ref_stk, n, spearman)(ind);
}
inline Indicator IC(const Indicator& ind, const Block& blk, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1) {
return IC(blk, query, ref_stk, n)(ind);
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
return IC(blk, query, ref_stk, n, spearman)(ind);
}
} // namespace hku

View File

@ -22,12 +22,14 @@ namespace hku {
* @param ref_stk sh000300 300
* @param n IC对应的N日收益率
* @param rolling_n
* @param spearman 使 spearman pearson
* @return Indicator
* @ingroup Indicator
*/
inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120) {
Indicator ic = IC(ind, stks, query, ref_stk, n);
const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
bool spearman = true) {
Indicator ic = IC(ind, stks, query, ref_stk, n, spearman);
Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
x.name("ICIR");
x.setParam<int>("n", n);
@ -36,8 +38,9 @@ inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery&
}
inline Indicator ICIR(const Indicator& ind, const Block& blk, const KQuery& query,
const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120) {
Indicator ic = IC(ind, blk, query, ref_stk, n);
const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
bool spearman = true) {
Indicator ic = IC(ind, blk, query, ref_stk, n, spearman);
Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
x.name("ICIR");
x.setParam<int>("n", n);

View File

@ -11,6 +11,7 @@
#include "hikyuu/indicator/crt/ROCP.h"
#include "hikyuu/indicator/crt/PRICELIST.h"
#include "hikyuu/indicator/crt/SPEARMAN.h"
#include "hikyuu/indicator/crt/CORR.h"
#include "IIc.h"
#if HKU_SUPPORT_SERIALIZATION
@ -23,12 +24,14 @@ IIc::IIc() : IndicatorImp("IC", 1) {
setParam<int>("n", 1); // 调仓周期
// 对齐时是否以 nan 值进行填充,否则以小于当前日期的最后值作为填充
setParam<bool>("fill_null", true);
setParam<bool>("use_spearman", true); // 默认使用SPEARMAN计算相关系数, 否则使用pearson相关系数
}
IIc::IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk)
IIc::IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman)
: IndicatorImp("IC", 1), m_query(query), m_ref_stk(ref_stk), m_stks(stks) {
setParam<int>("n", n);
setParam<bool>("fill_null", true);
setParam<bool>("use_spearman", spearman);
}
IIc::~IIc() {}
@ -89,6 +92,11 @@ void IIc::_calculate(const Indicator& inputInd) {
m_discard = discard;
HKU_IF_RETURN(m_discard >= days_total, void());
Indicator (*spearman)(const Indicator&, const Indicator&, int) = hku::SPEARMAN;
if (!getParam<bool>("use_spearman")) {
spearman = hku::CORR;
}
PriceList tmp(stk_count, Null<price_t>());
PriceList tmp_return(stk_count, Null<price_t>());
auto* dst = this->data();
@ -100,7 +108,7 @@ void IIc::_calculate(const Indicator& inputInd) {
}
auto a = PRICELIST(tmp);
auto b = PRICELIST(tmp_return);
auto ic = hku::SPEARMAN(a, b, stk_count);
auto ic = spearman(a, b, stk_count);
dst[i] = ic[ic.size() - 1];
}
@ -112,13 +120,15 @@ void IIc::_calculate(const Indicator& inputInd) {
}
}
Indicator HKU_API IC(const StockList& stks, const KQuery& query, const Stock& ref_stk, int n) {
return Indicator(make_shared<IIc>(stks, query, n, ref_stk));
Indicator HKU_API IC(const StockList& stks, const KQuery& query, const Stock& ref_stk, int n,
bool spearman) {
return Indicator(make_shared<IIc>(stks, query, n, ref_stk, spearman));
}
Indicator HKU_API IC(const Block& blk, const KQuery& query, const Stock& ref_stk, int n) {
Indicator HKU_API IC(const Block& blk, const KQuery& query, const Stock& ref_stk, int n,
bool spearman) {
StockList stks = blk.getStockList();
return IC(stks, query, ref_stk, n);
return IC(stks, query, ref_stk, n, spearman);
}
} // namespace hku

View File

@ -14,7 +14,7 @@ namespace hku {
class IIc : public IndicatorImp {
public:
IIc();
IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk);
IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman);
virtual ~IIc();
virtual void _checkParam(const string& name) const override;

View File

@ -14,6 +14,7 @@
#include "hikyuu/indicator/crt/IC.h"
#include "hikyuu/indicator/crt/ICIR.h"
#include "hikyuu/indicator/crt/SPEARMAN.h"
#include "hikyuu/indicator/crt/CORR.h"
#include "hikyuu/indicator/crt/ZSCORE.h"
#include "MultiFactorBase.h"
@ -77,9 +78,10 @@ MultiFactorBase::MultiFactorBase(const MultiFactorBase& base)
MultiFactorBase::MultiFactorBase(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, const string& name,
int ic_n)
int ic_n, bool spearman)
: m_name(name), m_inds(inds), m_stks(stks), m_ref_stk(ref_stk), m_query(query) {
initParam();
setParam<bool>("spearman", spearman);
setParam<int>("ic_n", ic_n);
checkParam("ic_n");
_checkData();
@ -93,6 +95,7 @@ void MultiFactorBase::initParam() {
setParam<bool>("zscore_out_extreme", false);
setParam<bool>("zscore_recursive", false);
setParam<double>("zscore_nsigma", 3.0);
setParam<bool>("use_spearman", true); // 默认使用SPEARMAN计算相关系数, 否则使用pearson相关系数
}
void MultiFactorBase::baseCheckParam(const string& name) const {
@ -358,6 +361,11 @@ Indicator MultiFactorBase::getIC(int ndays) {
result.setDiscard(discard);
Indicator (*spearman)(const Indicator&, const Indicator&, int) = hku::SPEARMAN;
if (!getParam<bool>("use_spearman")) {
spearman = hku::CORR;
}
PriceList tmp(ind_count, Null<price_t>());
PriceList tmp_return(ind_count, Null<price_t>());
auto* dst = result.data();
@ -368,7 +376,7 @@ Indicator MultiFactorBase::getIC(int ndays) {
}
auto a = PRICELIST(tmp);
auto b = PRICELIST(tmp_return);
auto ic = hku::SPEARMAN(a, b, ind_count);
auto ic = spearman(a, b, ind_count);
dst[i] = ic[ic.size() - 1];
}

View File

@ -29,7 +29,7 @@ public:
MultiFactorBase();
explicit MultiFactorBase(const string& name);
MultiFactorBase(const IndicatorList& inds, const StockList& stks, const KQuery& query,
const Stock& ref_stk, const string& name, int ic_n);
const Stock& ref_stk, const string& name, int ic_n, bool spearman);
MultiFactorBase(const MultiFactorBase&);
virtual ~MultiFactorBase() = default;

View File

@ -17,10 +17,12 @@ namespace hku {
* @param query
* @param ref_stk
* @param ic_n IC N
* @param spearman 使 spearman pearson
* @return MultiFactorPtr
*/
MultiFactorPtr HKU_API MF_EqualWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n = 5);
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
bool spearman = true);
MultiFactorPtr HKU_API MF_EqualWeight();

View File

@ -19,11 +19,12 @@ namespace hku {
* @param ref_stk
* @param ic_n IC N
* @param ic_rolling_n IC
* @param spearman 使 spearman pearson
* @return MultiFactorPtr
*/
MultiFactorPtr HKU_API MF_ICIRWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
int ic_rolling_n = 120);
int ic_rolling_n = 120, bool spearman = true);
MultiFactorPtr HKU_API MF_ICIRWeight();
}
} // namespace hku

View File

@ -19,10 +19,12 @@ namespace hku {
* @param ref_stk
* @param ic_n IC N
* @param ic_rolling_n IC
* @param spearman 使 spearman pearson
* @return MultiFactorPtr
*/
MultiFactorPtr HKU_API MF_ICWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
int ic_rolling_n = 120);
int ic_rolling_n = 120, bool spearman = true);
MultiFactorPtr HKU_API MF_ICWeight();
}
} // namespace hku

View File

@ -7,9 +7,6 @@
#include "hikyuu/utilities/thread/algorithm.h"
#include "hikyuu/indicator/crt/PRICELIST.h"
#include "hikyuu/indicator/crt/IC.h"
#include "hikyuu/indicator/crt/ICIR.h"
#include "hikyuu/indicator/crt/SPEARMAN.h"
#include "EqualWeightMultiFactor.h"
#if HKU_SUPPORT_SERIALIZATION
@ -21,8 +18,9 @@ namespace hku {
EqualWeightMultiFactor::EqualWeightMultiFactor() : MultiFactorBase("MF_EqualWeight") {}
EqualWeightMultiFactor::EqualWeightMultiFactor(const vector<Indicator>& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_EqualWeight", ic_n) {}
const KQuery& query, const Stock& ref_stk, int ic_n,
bool spearman)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_EqualWeight", ic_n, spearman) {}
vector<Indicator> EqualWeightMultiFactor::_calculate(
const vector<vector<Indicator>>& all_stk_inds) {
@ -116,8 +114,9 @@ MultiFactorPtr HKU_API MF_EqualWeight() {
}
MultiFactorPtr HKU_API MF_EqualWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n) {
return make_shared<EqualWeightMultiFactor>(inds, stks, query, ref_stk, ic_n);
const KQuery& query, const Stock& ref_stk, int ic_n,
bool spearman) {
return make_shared<EqualWeightMultiFactor>(inds, stks, query, ref_stk, ic_n, spearman);
}
} // namespace hku

View File

@ -18,7 +18,7 @@ class EqualWeightMultiFactor : public MultiFactorBase {
public:
EqualWeightMultiFactor();
EqualWeightMultiFactor(const vector<Indicator>& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n);
const KQuery& query, const Stock& ref_stk, int ic_n, bool spearman);
virtual ~EqualWeightMultiFactor() = default;
};

View File

@ -9,7 +9,6 @@
#include "hikyuu/indicator/crt/PRICELIST.h"
#include "hikyuu/indicator/crt/IC.h"
#include "hikyuu/indicator/crt/ICIR.h"
#include "hikyuu/indicator/crt/SPEARMAN.h"
#include "ICIRMultiFactor.h"
#if HKU_SUPPORT_SERIALIZATION
@ -24,8 +23,8 @@ ICIRMultiFactor::ICIRMultiFactor() : MultiFactorBase("MF_ICIRWeight") {
ICIRMultiFactor::ICIRMultiFactor(const vector<Indicator>& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n,
int ic_rolling_n)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_ICIRWeight", ic_n) {
int ic_rolling_n, bool spearman)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_ICIRWeight", ic_n, spearman) {
setParam<int>("ic_rolling_n", ic_rolling_n);
checkParam("ic_rolling_n");
}
@ -43,20 +42,22 @@ IndicatorList ICIRMultiFactor::_calculate(const vector<IndicatorList>& all_stk_i
int ic_n = getParam<int>("ic_n");
int ir_n = getParam<int>("ic_rolling_n");
bool spearman = getParam<bool>("use_spearman");
#if !MF_USE_MULTI_THREAD
size_t discard = 0;
vector<Indicator> icir(ind_count);
for (size_t ii = 0; ii < ind_count; ii++) {
icir[ii] = ICIR(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, ir_n);
icir[ii] = ICIR(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, ir_n, spearman);
if (icir[ii].discard() > discard) {
discard = icir[ii].discard();
}
}
#else
vector<Indicator> icir = parallel_for_index(0, ind_count, [this, ic_n, ir_n](size_t ii) {
return ICIR(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, ir_n);
});
vector<Indicator> icir =
parallel_for_index(0, ind_count, [this, ic_n, ir_n, spearman](size_t ii) {
return ICIR(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, ir_n, spearman);
});
size_t discard = 0;
for (size_t ii = 0; ii < ind_count; ii++) {
@ -147,8 +148,8 @@ MultiFactorPtr HKU_API MF_ICIRWeight() {
MultiFactorPtr HKU_API MF_ICIRWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n,
int ic_rolling_n) {
return make_shared<ICIRMultiFactor>(inds, stks, query, ref_stk, ic_n, ic_rolling_n);
int ic_rolling_n, bool spearman) {
return make_shared<ICIRMultiFactor>(inds, stks, query, ref_stk, ic_n, ic_rolling_n, spearman);
}
} // namespace hku

View File

@ -18,7 +18,7 @@ class ICIRMultiFactor : public MultiFactorBase {
public:
ICIRMultiFactor();
ICIRMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
const Stock& ref_stk, int ic_n, int ic_rolling_n);
const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
virtual ~ICIRMultiFactor() = default;
virtual void _checkParam(const string& name) const override;

View File

@ -9,7 +9,6 @@
#include "hikyuu/indicator/crt/PRICELIST.h"
#include "hikyuu/indicator/crt/IC.h"
#include "hikyuu/indicator/crt/MA.h"
#include "hikyuu/indicator/crt/SPEARMAN.h"
#include "ICMultiFactor.h"
#if HKU_SUPPORT_SERIALIZATION
@ -23,8 +22,8 @@ ICMultiFactor::ICMultiFactor() : MultiFactorBase("MF_ICWeight") {
}
ICMultiFactor::ICMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
const Stock& ref_stk, int ic_n, int ic_rolling_n)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_ICWeight", ic_n) {
const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman)
: MultiFactorBase(inds, stks, query, ref_stk, "MF_ICWeight", ic_n, spearman) {
setParam<int>("ic_rolling_n", ic_rolling_n);
checkParam("ic_rolling_n");
}
@ -42,21 +41,23 @@ IndicatorList ICMultiFactor::_calculate(const vector<IndicatorList>& all_stk_ind
int ic_n = getParam<int>("ic_n");
int ic_rolling_n = getParam<int>("ic_rolling_n");
bool spearman = getParam<bool>("use_spearman");
// 计算每个原始因子的滚动IC值
#if !MF_USE_MULTI_THREAD
size_t discard = 0;
IndicatorList ic(ind_count);
for (size_t ii = 0; ii < ind_count; ii++) {
ic[ii] = MA(IC(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n), ic_rolling_n);
ic[ii] = MA(IC(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, spearman), ic_rolling_n);
if (ic[ii].discard() > discard) {
discard = ic[ii].discard();
}
}
#else
IndicatorList ic = parallel_for_index(0, ind_count, [this, ic_n, ic_rolling_n](size_t ii) {
return MA(IC(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n), ic_rolling_n);
});
IndicatorList ic =
parallel_for_index(0, ind_count, [this, ic_n, ic_rolling_n, spearman](size_t ii) {
return MA(IC(m_inds[ii], m_stks, m_query, m_ref_stk, ic_n, spearman), ic_rolling_n);
});
size_t discard = 0;
for (size_t ii = 0; ii < ind_count; ii++) {
if (ic[ii].discard() > discard) {
@ -148,8 +149,9 @@ MultiFactorPtr HKU_API MF_ICWeight() {
MultiFactorPtr HKU_API MF_ICWeight(const IndicatorList& inds, const StockList& stks,
const KQuery& query, const Stock& ref_stk, int ic_n,
int ic_rolling_n) {
return std::make_shared<ICMultiFactor>(inds, stks, query, ref_stk, ic_n, ic_rolling_n);
int ic_rolling_n, bool spearman) {
return std::make_shared<ICMultiFactor>(inds, stks, query, ref_stk, ic_n, ic_rolling_n,
spearman);
}
} // namespace hku

View File

@ -18,7 +18,7 @@ class ICMultiFactor : public MultiFactorBase {
public:
ICMultiFactor();
ICMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
const Stock& ref_stk, int ic_n, int ic_rolling_n);
const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
virtual ~ICMultiFactor() = default;
virtual void _checkParam(const string& name) const override;

View File

@ -1748,20 +1748,21 @@ void export_Indicator_build_in(py::module& m) {
m.def(
"IC",
[](const Indicator& ind, const py::object& stks, const KQuery& query, const Stock& ref_stk,
int n) {
int n, bool spearman) {
if (py::isinstance<Block>(stks)) {
const auto& blk = stks.cast<Block&>();
return IC(ind, blk, query, ref_stk, n);
return IC(ind, blk, query, ref_stk, n, spearman);
}
if (py::isinstance<py::sequence>(stks)) {
StockList c_stks = python_list_to_vector<Stock>(stks);
return IC(ind, c_stks, query, ref_stk, n);
return IC(ind, c_stks, query, ref_stk, n, spearman);
}
HKU_THROW("Input stks must be Block or sequenc(Stock)!");
},
py::arg("ind"), py::arg("stks"), py::arg("query"), py::arg("ref_stk"), py::arg("n") = 1,
py::arg("spearman") = true,
R"(IC(ind, stks, query, ref_stk[, n=1])
IC RankIC
@ -1770,26 +1771,27 @@ void export_Indicator_build_in(py::module& m) {
:param sequence(stock)|Block stks
:param Query query:
:param Stock ref_stk: 使 sh000300 300
:param int n: )");
:param int n:
:param bool spearman: 使 spearman pearson)");
m.def(
"ICIR",
[](const Indicator& ind, const py::object& stks, const KQuery& query, const Stock& ref_stk,
int n, int rolling_n) {
int n, int rolling_n, bool spearman) {
if (py::isinstance<Block>(stks)) {
const auto& blk = stks.cast<Block&>();
return ICIR(ind, blk, query, ref_stk, n, rolling_n);
return ICIR(ind, blk, query, ref_stk, n, rolling_n, spearman);
}
if (py::isinstance<py::sequence>(stks)) {
StockList c_stks = python_list_to_vector<Stock>(stks);
return ICIR(ind, c_stks, query, ref_stk, n, rolling_n);
return ICIR(ind, c_stks, query, ref_stk, n, rolling_n, spearman);
}
HKU_THROW("Input stks must be Block or sequenc(Stock)!");
},
py::arg("ind"), py::arg("stks"), py::arg("query"), py::arg("ref_stk"), py::arg("n") = 1,
py::arg("rolling_n") = 120,
py::arg("rolling_n") = 120, py::arg("spearman") = true,
R"(ICIR(ind, stks, query, ref_stk[, n=1, rolling_n=120])
IC IR = IC的多周期均值/IC的标准方差
@ -1799,7 +1801,8 @@ void export_Indicator_build_in(py::module& m) {
:param Query query:
:param Stock ref_stk: 使 sh000300 300
:param int n: IC时对应的 n
:param int rolling_n: )");
:param int rolling_n:
:param bool spearman: 使 spearman pearson)");
m.def("ZSCORE", ZSCORE_1, py::arg("out_extreme") = false, py::arg("nsigma") = 3.0,
py::arg("recursive") = false);

View File

@ -194,15 +194,15 @@ void export_MultiFactor(py::module& m) {
m.def(
"MF_EqualWeight",
[](const py::sequence& inds, const py::sequence& stks, const KQuery& query,
const py::object& ref_stk, int ic_n) {
const py::object& ref_stk, int ic_n, bool spearman) {
IndicatorList c_inds = python_list_to_vector<Indicator>(inds);
StockList c_stks = python_list_to_vector<Stock>(stks);
return MF_EqualWeight(c_inds, c_stks, query,
ref_stk.is_none() ? getStock("sh000300") : ref_stk.cast<Stock>(),
ic_n);
ic_n, spearman);
},
py::arg("inds"), py::arg("stks"), py::arg("query"), py::arg("ref_stk") = py::none(),
py::arg("ic_n") = 5,
py::arg("ic_n") = 5, py::arg("spearman") = true,
R"(MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5])
@ -212,21 +212,22 @@ void export_MultiFactor(py::module& m) {
:param Query query:
:param Stock ref_stk: ( sh000300 300)
:param int ic_n: IC N
:param bool spearman: 使 spearman pearson
:rtype: MultiFactor)");
m.def("MF_ICWeight", py::overload_cast<>(MF_ICWeight));
m.def(
"MF_ICWeight",
[](const py::sequence& inds, const py::sequence& stks, const KQuery& query,
const py::object& ref_stk, int ic_n, int ic_rolling_n) {
const py::object& ref_stk, int ic_n, int ic_rolling_n, bool spearman) {
IndicatorList c_inds = python_list_to_vector<Indicator>(inds);
StockList c_stks = python_list_to_vector<Stock>(stks);
return MF_ICWeight(c_inds, c_stks, query,
ref_stk.is_none() ? getStock("sh000300") : ref_stk.cast<Stock>(), ic_n,
ic_rolling_n);
ic_rolling_n, spearman);
},
py::arg("inds"), py::arg("stks"), py::arg("query"), py::arg("ref_stk") = py::none(),
py::arg("ic_n") = 5, py::arg("ic_rolling_n") = 120,
py::arg("ic_n") = 5, py::arg("ic_rolling_n") = 120, py::arg("spearman") = true,
R"(MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])
IC权重合成因子
@ -237,21 +238,22 @@ void export_MultiFactor(py::module& m) {
:param Stock ref_stk: ( sh000300 300)
:param int ic_n: IC N
:param int ic_rolling_n: IC
:param bool spearman: 使 spearman pearson
:rtype: MultiFactor)");
m.def("MF_ICIRWeight", py::overload_cast<>(MF_ICIRWeight));
m.def(
"MF_ICIRWeight",
[](const py::sequence& inds, const py::sequence& stks, const KQuery& query,
const py::object& ref_stk, int ic_n, int ic_rolling_n) {
const py::object& ref_stk, int ic_n, int ic_rolling_n, bool spearman) {
IndicatorList c_inds = python_list_to_vector<Indicator>(inds);
StockList c_stks = python_list_to_vector<Stock>(stks);
return MF_ICIRWeight(c_inds, c_stks, query,
ref_stk.is_none() ? getStock("sh000300") : ref_stk.cast<Stock>(),
ic_n, ic_rolling_n);
ic_n, ic_rolling_n, spearman);
},
py::arg("inds"), py::arg("stks"), py::arg("query"), py::arg("ref_stk") = py::none(),
py::arg("ic_n") = 5, py::arg("ic_rolling_n") = 120,
py::arg("ic_n") = 5, py::arg("ic_rolling_n") = 120, py::arg("spearman") = true,
R"(MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])
ICIR权重合成因子
@ -262,5 +264,6 @@ void export_MultiFactor(py::module& m) {
:param Stock ref_stk: ( sh000300 300)
:param int ic_n: IC N
:param int ic_rolling_n: IC
:param bool spearman: 使 spearman pearson
:rtype: MultiFactor)");
}