mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-04 04:48:17 +08:00
Merge branch 'master' of https://github.com/fasiondog/hikyuu into feature/docs
This commit is contained in:
commit
652a147926
@ -129,15 +129,10 @@ void TradeManager::_reset() {
|
||||
|
||||
TradeManagerPtr TradeManager::_clone() {
|
||||
auto p = make_shared<TradeManager>(m_init_datetime, m_init_cash, m_costfunc, m_name);
|
||||
p->m_params = m_params;
|
||||
p->m_name = m_name;
|
||||
p->m_init_datetime = m_init_datetime;
|
||||
p->m_init_cash = m_init_cash;
|
||||
p->m_last_update_datetime = m_last_update_datetime;
|
||||
|
||||
// costfunc是一个公共的函数对象,是共享实现,无须deepcopy
|
||||
p->m_costfunc = m_costfunc;
|
||||
|
||||
p->m_cash = m_cash;
|
||||
p->m_checkin_cash = m_checkin_cash;
|
||||
p->m_checkout_cash = m_checkout_cash;
|
||||
@ -149,11 +144,7 @@ TradeManagerPtr TradeManager::_clone() {
|
||||
p->m_trade_list = m_trade_list;
|
||||
p->m_position = m_position;
|
||||
p->m_position_history = m_position_history;
|
||||
p->m_broker_list = m_broker_list;
|
||||
p->m_broker_last_datetime = m_broker_last_datetime;
|
||||
|
||||
p->m_actions = m_actions;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,7 @@ public:
|
||||
p->m_name = m_name;
|
||||
p->m_broker_last_datetime = m_broker_last_datetime;
|
||||
p->m_costfunc = m_costfunc;
|
||||
p->m_broker_list = m_broker_list;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ MultiFactorSelector::MultiFactorSelector() : SelectorBase("SE_MultiFactor") {
|
||||
setParam<bool>("only_should_buy", false);
|
||||
setParam<bool>("ignore_null", true); // 是否忽略 MF 中 score 值为 nan 的证券
|
||||
setParam<int>("topn", 10);
|
||||
setParam<bool>("reverse", false); // 逆序,此时 topn 代表最末尾的几个,相当于按最低值排序
|
||||
setParam<int>("ic_n", 5);
|
||||
setParam<int>("ic_rolling_n", 120);
|
||||
setParam<KQuery>("query", KQuery());
|
||||
setParam<Stock>("ref_stk", Stock());
|
||||
setParam<string>("mode", "MF_ICIRWeight");
|
||||
}
|
||||
@ -32,12 +32,14 @@ MultiFactorSelector::MultiFactorSelector(const MFPtr& mf, int topn)
|
||||
setParam<bool>("only_should_buy", false);
|
||||
setParam<bool>("ignore_null", true);
|
||||
setParam<int>("topn", topn);
|
||||
setParam<bool>("reverse", false);
|
||||
|
||||
setParam<int>("ic_n", mf->getParam<int>("ic_n"));
|
||||
setParam<KQuery>("query", mf->getQuery());
|
||||
setParam<Stock>("ref_stk", mf->getRefStock());
|
||||
if (mf->haveParam("ic_rolling_n")) {
|
||||
setParam<int>("ic_rolling_n", mf->getParam<int>("ic_rolling_n"));
|
||||
} else {
|
||||
setParam<int>("ic_rolling_n", 120);
|
||||
}
|
||||
setParam<string>("mode", mf->name());
|
||||
}
|
||||
@ -84,12 +86,35 @@ SystemWeightList MultiFactorSelector::getSelected(Datetime date) {
|
||||
}
|
||||
|
||||
ScoreRecordList scores;
|
||||
if (!getParam<bool>("reverse")) {
|
||||
if (getParam<bool>("ignore_null")) {
|
||||
scores = m_mf->getScores(date, 0, topn,
|
||||
[](const ScoreRecord& sc) { return !std::isnan(sc.value); });
|
||||
} else {
|
||||
scores = m_mf->getScores(date, 0, topn);
|
||||
}
|
||||
} else {
|
||||
ScoreRecordList raw_scores = m_mf->getScores(date);
|
||||
auto iter = raw_scores.rbegin();
|
||||
for (size_t count = 0; count < topn && iter != raw_scores.rend(); ++iter) {
|
||||
if (!std::isnan(iter->value)) {
|
||||
scores.emplace_back(*iter);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (scores.size() < topn && !getParam<bool>("ignore_null")) {
|
||||
size_t lack = topn - scores.size();
|
||||
auto iter = raw_scores.rbegin();
|
||||
for (size_t count = 0; count < lack && iter != raw_scores.rend(); ++iter) {
|
||||
if (std::isnan(iter->value)) {
|
||||
scores.emplace_back(*iter);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getParam<bool>("only_should_buy")) {
|
||||
for (const auto& sc : scores) {
|
||||
@ -118,7 +143,7 @@ void MultiFactorSelector::_calculate() {
|
||||
stks.emplace_back(sys->getStock());
|
||||
}
|
||||
|
||||
auto query = getParam<KQuery>("query");
|
||||
const auto& query = m_query;
|
||||
auto ic_n = getParam<int>("ic_n");
|
||||
auto ic_rolling_n = getParam<int>("ic_rolling_n");
|
||||
auto mode = getParam<string>("mode");
|
||||
|
@ -254,7 +254,6 @@ void export_TradeManager(py::module& m) {
|
||||
|
||||
公共参数:
|
||||
|
||||
- reinvest=False (bool) : 红利是否再投资
|
||||
- precision=2 (int) : 价格计算精度
|
||||
- support_borrow_cash=False (bool) : 是否自动融资
|
||||
- support_borrow_stock=False (bool) : 是否自动融券
|
||||
|
Loading…
Reference in New Issue
Block a user