1、python中的MM引出默认_reset方法;

2、SYS支持动态盈利目标计算(尚遗留几个测试用例需要修改)
This commit is contained in:
fasiondog 2018-04-25 02:43:55 +08:00
parent 4fa2a35515
commit dce4bb654f
5 changed files with 28 additions and 7 deletions

View File

@ -46,7 +46,7 @@ public:
price_t stoploss; ///< 当前止损价 price_t stoploss; ///< 当前止损价
price_t goalPrice; ///< 当前的目标价格 price_t goalPrice; ///< 当前的目标价格
size_t totalNumber; ///< 累计持仓数量 size_t totalNumber; ///< 累计持仓数量
price_t buyMoney; ///< 累计买入资金 price_t buyMoney; ///< 累计买入资金
price_t totalCost; ///< 累计交易总成本 price_t totalCost; ///< 累计交易总成本
price_t totalRisk; ///< 累计交易风险 = 各次 (买入价格-止损)*买入数量, 不包含交易成本 price_t totalRisk; ///< 累计交易风险 = 各次 (买入价格-止损)*买入数量, 不包含交易成本
price_t sellMoney; ///< 累计卖出资金 price_t sellMoney; ///< 累计卖出资金

View File

@ -159,9 +159,10 @@ size_t MoneyManagerBase
if (getParam<bool>("auto-checkin")) { if (getParam<bool>("auto-checkin")) {
price_t cash = m_tm->currentCash(); price_t cash = m_tm->currentCash();
CostRecord cost = m_tm->getBuyCost(datetime, stock, price, n); 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) { if (money > cash) {
m_tm->checkin(datetime, roundUp(money - cash, stock.precision())); m_tm->checkin(datetime, roundUp(money - cash, precision));
} }
} }

View File

@ -23,7 +23,18 @@ void FixedPercentProfitGoal::_calculate() {
} }
price_t FixedPercentProfitGoal::getGoal(const Datetime& datetime, price_t price) { price_t FixedPercentProfitGoal::getGoal(const Datetime& datetime, price_t price) {
return price * (1 + getParam<double>("p")); Stock stock = getTO().getStock();
PositionRecord position = getTM()->getPosition(stock);
price_t result = Null<price_t>();
if (position.number != 0) {
price_t per_price = position.buyMoney / position.number;
result = per_price * (1 + getParam<double>("p"));
} else {
result = price * (1 + getParam<double>("p"));
}
return result;
//return price * (1 + getParam<double>("p"));
} }
ProfitGoalPtr HKU_API PG_FixedPercent(double p) { ProfitGoalPtr HKU_API PG_FixedPercent(double p) {

View File

@ -441,7 +441,8 @@ void System::_runMoment(const KRecord& today) {
if( position.number != 0) { if( position.number != 0) {
if (current_price <= position.stoploss) { if (current_price <= position.stoploss) {
_sell(today, PART_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); _sell(today, PART_PROFITGOAL);
} else { } else {
price_t current_take_profile = _getTakeProfitPrice(today.datetime); price_t current_take_profile = _getTakeProfitPrice(today.datetime);

View File

@ -87,7 +87,15 @@ public:
} }
void _reset() { void _reset() {
this->get_override("_reset")(); if (override func = get_override("_reset")) {
func();
} else {
MoneyManagerBase::_reset();
}
}
void default_reset() {
this->MoneyManagerBase::_reset();
} }
MoneyManagerPtr _clone() { MoneyManagerPtr _clone() {
@ -130,7 +138,7 @@ void export_MoneyManager() {
&MoneyManagerWrap::default_getSellShortNumber) &MoneyManagerWrap::default_getSellShortNumber)
.def("_getBuyShortNumber", &MoneyManagerBase::_getBuyShortNumber, .def("_getBuyShortNumber", &MoneyManagerBase::_getBuyShortNumber,
&MoneyManagerWrap::default_getBuyShortNumber) &MoneyManagerWrap::default_getBuyShortNumber)
.def("_reset", pure_virtual(&MoneyManagerBase::_reset)) .def("_reset", &MoneyManagerBase::_reset, &MoneyManagerWrap::default_reset)
.def("_clone", pure_virtual(&MoneyManagerBase::_clone)) .def("_clone", pure_virtual(&MoneyManagerBase::_clone))
#if HKU_PYTHON_SUPPORT_PICKLE #if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<MoneyManagerBase>()) .def_pickle(name_init_pickle_suite<MoneyManagerBase>())