diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp index 1736db73..bdb8765f 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp @@ -129,15 +129,10 @@ void TradeManager::_reset() { TradeManagerPtr TradeManager::_clone() { auto p = make_shared(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; } diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h index f201c5e8..5eac5da6 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h @@ -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; } diff --git a/hikyuu_cpp/hikyuu/trade_sys/selector/imp/MultiFactorSelector.cpp b/hikyuu_cpp/hikyuu/trade_sys/selector/imp/MultiFactorSelector.cpp index d46b6aa9..eb86be85 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/selector/imp/MultiFactorSelector.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/selector/imp/MultiFactorSelector.cpp @@ -19,9 +19,9 @@ MultiFactorSelector::MultiFactorSelector() : SelectorBase("SE_MultiFactor") { setParam("only_should_buy", false); setParam("ignore_null", true); // 是否忽略 MF 中 score 值为 nan 的证券 setParam("topn", 10); + setParam("reverse", false); // 逆序,此时 topn 代表最末尾的几个,相当于按最低值排序 setParam("ic_n", 5); setParam("ic_rolling_n", 120); - setParam("query", KQuery()); setParam("ref_stk", Stock()); setParam("mode", "MF_ICIRWeight"); } @@ -32,12 +32,14 @@ MultiFactorSelector::MultiFactorSelector(const MFPtr& mf, int topn) setParam("only_should_buy", false); setParam("ignore_null", true); setParam("topn", topn); + setParam("reverse", false); setParam("ic_n", mf->getParam("ic_n")); - setParam("query", mf->getQuery()); setParam("ref_stk", mf->getRefStock()); if (mf->haveParam("ic_rolling_n")) { setParam("ic_rolling_n", mf->getParam("ic_rolling_n")); + } else { + setParam("ic_rolling_n", 120); } setParam("mode", mf->name()); } @@ -84,11 +86,34 @@ SystemWeightList MultiFactorSelector::getSelected(Datetime date) { } ScoreRecordList scores; - if (getParam("ignore_null")) { - scores = m_mf->getScores(date, 0, topn, - [](const ScoreRecord& sc) { return !std::isnan(sc.value); }); + if (!getParam("reverse")) { + if (getParam("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 { - scores = m_mf->getScores(date, 0, topn); + 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("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("only_should_buy")) { @@ -118,7 +143,7 @@ void MultiFactorSelector::_calculate() { stks.emplace_back(sys->getStock()); } - auto query = getParam("query"); + const auto& query = m_query; auto ic_n = getParam("ic_n"); auto ic_rolling_n = getParam("ic_rolling_n"); auto mode = getParam("mode"); diff --git a/hikyuu_pywrap/trade_manage/_TradeManager.cpp b/hikyuu_pywrap/trade_manage/_TradeManager.cpp index ee214ccf..80d3b7e8 100644 --- a/hikyuu_pywrap/trade_manage/_TradeManager.cpp +++ b/hikyuu_pywrap/trade_manage/_TradeManager.cpp @@ -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) : 是否自动融券