补充注释帮助

This commit is contained in:
fasiondog 2020-08-10 00:27:23 +08:00
parent 7145dfdb66
commit 202dc2a7c0
3 changed files with 35 additions and 15 deletions

View File

@ -89,7 +89,7 @@
* @details
* @ingroup Portfolio
*
* @defgroup AllocateMoney AllocateMoney
* @defgroup AllocateFunds Allocate Funds
* @details
* @ingroup Portfolio
*

View File

@ -262,7 +262,7 @@ void AllocateFundsBase::_adjust_without_running(const Datetime& date, const Syst
return;
}
//如果持仓的系统数已大于等于最大持仓系统数,直接输出已持仓系统列表,并返回
//如果运行中的系统数已大于等于允许的最大系统数,直接返回
int max_num = getParam<int>("max_sys_num");
if (running_list.size() >= max_num) {
return;
@ -281,7 +281,7 @@ void AllocateFundsBase::_adjust_without_running(const Datetime& date, const Syst
}
}
//获取权重
//获取计划分配的资金权重
SystemWeightList sw_list = _allocateWeight(date, pure_se_list);
if (sw_list.size() == 0) {
return;
@ -292,26 +292,26 @@ void AllocateFundsBase::_adjust_without_running(const Datetime& date, const Syst
boost::bind(std::less<double>(), boost::bind(&SystemWeight::m_weight, _1),
boost::bind(&SystemWeight::m_weight, _2)));
//倒序遍历计算总权重并在遇到权重为0或等于最大持仓时结束遍历
size_t remain = max_num - running_list.size();
//倒序遍历计算总权重并在遇到权重为0或等于运行的最大运行时系统数时结束遍历
price_t total_weight = 0.0;
size_t count = 0;
auto sw_iter = sw_list.rbegin();
for (size_t count = 0; sw_iter != sw_list.rend(); ++sw_iter, count++) {
if (sw_iter->getWeight() <= 0.0 || count >= remain)
for (; sw_iter != sw_list.rend(); ++sw_iter) {
if (sw_iter->getWeight() <= 0.0 || count >= max_num)
break;
total_weight += sw_iter->getWeight();
count++;
}
if (total_weight <= 0.0) {
return;
}
auto end_iter = sw_iter;
auto end_iter = sw_iter; // 记录结束位置
int precision = m_tm->getParam<int>("precision");
price_t per_cash = 0.0;
per_cash = m_tm->currentCash() / total_weight; // 每单位权重资金
// 再次遍历选中子系统列表,并将剩余现金按权重比例转入子账户
int precision = m_tm->getParam<int>("precision"); // 总账号资金精度
price_t per_cash = m_tm->currentCash() / total_weight; // 每单位权重资金
sw_iter = sw_list.rbegin();
for (; sw_iter != end_iter; ++sw_iter) {
// 该系统期望分配的资金
@ -321,8 +321,7 @@ void AllocateFundsBase::_adjust_without_running(const Datetime& date, const Syst
}
// 尝试从总账户中取出资金存入子账户
SYSPtr sub_sys = sw_iter->getSYS();
TMPtr sub_tm = sub_sys->getTM();
TMPtr sub_tm = sw_iter->getSYS()->getTM();
if (m_tm->checkout(date, will_cash)) {
sub_tm->checkin(date, will_cash);
}

View File

@ -20,15 +20,30 @@
namespace hku {
/**
*
* @ingroup AllocateFunds
*/
class HKU_API AllocateFundsBase : public enable_shared_from_this<AllocateFundsBase> {
PARAMETER_SUPPORT
public:
/** 默认构造函数 */
AllocateFundsBase();
/**
*
* @param name
*/
AllocateFundsBase(const string& name);
/** 析构函数 */
virtual ~AllocateFundsBase();
/** 获取算法名称 */
string name() const;
/** 修改算法名称 */
void name(const string& name);
/**
@ -47,7 +62,10 @@ public:
/** 设定交易账户 */
void setTM(const TMPtr&);
/** 获取关联查询条件 */
KQuery getQuery();
/** 设置查询条件 */
void setQuery(KQuery query);
/** 获取不参与资产分配的保留比例 */
@ -80,11 +98,14 @@ public:
* @param se_list
* @return
*/
virtual SystemWeightList _allocateWeight(const Datetime& date, const SystemList& se_list) = 0;
private:
/* 同时调整已运行中的子系统(已分配资金或已持仓) */
void _adjust_with_running(const Datetime& date, const SystemList& se_list,
const std::list<SYSPtr>& running_list);
/* 仅适用剩余资金在选中的子系统中分配资金 */
void _adjust_without_running(const Datetime& date, const SystemList& se_list,
const std::list<SYSPtr>& running_list);