更新注释与帮助

This commit is contained in:
fasiondog 2022-02-25 08:33:57 +08:00
parent a1cd5983a2
commit e949061bc1
11 changed files with 121 additions and 66 deletions

View File

@ -104,7 +104,6 @@ pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
@ -208,25 +207,24 @@ htmlhelp_basename = 'Hikyuudoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Latex figure (float) alignment
#'figure_align': 'htbp',
# Latex figure (float) alignment
#'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Hikyuu.tex', 'Hikyuu Documentation',
'fasiondog', 'manual'),
(master_doc, 'Hikyuu.tex', 'Hikyuu Documentation', 'fasiondog', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@ -249,29 +247,23 @@ latex_documents = [
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'hikyuu', 'Hikyuu Documentation',
[author], 1)
]
man_pages = [(master_doc, 'hikyuu', 'Hikyuu Documentation', [author], 1)]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Hikyuu', 'Hikyuu Documentation',
author, 'Hikyuu', 'One line description of project.',
'Miscellaneous'),
(master_doc, 'Hikyuu', 'Hikyuu Documentation', author, 'Hikyuu',
'One line description of project.', 'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.

View File

@ -5,7 +5,19 @@
================
内建资产分配算法
-----------------
------------------
.. py:function:: AF_FixedWeight(weight)
固定比例资产分配,每个选中的资产都只占总资产固定的比例
:param float weight: 指定的资产比例 [0, 1]
.. py:function:: AF_EqualWeight()
固定比例资产分配,对选中的资产进行等比例分配
系统权重系数结构
-----------------
@ -22,11 +34,25 @@
由系统权重系数结构组成的列表
.. py:attribute:: sys
对应的 System 实例
.. py::attribute weight
对应的权重系数,有效范围为 [0, 1]
资产分配算法基类
------------------
.. py:class:: AllocateFundsBase
资产分配算法基类
资产分配算法基类, 子类接口:
- _allocateWeight : 【必须】子类资产分配调整实现
- _clone : 【必须】克隆接口
- _reset : 【可选】重载私有变量

View File

@ -8,4 +8,4 @@
portfolio
selector
allcate_funds
allocate_funds

View File

@ -59,21 +59,23 @@ public:
const std::list<SYSPtr>& running_list, const SystemList& ignore_list);
/** 获取交易账户 */
TMPtr getTM();
const TMPtr& getTM() const;
/** 设定交易账户 */
/** 设定交易账户,由 PF 设定 */
void setTM(const TMPtr&);
/** 设置 Portfolio 的影子账户, 仅由 Portfolio 调用 */
void setShadowTM(const TMPtr&);
/** 获取关联查询条件 */
KQuery getQuery();
const TMPtr& getShadowTM(const TMPtr&) const;
/** 设置查询条件 */
/** 获取关联查询条件 */
const KQuery& getQuery() const;
/** 设置查询条件, 由 PF 设定 */
void setQuery(const KQuery& query);
/** 获取不参与资产分配的保留比例 */
/** 获取当前不参与资产分配的保留比例 */
double getReservePercent();
/**
@ -207,7 +209,7 @@ inline void AllocateFundsBase::name(const string& name) {
m_name = name;
}
inline TMPtr AllocateFundsBase::getTM() {
inline const TMPtr& AllocateFundsBase::getTM() const {
return m_tm;
}
@ -219,7 +221,11 @@ inline void AllocateFundsBase::setShadowTM(const TMPtr& tm) {
m_shadow_tm = tm;
}
inline KQuery AllocateFundsBase::getQuery() {
inline const TMPtr& AllocateFundsBase::getShadowTM(const TMPtr&) const {
return m_shadow_tm;
}
inline const KQuery& AllocateFundsBase::getQuery() const {
return m_query;
}

View File

@ -13,6 +13,11 @@
namespace hku {
/**
* @brief
* @return AFPtr
* @ingroup AllocateFunds
*/
AFPtr HKU_API AF_EqualWeight();
} /* namespace hku */

View File

@ -13,6 +13,12 @@
namespace hku {
/**
* @brief
* @param weight [0, 1]
* @return AFPtr
* @ingroup AllocateFunds
*/
AFPtr HKU_API AF_FixedWeight(double weight = 0.1);
} /* namespace hku */

View File

@ -27,7 +27,7 @@ SystemWeightList FixedWeightAllocateFunds ::_allocateWeight(const Datetime& date
}
AFPtr HKU_API AF_FixedWeight(double weight) {
HKU_CHECK_THROW(weight > 0 && weight <= 1, std::out_of_range,
HKU_CHECK_THROW(weight > 0.0 && weight <= 1.0, std::out_of_range,
"input weigth ({}) is out of range [0, 1]!", weight);
auto p = make_shared<FixedWeightAllocateFunds>();
p->setParam<double>("weight", weight);

View File

@ -25,13 +25,12 @@ HKU_API std::ostream& operator<<(std::ostream& os, const SelectorPtr& st) {
return os;
}
SelectorBase::SelectorBase() : m_name("SelectorBase"), m_count(0), m_pre_date(Datetime::min()) {
SelectorBase::SelectorBase() : m_name("SelectorBase") {
// 是否单独执行原型系统
setParam<bool>("run_proto_sys", false);
}
SelectorBase::SelectorBase(const string& name)
: m_name(name), m_count(0), m_pre_date(Datetime::min()) {
SelectorBase::SelectorBase(const string& name) : m_name(name) {
// 是否单独执行原型系统
setParam<bool>("run_proto_sys", false);
}
@ -39,8 +38,6 @@ SelectorBase::SelectorBase(const string& name)
SelectorBase::~SelectorBase() {}
void SelectorBase::clear() {
m_count = 0;
m_pre_date = Datetime::min();
m_pro_sys_list.clear();
m_real_sys_list.clear();
}
@ -52,8 +49,6 @@ void SelectorBase::reset() {
(*iter)->reset(true, false);
}
m_count = 0;
m_pre_date = Datetime::min();
m_real_sys_list.clear();
_reset();
}
@ -74,8 +69,6 @@ SelectorPtr SelectorBase::clone() {
p->m_params = m_params;
p->m_name = m_name;
p->m_count = m_count;
p->m_pre_date = m_pre_date;
p->m_real_sys_list = m_real_sys_list;
p->m_pro_sys_list = m_pro_sys_list;
return p;

View File

@ -104,8 +104,6 @@ private:
protected:
string m_name;
int m_count;
Datetime m_pre_date;
SystemList m_pro_sys_list; // 原型系统列表
SystemList m_real_sys_list; // PF组合中实际运行的系统有PF执行时设定顺序与原型列表一一对应
@ -119,8 +117,6 @@ private:
void save(Archive& ar, const unsigned int version) const {
ar& BOOST_SERIALIZATION_NVP(m_name);
ar& BOOST_SERIALIZATION_NVP(m_params);
ar& BOOST_SERIALIZATION_NVP(m_count);
ar& BOOST_SERIALIZATION_NVP(m_pre_date);
ar& BOOST_SERIALIZATION_NVP(m_pro_sys_list);
}
@ -128,8 +124,6 @@ private:
void load(Archive& ar, const unsigned int version) {
ar& BOOST_SERIALIZATION_NVP(m_name);
ar& BOOST_SERIALIZATION_NVP(m_params);
ar& BOOST_SERIALIZATION_NVP(m_count);
ar& BOOST_SERIALIZATION_NVP(m_pre_date);
ar& BOOST_SERIALIZATION_NVP(m_pro_sys_list);
}

View File

@ -13,8 +13,21 @@
namespace hku {
/**
* @brief
* @return SelectorPtr
* @ingroup Selector
*/
SelectorPtr HKU_API SE_Fixed();
/**
* @brief
* @details
* @param stock_list
* @param sys
* @return SelectorPtr
* @ingroup Selector
*/
SelectorPtr HKU_API SE_Fixed(const StockList& stock_list, const SystemPtr& sys);
} /* namespace hku */

View File

@ -65,30 +65,47 @@ void export_AllocateFunds() {
class_<SystemWeightList>("SystemWeightList").def(vector_indexing_suite<SystemWeightList>());
// SystemWeightList::const_reference (SystemWeightList::*SystemWeightList_at)(
// SystemWeightList::size_type) const = &SystemWeightList::at;
// void (SystemWeightList::*append)(const SystemWeight&) = &SystemWeightList::push_back;
// class_<SystemWeightList>("SystemWeightList")
// .def("__iter__", iterator<SystemWeightList>())
// .def("size", &SystemWeightList::size)
// .def("__len__", &SystemWeightList::size)
// .def("get", SystemWeightList_at, return_value_policy<copy_const_reference>())
// .def("append", append);
class_<AllocateFundsBaseWrap, boost::noncopyable>("AllocateFundsBase",
R"(资产分配算法基类, 子类接口:
- _allocateWeight :
- _clone :
- _reset : )",
init<>())
class_<AllocateFundsBaseWrap, boost::noncopyable>("AllocateFundsBase", init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", make_function(af_get_name, return_value_policy<copy_const_reference>()),
af_set_name, "算法组件名称")
.def("get_param", &AllocateFundsBase::getParam<boost::any>)
.def("set_param", &AllocateFundsBase::setParam<object>)
.def("have_param", &AllocateFundsBase::haveParam)
.add_property(
"query",
make_function(&AllocateFundsBase::getQuery, return_value_policy<copy_const_reference>()),
&AllocateFundsBase::setQuery, "设置或获取查询条件")
.def("reset", &AllocateFundsBase::reset)
.def("clone", &AllocateFundsBase::clone)
.def("_reset", &AllocateFundsBase::_reset, &AllocateFundsBaseWrap::default_reset)
.def("_clone", pure_virtual(&AllocateFundsBase::_clone))
.def("get_param", &AllocateFundsBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &AllocateFundsBase::setParam<object>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &AllocateFundsBase::haveParam, "是否存在指定参数")
.def("reset", &AllocateFundsBase::reset, "复位操作")
.def("clone", &AllocateFundsBase::clone, "克隆操作")
.def("_reset", &AllocateFundsBase::_reset, &AllocateFundsBaseWrap::default_reset,
"子类复位操作实现")
.def("_clone", pure_virtual(&AllocateFundsBase::_clone), "子类克隆操作实现接口")
.def("_allocate_weight", pure_virtual(&AllocateFundsBase::_allocateWeight))
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<AllocateFundsBase>())
@ -97,6 +114,9 @@ void export_AllocateFunds() {
register_ptr_to_python<AFPtr>();
def("AF_EqualWeight", AF_EqualWeight);
def("AF_FixedWeight", AF_FixedWeight);
def("AF_EqualWeight", AF_EqualWeight, R"(等权重资产分配,对选中的资产进行等比例分配)");
def("AF_FixedWeight", AF_FixedWeight, R"(固定比例资产分配
:param float weight: [0, 1])");
}