mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
买卖数量数据类型从size_t变更为double
This commit is contained in:
parent
82a08790d9
commit
1ea7c147fb
@ -65,7 +65,7 @@ MoneyManagerPtr MoneyManagerBase::clone() {
|
||||
return p;
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase ::getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double MoneyManagerBase ::getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
if (!m_tm) {
|
||||
HKU_ERROR("m_tm is null! Datetime({}) Stock({}) price({:<.4f}) risk({:<.2f})", datetime,
|
||||
@ -76,30 +76,24 @@ size_t MoneyManagerBase ::getSellNumber(const Datetime& datetime, const Stock& s
|
||||
if (PART_ENVIRONMENT == from) {
|
||||
if (false == getParam<bool>("disable_ev_force_clean_position")) {
|
||||
//强制全部卖出
|
||||
return Null<size_t>();
|
||||
return MAX_DOUBLE;
|
||||
}
|
||||
}
|
||||
|
||||
if (PART_CONDITION == from) {
|
||||
if (false == getParam<bool>("disable_cn_force_clean_position")) {
|
||||
return Null<size_t>();
|
||||
return MAX_DOUBLE;
|
||||
}
|
||||
}
|
||||
|
||||
if (risk <= 0.0) {
|
||||
// HKU_WARN("risk is zero! Will not sell! "
|
||||
// << "Datetime(" << datetime << ") Stock("
|
||||
// << stock.market_code() << ") price(" << price
|
||||
// << ") risk(" << risk
|
||||
// << ") [MoneyManagerBase::getSellNumber]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _getSellNumber(datetime, stock, price, risk, from);
|
||||
;
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase ::getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double MoneyManagerBase ::getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
if (!m_tm) {
|
||||
HKU_ERROR("m_tm is null! Datetime({}) Stock({}) price({:<.3f}) risk({:<.2f})", datetime,
|
||||
@ -123,8 +117,8 @@ size_t MoneyManagerBase ::getBuyNumber(const Datetime& datetime, const Stock& st
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t n = _getBuyNumber(datetime, stock, price, risk, from);
|
||||
size_t min_trade = stock.minTradeNumber();
|
||||
double n = _getBuyNumber(datetime, stock, price, risk, from);
|
||||
double min_trade = stock.minTradeNumber();
|
||||
|
||||
if (n < min_trade) {
|
||||
HKU_TRACE("Ignore! Is less than the minimum number of transactions({})", min_trade);
|
||||
@ -132,8 +126,8 @@ size_t MoneyManagerBase ::getBuyNumber(const Datetime& datetime, const Stock& st
|
||||
}
|
||||
|
||||
//转换为最小交易量的整数倍
|
||||
n = (n / min_trade) * min_trade;
|
||||
size_t max_trade = stock.maxTradeNumber();
|
||||
n = long(n / min_trade) * min_trade;
|
||||
double max_trade = stock.maxTradeNumber();
|
||||
|
||||
if (n > max_trade) {
|
||||
n = max_trade;
|
||||
@ -164,7 +158,7 @@ size_t MoneyManagerBase ::getBuyNumber(const Datetime& datetime, const Stock& st
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase ::getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
double MoneyManagerBase ::getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
if (!m_tm) {
|
||||
HKU_ERROR("m_tm is null! Datetime({}) Stock({}) price({:<.3f}) risk({:<.2f})", datetime,
|
||||
@ -181,7 +175,7 @@ size_t MoneyManagerBase ::getSellShortNumber(const Datetime& datetime, const Sto
|
||||
return _getSellShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase ::getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
double MoneyManagerBase ::getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
if (!m_tm) {
|
||||
HKU_ERROR("m_tm is null! Datetime({}) Stock({}) price({:<.3f}) risk({:<.2f})", datetime,
|
||||
@ -198,19 +192,18 @@ size_t MoneyManagerBase ::getBuyShortNumber(const Datetime& datetime, const Stoc
|
||||
return _getBuyShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase::_getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double MoneyManagerBase::_getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
//默认卖出全部
|
||||
// return m_tm->getHoldNumber(datetime, stock);
|
||||
return Null<size_t>();
|
||||
return MAX_DOUBLE;
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase::_getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
double MoneyManagerBase::_getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t MoneyManagerBase::_getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
double MoneyManagerBase::_getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -91,9 +91,9 @@ public:
|
||||
* @param price 交易价格
|
||||
* @param risk 新的交易承担的风险,如果为0,表示全部损失,即市值跌至0元
|
||||
* @param from 信号来源
|
||||
* @note 默认实现返回Null<size_t>() 卖出全部; 多次减仓才需要实现该接口
|
||||
* @note 默认实现返回 MAX_DOUBLE 卖出全部; 多次减仓才需要实现该接口
|
||||
*/
|
||||
size_t getSellNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
double getSellNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
SystemPart from);
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ public:
|
||||
* @param from 信号来源
|
||||
* @param risk 承担的交易风险,如果为Null<price_t>,表示不设损失上限
|
||||
*/
|
||||
size_t getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from);
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ public:
|
||||
* @param from 信号来源
|
||||
* @param risk 承担的交易风险,如果为Null<price_t>,表示不设损失上限
|
||||
*/
|
||||
size_t getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from);
|
||||
|
||||
/**
|
||||
@ -126,19 +126,19 @@ public:
|
||||
* @param from 信号来源
|
||||
* @param risk 交易承担的风险,如果为0,表示全部损失,即市值跌至0元
|
||||
*/
|
||||
size_t getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
double getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
SystemPart from);
|
||||
|
||||
virtual size_t _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) = 0;
|
||||
|
||||
virtual size_t _getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
virtual double _getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from);
|
||||
|
||||
virtual size_t _getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
virtual double _getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from);
|
||||
|
||||
virtual size_t _getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
virtual double _getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from);
|
||||
|
||||
/** 子类复位接口 */
|
||||
@ -221,7 +221,7 @@ public:
|
||||
virtual MoneyManagerPtr _clone() override { \
|
||||
return MoneyManagerPtr(new classname()); \
|
||||
} \
|
||||
virtual size_t _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, \
|
||||
virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, \
|
||||
price_t risk, SystemPart from) override;
|
||||
|
||||
HKU_API std::ostream& operator<<(std::ostream&, const MoneyManagerBase&);
|
||||
|
@ -21,7 +21,7 @@ namespace hku {
|
||||
* 2) 该策略并不判断已有的持仓情况,如果在已有持仓情况下不能交易,则该判断应为System本身的责任
|
||||
* @ingroup MoneyManager
|
||||
*/
|
||||
MoneyManagerPtr HKU_API MM_FixedCount(int n = 100);
|
||||
MoneyManagerPtr HKU_API MM_FixedCount(double n = 100);
|
||||
|
||||
} // namespace hku
|
||||
|
||||
|
@ -15,7 +15,7 @@ FixedCapitalMoneyManager::FixedCapitalMoneyManager() : MoneyManagerBase("MM_Fixe
|
||||
|
||||
FixedCapitalMoneyManager::~FixedCapitalMoneyManager() {}
|
||||
|
||||
size_t FixedCapitalMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedCapitalMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double capital = getParam<double>("capital");
|
||||
return capital > 0.0 ? size_t(m_tm->currentCash() / capital) : 0;
|
||||
|
@ -10,19 +10,19 @@
|
||||
namespace hku {
|
||||
|
||||
FixedCountMoneyManager::FixedCountMoneyManager() : MoneyManagerBase("MM_FixedCount") {
|
||||
setParam<int>("n", 100);
|
||||
setParam<double>("n", 100);
|
||||
}
|
||||
|
||||
FixedCountMoneyManager::~FixedCountMoneyManager() {}
|
||||
|
||||
size_t FixedCountMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedCountMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
return getParam<int>("n");
|
||||
return getParam<double>("n");
|
||||
}
|
||||
|
||||
MoneyManagerPtr HKU_API MM_FixedCount(int n) {
|
||||
MoneyManagerPtr HKU_API MM_FixedCount(double n) {
|
||||
FixedCountMoneyManager* p = new FixedCountMoneyManager();
|
||||
p->setParam<int>("n", n);
|
||||
p->setParam<double>("n", n);
|
||||
return MoneyManagerPtr(p);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ FixedPercentMoneyManager::FixedPercentMoneyManager() : MoneyManagerBase("MM_Fixe
|
||||
|
||||
FixedPercentMoneyManager::~FixedPercentMoneyManager() {}
|
||||
|
||||
size_t FixedPercentMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedPercentMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double p = getParam<double>("p");
|
||||
if (p <= 0.0 || p > 1.0) {
|
||||
@ -28,7 +28,7 @@ size_t FixedPercentMoneyManager ::_getBuyNumber(const Datetime& datetime, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
return int(m_tm->currentCash() * p / risk);
|
||||
return m_tm->currentCash() * p / risk;
|
||||
}
|
||||
|
||||
MoneyManagerPtr HKU_API MM_FixedPercent(double p) {
|
||||
|
@ -28,7 +28,7 @@ MoneyManagerPtr FixedRatioMoneyManager::_clone() {
|
||||
return MoneyManagerPtr(p);
|
||||
}
|
||||
|
||||
size_t FixedRatioMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedRatioMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double delta = getParam<double>("delta");
|
||||
if (m_pre_cash == 0.0) {
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
|
||||
virtual void _reset() override;
|
||||
virtual MoneyManagerPtr _clone() override;
|
||||
virtual size_t _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) override;
|
||||
|
||||
private:
|
||||
|
@ -15,7 +15,7 @@ FixedRiskMoneyManager::FixedRiskMoneyManager() : MoneyManagerBase("MM_FixedRisk"
|
||||
|
||||
FixedRiskMoneyManager::~FixedRiskMoneyManager() {}
|
||||
|
||||
size_t FixedRiskMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedRiskMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
return getParam<double>("risk") / risk;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ FixedUnitsMoneyManager::FixedUnitsMoneyManager() : MoneyManagerBase("MM_FixedUni
|
||||
|
||||
FixedUnitsMoneyManager::~FixedUnitsMoneyManager() {}
|
||||
|
||||
size_t FixedUnitsMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double FixedUnitsMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
int n = getParam<int>("n");
|
||||
price_t fixed_risk =
|
||||
|
@ -13,9 +13,9 @@ NotMoneyManager::NotMoneyManager() : MoneyManagerBase("MM_Nothing") {}
|
||||
|
||||
NotMoneyManager::~NotMoneyManager() {}
|
||||
|
||||
size_t NotMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
double NotMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
return size_t(m_tm->currentCash() / price);
|
||||
return m_tm->currentCash() / price;
|
||||
}
|
||||
|
||||
MoneyManagerPtr HKU_API MM_Nothing() {
|
||||
|
@ -17,7 +17,7 @@ WilliamsFixedRiskMoneyManager::WilliamsFixedRiskMoneyManager()
|
||||
|
||||
WilliamsFixedRiskMoneyManager::~WilliamsFixedRiskMoneyManager() {}
|
||||
|
||||
size_t WilliamsFixedRiskMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
double WilliamsFixedRiskMoneyManager ::_getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
price_t max_loss = getParam<price_t>("max_loss");
|
||||
if (max_loss <= 0.0) {
|
||||
|
@ -497,12 +497,12 @@ void System::_buyNow(const KRecord& today, Part from) {
|
||||
}
|
||||
|
||||
//获取可买入数量
|
||||
size_t number = _getBuyNumber(today.datetime, planPrice, planPrice - stoploss, from);
|
||||
double number = _getBuyNumber(today.datetime, planPrice, planPrice - stoploss, from);
|
||||
if (number == 0 || number > m_stock.maxTradeNumber()) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t min_num = m_stock.minTradeNumber();
|
||||
double min_num = m_stock.minTradeNumber();
|
||||
if (min_num > 1) {
|
||||
number = number / min_num * min_num;
|
||||
}
|
||||
@ -532,7 +532,7 @@ void System::_buyDelay(const KRecord& today) {
|
||||
|
||||
//计算止损价和可买入数量
|
||||
price_t stoploss = 0;
|
||||
size_t number = 0;
|
||||
double number = 0;
|
||||
price_t goalPrice = 0;
|
||||
if (getParam<bool>("delay_use_current_price")) {
|
||||
//使用当前计划价格计算止损价和可买入数量
|
||||
@ -552,7 +552,7 @@ void System::_buyDelay(const KRecord& today) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t min_num = m_stock.minTradeNumber();
|
||||
double min_num = m_stock.minTradeNumber();
|
||||
if (min_num > 1) {
|
||||
number = number / min_num * min_num;
|
||||
}
|
||||
@ -611,7 +611,7 @@ void System::_sell(const KRecord& today, Part from) {
|
||||
void System::_sellNow(const KRecord& today, Part from) {
|
||||
price_t planPrice = today.closePrice;
|
||||
|
||||
size_t number = 0;
|
||||
double number = 0;
|
||||
|
||||
//计算新的止损价
|
||||
price_t stoploss = _getStoplossPrice(today.datetime, planPrice);
|
||||
@ -659,7 +659,7 @@ void System::_sellDelay(const KRecord& today) {
|
||||
|
||||
//发出卖出请求时刻的止损价
|
||||
price_t stoploss = 0.0;
|
||||
size_t number = 0;
|
||||
double number = 0;
|
||||
price_t goalPrice = 0.0;
|
||||
|
||||
Part from = m_sellRequest.from;
|
||||
@ -753,7 +753,7 @@ void System::_buyShortNow(const KRecord& today, Part from) {
|
||||
price_t stoploss = _getShortStoplossPrice(m_buyRequest.datetime, planPrice);
|
||||
|
||||
//确定数量
|
||||
size_t number = _getBuyShortNumber(today.datetime, planPrice, stoploss - planPrice, from);
|
||||
double number = _getBuyShortNumber(today.datetime, planPrice, stoploss - planPrice, from);
|
||||
if (number == 0) {
|
||||
m_buyShortRequest.clear();
|
||||
return;
|
||||
@ -797,7 +797,7 @@ void System::_buyShortDelay(const KRecord& today) {
|
||||
price_t planPrice = today.openPrice; //取当前时刻的收盘价
|
||||
|
||||
price_t stoploss = 0.0;
|
||||
size_t number = 0;
|
||||
double number = 0;
|
||||
price_t goalPrice = 0.0;
|
||||
if (getParam<bool>("delay_use_current_price")) {
|
||||
//取当前时刻的收盘价对应的止损价
|
||||
@ -894,7 +894,7 @@ void System::_sellShortNow(const KRecord& today, Part from) {
|
||||
//计算止损价
|
||||
price_t stoploss = _getShortStoplossPrice(today.datetime, planPrice);
|
||||
|
||||
size_t number = _getSellShortNumber(today.datetime, planPrice, stoploss - planPrice, from);
|
||||
double number = _getSellShortNumber(today.datetime, planPrice, stoploss - planPrice, from);
|
||||
if (number == 0) {
|
||||
m_sellShortRequest.clear();
|
||||
return;
|
||||
@ -927,7 +927,7 @@ void System::_sellShortDelay(const KRecord& today) {
|
||||
|
||||
//发出卖出请求时刻的止损价
|
||||
price_t stoploss = 0.0;
|
||||
size_t number = 0;
|
||||
double number = 0;
|
||||
price_t goalPrice = 0.0;
|
||||
if (getParam<bool>("delay_use_current_price")) {
|
||||
stoploss = _getShortStoplossPrice(today.datetime, planPrice);
|
||||
|
@ -186,10 +186,10 @@ public:
|
||||
//通知所有需要接收实际卖出交易记录的部件
|
||||
void _sellNotifyAll(const TradeRecord&);
|
||||
|
||||
size_t _getBuyNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
size_t _getSellNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
size_t _getSellShortNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
size_t _getBuyShortNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
double _getBuyNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
double _getSellNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
double _getSellShortNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
double _getBuyShortNumber(const Datetime&, price_t price, price_t risk, Part from);
|
||||
|
||||
price_t _getStoplossPrice(const Datetime& datetime, price_t price);
|
||||
price_t _getShortStoplossPrice(const Datetime& datetime, price_t price);
|
||||
@ -365,22 +365,22 @@ inline bool System::_conditionIsValid(const Datetime& datetime) {
|
||||
return m_cn ? m_cn->isValid(datetime) : true;
|
||||
}
|
||||
|
||||
inline size_t System ::_getBuyNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
inline double System ::_getBuyNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
Part from) {
|
||||
return m_mm ? m_mm->getBuyNumber(datetime, m_stock, price, risk, from) : 0;
|
||||
}
|
||||
|
||||
inline size_t System ::_getSellNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
inline double System ::_getSellNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
Part from) {
|
||||
return m_mm ? m_mm->getSellNumber(datetime, m_stock, price, risk, from) : 0;
|
||||
}
|
||||
|
||||
inline size_t System ::_getSellShortNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
inline double System ::_getSellShortNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
Part from) {
|
||||
return m_mm ? m_mm->getSellShortNumber(datetime, m_stock, price, risk, from) : 0;
|
||||
}
|
||||
|
||||
inline size_t System ::_getBuyShortNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
inline double System ::_getBuyShortNumber(const Datetime& datetime, price_t price, price_t risk,
|
||||
Part from) {
|
||||
return m_mm ? m_mm->getBuyShortNumber(datetime, m_stock, price, risk, from) : 0;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
Datetime datetime;
|
||||
price_t stoploss;
|
||||
price_t goal;
|
||||
size_t number; //计划的买入/卖出数量,使用发出请求时刻的收盘价,
|
||||
double number; //计划的买入/卖出数量,使用发出请求时刻的收盘价,
|
||||
//用于避免实际买入时需用重新计算数量时,人工执行速度较慢
|
||||
//可通过系统参数进行设置,是否使用
|
||||
SystemPart from; //记录SystemBase::Part
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
m_x = x;
|
||||
}
|
||||
|
||||
virtual size_t _getBuyNumber(const Datetime &datetime, const Stock &stock, price_t price, price_t risk,
|
||||
SystemPart from) {
|
||||
virtual double _getBuyNumber(const Datetime &datetime, const Stock &stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -68,7 +68,8 @@ TEST_CASE("test_MoneyManager") {
|
||||
p->setTM(tm);
|
||||
CHECK_EQ(p_src->getTM(), tm);
|
||||
CHECK_EQ(p->getBuyNumber(Datetime(200001010000), stock, 10.0, 10.0, PART_SIGNAL), 0);
|
||||
CHECK_UNARY((p->getSellNumber(Datetime(200001010000), stock, 10.0, 10.0, PART_SIGNAL) == Null<size_t>()));
|
||||
CHECK_UNARY(
|
||||
(p->getSellNumber(Datetime(200001010000), stock, 10.0, 10.0, PART_SIGNAL) == MAX_DOUBLE));
|
||||
CHECK_EQ(p_src->getX(), 0);
|
||||
p_src->setX(10);
|
||||
CHECK_EQ(p_src->getX(), 10);
|
||||
|
@ -86,8 +86,7 @@ target("small-test")
|
||||
end
|
||||
|
||||
-- add files
|
||||
--add_files("./hikyuu/hikyuu/**.cpp");
|
||||
add_files(("./hikyuu/trade_manage/test_TradeManager.cpp"))
|
||||
add_files("./hikyuu/hikyuu/**.cpp");
|
||||
add_files("./hikyuu/test_main.cpp")
|
||||
|
||||
target_end()
|
@ -16,7 +16,7 @@ using namespace hku;
|
||||
class MoneyManagerWrap : public MoneyManagerBase, public wrapper<MoneyManagerBase> {
|
||||
public:
|
||||
MoneyManagerWrap() : MoneyManagerBase() {}
|
||||
MoneyManagerWrap(const string& name): MoneyManagerBase(name) {}
|
||||
MoneyManagerWrap(const string& name) : MoneyManagerBase(name) {}
|
||||
|
||||
void buyNotify(const TradeRecord& record) {
|
||||
if (override buyNotify = this->get_override("buyNotify")) {
|
||||
@ -42,47 +42,47 @@ public:
|
||||
MoneyManagerBase::sellNotify(record);
|
||||
}
|
||||
|
||||
size_t _getSellNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double _getSellNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
SystemPart from) {
|
||||
if (override _getSellNumber = this->get_override("_getSellNumber")) {
|
||||
return _getSellNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
return MoneyManagerBase::_getSellNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t default_getSellNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double default_getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
return MoneyManagerBase::_getSellNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t _getBuyNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
|
||||
SystemPart from) {
|
||||
return this->get_override("_getBuyNumber")(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t _getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double _getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
if (override _getSellShortNumber = this->get_override("_getSellShortNumber")) {
|
||||
return _getSellShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
return MoneyManagerBase::_getSellShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t default_getSellShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double default_getSellShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
return MoneyManagerBase::_getSellShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
if (override _getBuyShortNumber = this->get_override("_getBuyShortNumber")) {
|
||||
return _getBuyShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
return MoneyManagerBase::_getBuyShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
size_t default_getBuyShortNumber(const Datetime& datetime, const Stock& stock,
|
||||
price_t price, price_t risk, SystemPart from) {
|
||||
double default_getBuyShortNumber(const Datetime& datetime, const Stock& stock, price_t price,
|
||||
price_t risk, SystemPart from) {
|
||||
return MoneyManagerBase::_getBuyShortNumber(datetime, stock, price, risk, from);
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void default_reset() {
|
||||
void default_reset() {
|
||||
this->MoneyManagerBase::_reset();
|
||||
}
|
||||
|
||||
@ -103,59 +103,52 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
string (MoneyManagerBase::*mm_get_name)() const = &MoneyManagerBase::name;
|
||||
void (MoneyManagerBase::*mm_set_name)(const string&) = &MoneyManagerBase::name;
|
||||
|
||||
|
||||
void export_MoneyManager() {
|
||||
class_<MoneyManagerWrap, boost::noncopyable>("MoneyManagerBase", init<>())
|
||||
.def(init<const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", mm_get_name, mm_set_name)
|
||||
.def("getParam", &MoneyManagerBase::getParam<boost::any>)
|
||||
.def("setParam", &MoneyManagerBase::setParam<object>)
|
||||
.def("haveParam", &MoneyManagerBase::haveParam)
|
||||
.def("setTM", &MoneyManagerBase::setTM)
|
||||
.def("getTM", &MoneyManagerBase::getTM)
|
||||
.def("setQuery", &MoneyManagerBase::setQuery)
|
||||
.def("getQuery", &MoneyManagerBase::getQuery)
|
||||
.def("reset", &MoneyManagerBase::reset)
|
||||
.def("clone", &MoneyManagerBase::clone)
|
||||
.def("buyNotify", &MoneyManagerBase::buyNotify,
|
||||
&MoneyManagerWrap::default_buyNotify)
|
||||
.def("sellNotify", &MoneyManagerBase::sellNotify,
|
||||
&MoneyManagerWrap::default_sellNotify)
|
||||
.def(init<const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", mm_get_name, mm_set_name)
|
||||
.def("getParam", &MoneyManagerBase::getParam<boost::any>)
|
||||
.def("setParam", &MoneyManagerBase::setParam<object>)
|
||||
.def("haveParam", &MoneyManagerBase::haveParam)
|
||||
.def("setTM", &MoneyManagerBase::setTM)
|
||||
.def("getTM", &MoneyManagerBase::getTM)
|
||||
.def("setQuery", &MoneyManagerBase::setQuery)
|
||||
.def("getQuery", &MoneyManagerBase::getQuery)
|
||||
.def("reset", &MoneyManagerBase::reset)
|
||||
.def("clone", &MoneyManagerBase::clone)
|
||||
.def("buyNotify", &MoneyManagerBase::buyNotify, &MoneyManagerWrap::default_buyNotify)
|
||||
.def("sellNotify", &MoneyManagerBase::sellNotify, &MoneyManagerWrap::default_sellNotify)
|
||||
|
||||
.def("getBuyNumber", &MoneyManagerBase::getBuyNumber)
|
||||
.def("getSellNumber", &MoneyManagerBase::getSellNumber)
|
||||
.def("getSellShortNumber", &MoneyManagerBase::getSellShortNumber)
|
||||
.def("getBuyShortNumber", &MoneyManagerBase::getBuyShortNumber)
|
||||
.def("getBuyNumber", &MoneyManagerBase::getBuyNumber)
|
||||
.def("getSellNumber", &MoneyManagerBase::getSellNumber)
|
||||
.def("getSellShortNumber", &MoneyManagerBase::getSellShortNumber)
|
||||
.def("getBuyShortNumber", &MoneyManagerBase::getBuyShortNumber)
|
||||
|
||||
.def("_getBuyNumber", pure_virtual(&MoneyManagerBase::_getBuyNumber))
|
||||
.def("_getSellNumber", &MoneyManagerBase::_getSellNumber,
|
||||
&MoneyManagerWrap::default_getSellNumber)
|
||||
.def("_getSellShortNumber", &MoneyManagerBase::_getSellShortNumber,
|
||||
&MoneyManagerWrap::default_getSellShortNumber)
|
||||
.def("_getBuyShortNumber", &MoneyManagerBase::_getBuyShortNumber,
|
||||
&MoneyManagerWrap::default_getBuyShortNumber)
|
||||
.def("_reset", &MoneyManagerBase::_reset, &MoneyManagerWrap::default_reset)
|
||||
.def("_clone", pure_virtual(&MoneyManagerBase::_clone))
|
||||
.def("_getBuyNumber", pure_virtual(&MoneyManagerBase::_getBuyNumber))
|
||||
.def("_getSellNumber", &MoneyManagerBase::_getSellNumber,
|
||||
&MoneyManagerWrap::default_getSellNumber)
|
||||
.def("_getSellShortNumber", &MoneyManagerBase::_getSellShortNumber,
|
||||
&MoneyManagerWrap::default_getSellShortNumber)
|
||||
.def("_getBuyShortNumber", &MoneyManagerBase::_getBuyShortNumber,
|
||||
&MoneyManagerWrap::default_getBuyShortNumber)
|
||||
.def("_reset", &MoneyManagerBase::_reset, &MoneyManagerWrap::default_reset)
|
||||
.def("_clone", pure_virtual(&MoneyManagerBase::_clone))
|
||||
#if HKU_PYTHON_SUPPORT_PICKLE
|
||||
.def_pickle(name_init_pickle_suite<MoneyManagerBase>())
|
||||
.def_pickle(name_init_pickle_suite<MoneyManagerBase>())
|
||||
#endif
|
||||
;
|
||||
;
|
||||
|
||||
register_ptr_to_python<MoneyManagerPtr>();
|
||||
|
||||
def("MM_Nothing", MM_Nothing);
|
||||
def("MM_FixedRisk", MM_FixedRisk, (arg("risk")=1000.00));
|
||||
def("MM_FixedRisk", MM_FixedRisk, (arg("risk") = 1000.00));
|
||||
def("MM_FixedCapital", MM_FixedCapital, (arg("capital") = 10000.00));
|
||||
def("MM_FixedCount", MM_FixedCount, (arg("n")=100));
|
||||
def("MM_FixedPercent", MM_FixedPercent, (arg("p")=0.03));
|
||||
def("MM_FixedCount", MM_FixedCount, (arg("n") = 100));
|
||||
def("MM_FixedPercent", MM_FixedPercent, (arg("p") = 0.03));
|
||||
def("MM_FixedUnits", MM_FixedUnits, (arg("n") = 33));
|
||||
def("MM_WilliamsFixedRisk", MM_WilliamsFixedRisk, (arg("p") = 0.1, arg("max_loss")=1000.0));
|
||||
def("MM_WilliamsFixedRisk", MM_WilliamsFixedRisk, (arg("p") = 0.1, arg("max_loss") = 1000.0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user