优化MM处理最大买入量

This commit is contained in:
fasiondog 2024-05-28 00:40:16 +08:00
parent 33d3c99d28
commit d7651a8c2b

View File

@ -139,13 +139,14 @@ double MoneyManagerBase::getBuyNumber(const Datetime& datetime, const Stock& sto
m_tm->checkin(datetime, roundUp(money - cash, precision));
}
} else {
int precision = m_tm->getParam<int>("precision");
CostRecord cost = m_tm->getBuyCost(datetime, stock, price, n);
price_t need_cash = n * price + cost.total;
price_t need_cash = roundUp(n * price + cost.total, precision);
price_t current_cash = m_tm->cash(datetime, m_query.kType());
while (n > min_trade && need_cash > current_cash) {
n = n - min_trade;
cost = m_tm->getBuyCost(datetime, stock, price, n);
need_cash = n * price + cost.total;
need_cash = roundUp(n * price + cost.total, precision);
}
n = need_cash > current_cash ? 0 : n;
}