mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
优化MM处理最大买入量
This commit is contained in:
parent
33d3c99d28
commit
d7651a8c2b
@ -139,13 +139,14 @@ double MoneyManagerBase::getBuyNumber(const Datetime& datetime, const Stock& sto
|
|||||||
m_tm->checkin(datetime, roundUp(money - cash, precision));
|
m_tm->checkin(datetime, roundUp(money - cash, precision));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
int precision = m_tm->getParam<int>("precision");
|
||||||
CostRecord cost = m_tm->getBuyCost(datetime, stock, price, n);
|
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());
|
price_t current_cash = m_tm->cash(datetime, m_query.kType());
|
||||||
while (n > min_trade && need_cash > current_cash) {
|
while (n > min_trade && need_cash > current_cash) {
|
||||||
n = n - min_trade;
|
n = n - min_trade;
|
||||||
cost = m_tm->getBuyCost(datetime, stock, price, n);
|
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;
|
n = need_cash > current_cash ? 0 : n;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user