diff --git a/libs/hikyuu/trade_manage/PositionRecord.h b/libs/hikyuu/trade_manage/PositionRecord.h index f1bcd52c..f8150de3 100644 --- a/libs/hikyuu/trade_manage/PositionRecord.h +++ b/libs/hikyuu/trade_manage/PositionRecord.h @@ -46,7 +46,7 @@ public: price_t stoploss; ///< 当前止损价 price_t goalPrice; ///< 当前的目标价格 size_t totalNumber; ///< 累计持仓数量 - price_t buyMoney; ///< 累计买入资金 + price_t buyMoney; ///< 累计买入资金 price_t totalCost; ///< 累计交易总成本 price_t totalRisk; ///< 累计交易风险 = 各次 (买入价格-止损)*买入数量, 不包含交易成本 price_t sellMoney; ///< 累计卖出资金 diff --git a/libs/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp b/libs/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp index e10299f6..0428df32 100644 --- a/libs/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp +++ b/libs/hikyuu/trade_sys/moneymanager/MoneyManagerBase.cpp @@ -159,9 +159,10 @@ size_t MoneyManagerBase if (getParam("auto-checkin")) { price_t cash = m_tm->currentCash(); CostRecord cost = m_tm->getBuyCost(datetime, stock, price, n); - price_t money = price * n * stock.unit() + cost.total; + int precision = m_tm->precision(); + price_t money = roundUp(price * n * stock.unit() + cost.total, precision); if (money > cash) { - m_tm->checkin(datetime, roundUp(money - cash, stock.precision())); + m_tm->checkin(datetime, roundUp(money - cash, precision)); } } diff --git a/libs/hikyuu/trade_sys/profitgoal/imp/FixedPercentProfitGoal.cpp b/libs/hikyuu/trade_sys/profitgoal/imp/FixedPercentProfitGoal.cpp index 998e2766..7ae34d8c 100644 --- a/libs/hikyuu/trade_sys/profitgoal/imp/FixedPercentProfitGoal.cpp +++ b/libs/hikyuu/trade_sys/profitgoal/imp/FixedPercentProfitGoal.cpp @@ -23,7 +23,18 @@ void FixedPercentProfitGoal::_calculate() { } price_t FixedPercentProfitGoal::getGoal(const Datetime& datetime, price_t price) { - return price * (1 + getParam("p")); + Stock stock = getTO().getStock(); + PositionRecord position = getTM()->getPosition(stock); + price_t result = Null(); + if (position.number != 0) { + price_t per_price = position.buyMoney / position.number; + result = per_price * (1 + getParam("p")); + } else { + result = price * (1 + getParam("p")); + } + + return result; + //return price * (1 + getParam("p")); } ProfitGoalPtr HKU_API PG_FixedPercent(double p) { diff --git a/libs/hikyuu/trade_sys/system/System.cpp b/libs/hikyuu/trade_sys/system/System.cpp index 4937e207..0127191d 100644 --- a/libs/hikyuu/trade_sys/system/System.cpp +++ b/libs/hikyuu/trade_sys/system/System.cpp @@ -441,7 +441,8 @@ void System::_runMoment(const KRecord& today) { if( position.number != 0) { if (current_price <= position.stoploss) { _sell(today, PART_STOPLOSS); - } else if (current_price >= position.goalPrice) { + //} else if (current_price >= position.goalPrice) { + } else if (current_price >= _getGoalPrice(today.datetime, current_price)) { _sell(today, PART_PROFITGOAL); } else { price_t current_take_profile = _getTakeProfitPrice(today.datetime); diff --git a/libs/hikyuu_python/trade_sys/_MoneyManager.cpp b/libs/hikyuu_python/trade_sys/_MoneyManager.cpp index 3bb57c2f..5cc4cedd 100644 --- a/libs/hikyuu_python/trade_sys/_MoneyManager.cpp +++ b/libs/hikyuu_python/trade_sys/_MoneyManager.cpp @@ -87,7 +87,15 @@ public: } void _reset() { - this->get_override("_reset")(); + if (override func = get_override("_reset")) { + func(); + } else { + MoneyManagerBase::_reset(); + } + } + + void default_reset() { + this->MoneyManagerBase::_reset(); } MoneyManagerPtr _clone() { @@ -130,7 +138,7 @@ void export_MoneyManager() { &MoneyManagerWrap::default_getSellShortNumber) .def("_getBuyShortNumber", &MoneyManagerBase::_getBuyShortNumber, &MoneyManagerWrap::default_getBuyShortNumber) - .def("_reset", pure_virtual(&MoneyManagerBase::_reset)) + .def("_reset", &MoneyManagerBase::_reset, &MoneyManagerWrap::default_reset) .def("_clone", pure_virtual(&MoneyManagerBase::_clone)) #if HKU_PYTHON_SUPPORT_PICKLE .def_pickle(name_init_pickle_suite())