Skip to content

Commit

Permalink
AF添加公共参数ignore_se_score_is_null,ignore_se_score_lt_zero
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Feb 7, 2025
1 parent 86beff9 commit 0c0a6b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 0 additions & 1 deletion hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,6 @@ bool TradeManager::_add_buy_tr(const TradeRecord& tr) {
m_cash = roundEx(m_cash - money - tr.cost.total, precision);
new_tr.cash = m_cash;
m_trade_list.push_back(new_tr);
HKU_INFO("{}", new_tr);

// 更新当前持仓记录
position_map_type::iterator pos_iter = m_position.find(tr.stock.id());
Expand Down
23 changes: 21 additions & 2 deletions hikyuu_cpp/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void AllocateFundsBase::initParam() {
// 即,保留分为5份后,仅在2份中保持相对比例
setParam<bool>("ignore_zero_weight", false);

// 忽略选中系统列表中的系统得分为 null 的系统
setParam<bool>("ignore_se_score_is_null", true);

// 忽略选中系统列表中的系统得分小于等于 0 的系统
setParam<bool>("ignore_se_score_lt_zero", false);

setParam<double>("reserve_percent", 0.0); // 保留不参与重分配的资产比例
setParam<bool>("trace", false); // 打印跟踪
}
Expand Down Expand Up @@ -103,11 +109,24 @@ AFPtr AllocateFundsBase::clone() {
SystemWeightList AllocateFundsBase::adjustFunds(const Datetime& date,
const SystemWeightList& se_list,
const std::unordered_set<SYSPtr>& running_list) {
bool ignore_se_score_is_null = getParam<bool>("ignore_se_score_is_null");
bool ignore_se_score_lt_zero = getParam<bool>("ignore_se_score_lt_zero");
SystemWeightList filtered_se_list;
for (auto iter = se_list.begin(); iter != se_list.end(); ++iter) {
if (ignore_se_score_is_null && std::isnan(iter->weight)) {
continue;
}
if (ignore_se_score_lt_zero && iter->weight <= 0.0) {
continue;
}
filtered_se_list.emplace_back(*iter);
}

SystemWeightList result;
if (getParam<bool>("adjust_running_sys")) {
result = _adjust_with_running(date, se_list, running_list);
result = _adjust_with_running(date, filtered_se_list, running_list);
} else {
_adjust_without_running(date, se_list, running_list);
_adjust_without_running(date, filtered_se_list, running_list);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ SystemWeightList FixedWeightListAllocateFunds ::_allocateWeight(const Datetime&
size_t w_total = weights.size();
size_t wi = 0;
for (auto iter = se_list.begin(); iter != se_list.end() && wi < w_total; ++iter) {
if (iter->weight > 0) {
result.emplace_back(iter->sys, weights[wi++]);
}
result.emplace_back(iter->sys, weights[wi++]);
}

return result;
Expand Down

0 comments on commit 0c0a6b1

Please sign in to comment.