diff --git a/hikyuu_cpp/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp b/hikyuu_cpp/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp index fb7c312f..5e54106b 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp @@ -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("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; }