From d7651a8c2b4bac88fbbb921a69292e1990512ba6 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 28 May 2024 00:40:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96MM=E5=A4=84=E7=90=86=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E4=B9=B0=E5=85=A5=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; }