mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
完善帮助信息
This commit is contained in:
parent
509c785451
commit
cb60a10bad
@ -49,7 +49,10 @@ public:
|
||||
typedef SystemPart Part;
|
||||
|
||||
/** 获取名称 */
|
||||
const string& name() const;
|
||||
string name() const;
|
||||
|
||||
/** 设置名称 */
|
||||
void name(const string& name);
|
||||
|
||||
KData getTO() const { return m_kdata; }
|
||||
TradeManagerPtr getTM() const { return m_tm; }
|
||||
@ -266,10 +269,14 @@ HKU_API std::ostream& operator <<(std::ostream &os, const System& sys);
|
||||
HKU_API std::ostream& operator <<(std::ostream &os, const SystemPtr& sys);
|
||||
|
||||
|
||||
inline const string& System::name() const {
|
||||
inline string System::name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
inline void System::name(const string& name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
inline bool System::
|
||||
_environmentIsValid(const Datetime& datetime) {
|
||||
return m_ev ? m_ev->isValid(datetime) : true;
|
||||
|
@ -14,6 +14,7 @@ namespace hku {
|
||||
|
||||
/**
|
||||
* 系统关联部件(各自策略)枚举定义,用于修改相关部件参数
|
||||
* @ingroup System
|
||||
*/
|
||||
enum SystemPart {
|
||||
PART_ENVIRONMENT = 0, /**< 外部环境 */
|
||||
@ -27,8 +28,20 @@ enum SystemPart {
|
||||
PART_INVALID = 8, /**< 无效值 */
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取SystemPart枚举值的字符串名称
|
||||
* @param part 系统部件枚举值
|
||||
* @return
|
||||
* @ingroup System
|
||||
*/
|
||||
string HKU_API getSystemPartName(int part);
|
||||
|
||||
/**
|
||||
* 通过字符串名称获取SystemPart枚举值
|
||||
* @param name 字符串名称
|
||||
* @return
|
||||
* @ingroup System
|
||||
*/
|
||||
SystemPart HKU_API getSystemPartEnum(const string& name);
|
||||
|
||||
} /* namespace */
|
||||
|
@ -12,6 +12,10 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
/**
|
||||
* 交易请求记录
|
||||
* @ingroup System
|
||||
*/
|
||||
class HKU_API TradeRequest {
|
||||
public:
|
||||
TradeRequest();
|
||||
|
@ -20,9 +20,22 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(run_overload, run, 2, 3);
|
||||
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(SYS_Simple_overload, SYS_Simple, 0, 9);
|
||||
|
||||
string (System::*sys_get_name)() const = &System::name;
|
||||
void (System::*sys_set_name)(const string&) = &System::name;
|
||||
|
||||
|
||||
void export_System() {
|
||||
|
||||
def("SYS_Simple", SYS_Simple, SYS_Simple_overload());
|
||||
/*def("SYS_Simple", SYS_Simple, (arg("tm")=TradeManagerPtr(),
|
||||
arg("mm")=MoneyManagerPtr(),
|
||||
arg("ev")=EnvironmentPtr(),
|
||||
arg("cn")=ConditionPtr(),
|
||||
arg("sg")=SignalPtr(),
|
||||
arg("sl")=StoplossPtr(),
|
||||
arg("tp")=StoplossPtr(),
|
||||
arg("pg")=ProfitGoalPtr(),
|
||||
arg("sp")=SlippagePtr()));*/
|
||||
|
||||
def("getSystemPartName", getSystemPartName);
|
||||
def("getSystemPartEnum", getSystemPartEnum);
|
||||
@ -53,12 +66,7 @@ void export_System() {
|
||||
const SlippagePtr&,
|
||||
const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name",
|
||||
make_function(&System::name,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.add_property("params",
|
||||
make_function(&System::getParameter,
|
||||
return_internal_reference<>()))
|
||||
.add_property("name", sys_get_name, sys_set_name)
|
||||
.add_property("tm", &System::getTM, &System::setTM)
|
||||
.add_property("mm", &System::getMM, &System::setMM)
|
||||
.add_property("ev", &System::getEV, &System::setEV)
|
||||
@ -69,6 +77,9 @@ void export_System() {
|
||||
.add_property("pg", &System::getPG, &System::setPG)
|
||||
.add_property("sp", &System::getSP, &System::setSP)
|
||||
|
||||
.def("getParam", &System::getParam<boost::any>)
|
||||
.def("setParam", &System::setParam<object>)
|
||||
|
||||
.def("getStock", &System::getStock)
|
||||
.def("getTradeRecordList", &System::getTradeRecordList,
|
||||
return_value_policy<copy_const_reference>())
|
||||
@ -111,7 +122,7 @@ void export_System() {
|
||||
#endif
|
||||
;
|
||||
|
||||
enum_<SystemPart>("SystemPart")
|
||||
enum_<SystemPart>("Part")
|
||||
.value("ENVIRONMENT", PART_ENVIRONMENT)
|
||||
.value("CONDITION", PART_CONDITION)
|
||||
.value("SIGNAL", PART_SIGNAL)
|
||||
|
@ -25,28 +25,13 @@
|
||||
# SOFTWARE.
|
||||
|
||||
|
||||
from . import _trade_sys as csys
|
||||
from ._trade_sys import ProfitGoalBase, PG_NoGoal, PG_FixedPercent
|
||||
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
|
||||
|
||||
ProfitGoalBase = csys.ProfitGoalBase
|
||||
|
||||
ProfitGoalBase.__unicode__ = unicodeFunc
|
||||
ProfitGoalBase.__repr__ = reprFunc
|
||||
|
||||
PG_NoGoal = csys.PG_NoGoal
|
||||
PG_FixedPercent = csys.PG_FixedPercent
|
||||
|
||||
PG_NoGoal.__doc__ = """\n
|
||||
无盈利目标策略,通常为了进行测试或对比。
|
||||
|
||||
:return: 盈利目标策略实例
|
||||
"""
|
||||
|
||||
PG_FixedPercent.__doc__ = """\n
|
||||
固定百分比盈利目标,目标价格 = 买入价格 * (1 + p)
|
||||
|
||||
:param float p: 百分比
|
||||
:return: 盈利目标策略实例
|
||||
"""
|
||||
|
||||
def pg_init(self, name, params):
|
||||
super(self.__class__, self).__init__(name)
|
||||
@ -67,4 +52,142 @@ def crtPG(func, params={}, name='crtPG'):
|
||||
meta_x = type(name, (ProfitGoalBase,), {'__init__': pg_init})
|
||||
meta_x._clone = lambda self: meta_x(self._name, self._params)
|
||||
meta_x._calculate = func
|
||||
return meta_x(name, params)
|
||||
return meta_x(name, params)
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string
|
||||
#------------------------------------------------------------------
|
||||
|
||||
ProfitGoalBase.__doc__ = """
|
||||
盈利目标策略基类
|
||||
|
||||
自定义盈利目标策略接口:
|
||||
|
||||
ProfitGoalBase.getGoal() - 【必须】获取目标价格
|
||||
ProfitGoalBase._calculate() - 【必须】子类计算接口
|
||||
ProfitGoalBase._clone() - 【必须】克隆接口
|
||||
ProfitGoalBase._reset() - 【可选】重载私有变量
|
||||
"""
|
||||
|
||||
ProfitGoalBase.name.__doc__ = """名称"""
|
||||
|
||||
ProfitGoalBase.__init__.__doc__ = """
|
||||
__init__(self[, name="ProfitGoalBase"])
|
||||
|
||||
初始化构造函数
|
||||
|
||||
:param str name: 名称
|
||||
"""
|
||||
|
||||
ProfitGoalBase.getParam.__doc__ = """
|
||||
getParam(self, name)
|
||||
|
||||
获取指定的参数
|
||||
|
||||
:param str name: 参数名称
|
||||
:return: 参数值
|
||||
:raises out_of_range: 无此参数
|
||||
"""
|
||||
|
||||
ProfitGoalBase.setParam.__doc__ = """
|
||||
setParam(self, name, value)
|
||||
|
||||
设置参数
|
||||
|
||||
:param str name: 参数名称
|
||||
:param value: 参数值
|
||||
:type value: int | bool | float | string
|
||||
:raises logic_error: Unsupported type! 不支持的参数类型
|
||||
"""
|
||||
|
||||
ProfitGoalBase.setTO.__doc__ = """
|
||||
setTO(self, k)
|
||||
|
||||
:param KData k: 设置交易对象
|
||||
"""
|
||||
|
||||
ProfitGoalBase.getTO.__doc__ = """
|
||||
getTO(self)
|
||||
|
||||
:return: 交易对象
|
||||
:rtype: KData
|
||||
"""
|
||||
|
||||
ProfitGoalBase.setTM.__doc__ = """
|
||||
setTM(self, tm)
|
||||
|
||||
:param TradeManager tm: 设置交易管理账户
|
||||
"""
|
||||
|
||||
ProfitGoalBase.getTM.__doc__ = """
|
||||
getTM(self)
|
||||
|
||||
获取交易管理账户
|
||||
|
||||
:rtype: TradeManager
|
||||
"""
|
||||
|
||||
ProfitGoalBase.getGoal.__doc__ = """
|
||||
getGoal(self, datetime, price)
|
||||
|
||||
【重载接口】获取盈利目标价格
|
||||
|
||||
:param Datetime datetime: 买入时间
|
||||
:param float price: 买入价格
|
||||
:return: 目标价格
|
||||
:rtype: float
|
||||
"""
|
||||
|
||||
ProfitGoalBase.reset.__doc__ = """
|
||||
reset(self)
|
||||
|
||||
复位操作
|
||||
"""
|
||||
|
||||
ProfitGoalBase.clone.__doc__ = """
|
||||
clone(self)
|
||||
|
||||
克隆操作
|
||||
"""
|
||||
|
||||
ProfitGoalBase._calculate.__doc__ = """
|
||||
_calculate(self)
|
||||
|
||||
【重载接口】子类计算接口
|
||||
"""
|
||||
|
||||
ProfitGoalBase._reset.__doc__ = """
|
||||
_reset(self)
|
||||
|
||||
【重载接口】子类复位接口,复位内部私有变量
|
||||
"""
|
||||
|
||||
ProfitGoalBase._clone.__doc__ = """
|
||||
_clone(self)
|
||||
|
||||
【重载接口】子类克隆接口
|
||||
"""
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string for build_in func
|
||||
#------------------------------------------------------------------
|
||||
|
||||
PG_NoGoal.__doc__ = """
|
||||
PG_NoGoal()
|
||||
|
||||
无盈利目标策略,通常为了进行测试或对比。
|
||||
|
||||
:return: 盈利目标策略实例
|
||||
"""
|
||||
|
||||
PG_FixedPercent.__doc__ = """
|
||||
PG_FixedPercent([p = 0.2])
|
||||
|
||||
固定百分比盈利目标,目标价格 = 买入价格 * (1 + p)
|
||||
|
||||
:param float p: 百分比
|
||||
:return: 盈利目标策略实例
|
||||
"""
|
||||
|
||||
|
@ -25,15 +25,13 @@
|
||||
# SOFTWARE.
|
||||
|
||||
|
||||
from . import _trade_sys as csys
|
||||
from ._trade_sys import (SlippageBase, SL_FixedPercent, SL_FixedValue)
|
||||
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
|
||||
|
||||
SlippageBase = csys.SlippageBase
|
||||
|
||||
SlippageBase.__unicode__ = unicodeFunc
|
||||
SlippageBase.__repr__ = reprFunc
|
||||
|
||||
SL_FixedPercent = csys.SL_FixedPercent
|
||||
SL_FixedValue = csys.SL_FixedValue
|
||||
|
||||
def sl_init(self, name, params):
|
||||
super(self.__class__, self).__init__(name)
|
||||
@ -57,14 +55,135 @@ def crtSL(func, params={}, name='crtSL'):
|
||||
return meta_x(name, params)
|
||||
|
||||
|
||||
SL_FixedPercent.__doc__ = """\n
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string
|
||||
#------------------------------------------------------------------
|
||||
|
||||
SlippageBase.__doc__ = """
|
||||
移滑价差算法基类
|
||||
|
||||
自定义移滑价差接口:
|
||||
|
||||
SlippageBase.getRealBuyPrice() - 【必须】计算实际买入价格
|
||||
SlippageBase.getRealSellPrice() - 【必须】计算实际卖出价格
|
||||
SlippageBase._calculate() - 【必须】子类计算接口
|
||||
SlippageBase._clone() - 【必须】克隆接口
|
||||
SlippageBase._reset() - 【可选】重载私有变量
|
||||
"""
|
||||
|
||||
SlippageBase.name.__doc__ = """名称"""
|
||||
|
||||
SlippageBase.__init__.__doc__ = """
|
||||
__init__(self[, name="SlippageBase"])
|
||||
|
||||
初始化构造函数
|
||||
|
||||
:param str name: 名称
|
||||
"""
|
||||
|
||||
SlippageBase.getParam.__doc__ = """
|
||||
getParam(self, name)
|
||||
|
||||
获取指定的参数
|
||||
|
||||
:param str name: 参数名称
|
||||
:return: 参数值
|
||||
:raises out_of_range: 无此参数
|
||||
"""
|
||||
|
||||
SlippageBase.setParam.__doc__ = """
|
||||
setParam(self, name, value)
|
||||
|
||||
设置参数
|
||||
|
||||
:param str name: 参数名称
|
||||
:param value: 参数值
|
||||
:type value: int | bool | float | string
|
||||
:raises logic_error: Unsupported type! 不支持的参数类型
|
||||
"""
|
||||
|
||||
SlippageBase.setTO.__doc__ = """
|
||||
setTO(self, k)
|
||||
|
||||
:param KData k: 设置交易对象
|
||||
"""
|
||||
|
||||
SlippageBase.getTO.__doc__ = """
|
||||
getTO(self)
|
||||
|
||||
:return: 交易对象
|
||||
:rtype: KData
|
||||
"""
|
||||
|
||||
SlippageBase.getRealBuyPrice.__doc__ = """
|
||||
getRealBuyPrice(self, datetime, price)
|
||||
|
||||
【重载接口】计算实际买入价格
|
||||
|
||||
:param Datetime datetime: 买入时间
|
||||
:param float price: 计划买入价格
|
||||
:return: 实际买入价格
|
||||
:rtype: float
|
||||
"""
|
||||
|
||||
SlippageBase.getRealSellPrice.__doc__ = """
|
||||
getRealSellPrice(self, datetime, price)
|
||||
|
||||
【重载接口】计算实际卖出价格
|
||||
|
||||
:param Datetime datetime: 卖出时间
|
||||
:param float price: 计划卖出价格
|
||||
:return: 实际卖出价格
|
||||
:rtype: float
|
||||
"""
|
||||
|
||||
SlippageBase.reset.__doc__ = """
|
||||
reset(self)
|
||||
|
||||
复位操作
|
||||
"""
|
||||
|
||||
SlippageBase.clone.__doc__ = """
|
||||
clone(self)
|
||||
|
||||
克隆操作
|
||||
"""
|
||||
|
||||
SlippageBase._calculate.__doc__ = """
|
||||
_calculate(self)
|
||||
|
||||
【重载接口】子类计算接口
|
||||
"""
|
||||
|
||||
SlippageBase._reset.__doc__ = """
|
||||
_reset(self)
|
||||
|
||||
【重载接口】子类复位接口,复位内部私有变量
|
||||
"""
|
||||
|
||||
SlippageBase._clone.__doc__ = """
|
||||
_clone(self)
|
||||
|
||||
【重载接口】子类克隆接口
|
||||
"""
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string for build_in func
|
||||
#------------------------------------------------------------------
|
||||
|
||||
SL_FixedPercent.__doc__ = """
|
||||
SP_FixedPercent([p=0.001])
|
||||
|
||||
固定百分比移滑价差算法,买入实际价格 = 计划买入价格 * (1 + p),卖出实际价格 = 计划卖出价格 * (1 - p)
|
||||
|
||||
:param float p: 偏移的固定百分比
|
||||
:return: 移滑价差算法实例
|
||||
"""
|
||||
|
||||
SL_FixedValue.__doc__ = """\n
|
||||
SL_FixedValue.__doc__ = """
|
||||
SP_FixedValuet([p=0.001])
|
||||
|
||||
固定价格移滑价差算法,买入实际价格 = 计划买入价格 + 偏移价格,卖出实际价格 = 计划卖出价格 - 偏移价格
|
||||
|
||||
:param float p: 偏移价格
|
||||
|
@ -117,6 +117,66 @@ getTM(self)
|
||||
:rtype: TradeManager
|
||||
"""
|
||||
|
||||
StoplossBase.setTO.__doc__ = """
|
||||
setTO(self, k)
|
||||
|
||||
:param KData k: 设置交易对象
|
||||
"""
|
||||
|
||||
StoplossBase.getTO.__doc__ = """
|
||||
getTO(self)
|
||||
|
||||
:return: 交易对象
|
||||
:rtype: KData
|
||||
"""
|
||||
|
||||
StoplossBase.getPrice.__doc__ = """
|
||||
getPrice(self, datetime, price)
|
||||
|
||||
【重载接口】获取本次预期交易(买入)时的计划止损价格,如果不存在止损价,则返回0。
|
||||
用于系统在交易执行前向止损策略模块查询本次交易的计划止损价。
|
||||
|
||||
.. note::
|
||||
一般情况下,止损/止赢的算法可以互换,但止损的getPrice可以传入计划交易的
|
||||
价格,比如以买入价格的30%做为止损。而止赢则不考虑传入的price参数,即认为
|
||||
price 为 0.0。实际上,即使止损也不建议使用price参数,如可以使用前日最低
|
||||
价的 30% 作为止损,则不需要考虑price参数。
|
||||
|
||||
:param Datetime datetime: 交易时间
|
||||
:param float price: 计划买入的价格
|
||||
:return: 止损价格
|
||||
:rtype: float
|
||||
"""
|
||||
|
||||
StoplossBase.reset.__doc__ = """
|
||||
reset(self)
|
||||
|
||||
复位操作
|
||||
"""
|
||||
|
||||
StoplossBase.clone.__doc__ = """
|
||||
clone(self)
|
||||
|
||||
克隆操作
|
||||
"""
|
||||
|
||||
StoplossBase._calculate.__doc__ = """
|
||||
_calculate(self)
|
||||
|
||||
【重载接口】子类计算接口
|
||||
"""
|
||||
|
||||
StoplossBase._reset.__doc__ = """
|
||||
_reset(self)
|
||||
|
||||
【重载接口】子类复位接口,复位内部私有变量
|
||||
"""
|
||||
|
||||
StoplossBase._clone.__doc__ = """
|
||||
_clone(self)
|
||||
|
||||
【重载接口】子类克隆接口
|
||||
"""
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
|
@ -24,48 +24,63 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
|
||||
from . import _trade_sys as csys
|
||||
from ._trade_sys import (System,
|
||||
getSystemPartName,
|
||||
getSystemPartEnum,
|
||||
TradeRequest)
|
||||
from ._trade_sys import SYS_Simple as cpp_SYS_Simple
|
||||
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
|
||||
|
||||
System = csys.System
|
||||
System.__unicode__ = unicodeFunc
|
||||
System.__repr__ = reprFunc
|
||||
|
||||
System.ENVIRONMENT = System.SystemPart.ENVIRONMENT
|
||||
System.CONDITION = System.SystemPart.CONDITION
|
||||
System.SIGNAL = System.SystemPart.SIGNAL
|
||||
System.STOPLOSS = System.SystemPart.STOPLOSS
|
||||
System.TAKEPROFIT = System.SystemPart.TAKEPROFIT
|
||||
System.MONEYMANAGER = System.SystemPart.MONEYMANAGER
|
||||
System.PROFITGOAL = System.SystemPart.PROFITGOAL
|
||||
System.SLIPPAGE = System.SystemPart.SLIPPAGE
|
||||
System.INVALID = System.SystemPart.INVALID
|
||||
System.ENVIRONMENT = System.Part.ENVIRONMENT
|
||||
System.CONDITION = System.Part.CONDITION
|
||||
System.SIGNAL = System.Part.SIGNAL
|
||||
System.STOPLOSS = System.Part.STOPLOSS
|
||||
System.TAKEPROFIT = System.Part.TAKEPROFIT
|
||||
System.MONEYMANAGER = System.Part.MONEYMANAGER
|
||||
System.PROFITGOAL = System.Part.PROFITGOAL
|
||||
System.SLIPPAGE = System.Part.SLIPPAGE
|
||||
System.INVALID = System.Part.INVALID
|
||||
|
||||
SystemPart = System.SystemPart
|
||||
|
||||
getSystemPartName = csys.getSystemPartName
|
||||
getSystemPartEum = csys.getSystemPartEnum
|
||||
#SystemPart = System.Part
|
||||
|
||||
|
||||
def SYS_Simple(tm = None, mm = None, ev = None, cn = None,
|
||||
sg = None, sl = None, tp = None, pg = None, sp = None):
|
||||
"""
|
||||
创建简单系统实例(每次交易不进行多次加仓或减仓,即每次买入后在卖出时全部卖出),
|
||||
系统实例在运行时(调用run方法),至少需要一个配套的交易管理实例、一个资金管理策略
|
||||
创建简单系统实例(每次交易不进行多次加仓或减仓,即每次买入后在卖出时全部卖出),
|
||||
系统实例在运行时(调用run方法),至少需要一个配套的交易管理实例、一个资金管理策略
|
||||
和一个信号指示器),可以在创建系统实例后进行指定。如果出现调用run时没有任何输出,
|
||||
且没有正确结果的时候,可能是未设置tm、sg、mm。
|
||||
tm: 交易管理实例
|
||||
mm: 资金管理策略
|
||||
ev: 市场环境判断策略
|
||||
cn: 系统有效条件
|
||||
sg: 信号指示器
|
||||
sl: 止损策略
|
||||
tp: 止盈策略
|
||||
pg: 盈利目标策略
|
||||
sp: 移滑价差算法
|
||||
且没有正确结果的时候,可能是未设置tm、sg、mm。进行回测时,使用 run 方法,如::
|
||||
|
||||
#创建模拟交易账户进行回测,初始资金30万
|
||||
my_tm = crtTM(initCash = 300000)
|
||||
|
||||
#创建信号指示器(以5日EMA为快线,5日EMA自身的10日EMA最为慢线,快线向上穿越
|
||||
#慢线时买入,反之卖出)
|
||||
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
|
||||
|
||||
#固定每次买入1000股
|
||||
my_mm = MM_FixedCount(1000)
|
||||
|
||||
#创建交易系统并运行
|
||||
sys = SYS_Simple(tm = my_tm, sg = my_sg, mm = my_mm)
|
||||
sys.run(sm['sz000001'], Query(-150))
|
||||
|
||||
:param TradeManager tm: 交易管理实例
|
||||
:param MoneyManager mm: 资金管理策略
|
||||
:param EnvironmentBase ev: 市场环境判断策略
|
||||
:param ConditionBase cn: 系统有效条件
|
||||
:param SignalBase sg: 信号指示器
|
||||
:param StoplossBase sl: 止损策略
|
||||
:param StoplossBase tp: 止盈策略
|
||||
:param ProfitGoalBase pg: 盈利目标策略
|
||||
:param SlippageBase sp: 移滑价差算法
|
||||
:return: system实例
|
||||
"""
|
||||
sys_ins = csys.SYS_Simple()
|
||||
sys_ins = cpp_SYS_Simple()
|
||||
if tm:
|
||||
sys_ins.tm = tm
|
||||
if mm:
|
||||
@ -84,4 +99,91 @@ def SYS_Simple(tm = None, mm = None, ev = None, cn = None,
|
||||
sys_ins.pg = pg
|
||||
if sp:
|
||||
sys_ins.sp = sp
|
||||
return sys_ins
|
||||
return sys_ins
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string
|
||||
#------------------------------------------------------------------
|
||||
|
||||
System.Part.__doc__ = """
|
||||
系统部件枚举值,系统的买入/卖出等操作可由这些部件触发,用于标识实际交易指令的来源,
|
||||
参见::py:class:`TradeRecord`。
|
||||
|
||||
实际使用中,可使用 System.ENVIRONMENT 的简化方式 代替 System.Part.ENVIRONMENT,
|
||||
其他与此类似。
|
||||
|
||||
- System.Part.ENVIRONMENT - 市场环境判断策略
|
||||
- System.Part.CONDITION - 系统有效条件
|
||||
- System.Part.SIGNAL - 信号指示器
|
||||
- System.Part.STOPLOSS - 止损策略
|
||||
- System.Part.TAKEPROFIT - 止盈策略
|
||||
- System.Part.MONEYMANAGER - 资金管理策略
|
||||
- System.Part.PROFITGOAL - 盈利目标策略
|
||||
- System.Part.SLIPPAGE - 移滑价差算法
|
||||
- System.Part.INVALID - 无效值边界,大于等于该值时为无效部件
|
||||
"""
|
||||
|
||||
|
||||
System.__doc__ = """
|
||||
系统基类。需要扩展或实现更复杂的系统交易行为,可从此类继承。
|
||||
|
||||
系统是指针对针对单个交易对象的完整策略,包括环境判断、系统有效条件、资金管理、止损、
|
||||
止盈、盈利目标、移滑价差的完整策略,用于模拟回测。
|
||||
|
||||
公共参数:
|
||||
|
||||
delay=True (bool) : 是否延迟到下一个bar开盘时进行交易
|
||||
delay_use_current_price=True (bool) : 延迟操作的情况下,是使用当前交易时bar
|
||||
的价格计算新的止损价/止赢价/目标价还是
|
||||
使用上次计算的结果
|
||||
max_delay_count=3 (int) : 连续延迟交易请求的限制次数
|
||||
tp_monotonic=True (bool) : 止赢单调递增
|
||||
tp_delay_n=3 (int) : 止盈延迟开始的天数,即止盈策略判断从实际交易几天后开始生效
|
||||
ignore_sell_sg=False (bool) : 忽略卖出信号,只使用止损/止赢等其他方式卖出
|
||||
support_borrow_cash=False (bool) : 在现金不足时,是否支持借入现金,融资
|
||||
support_borrow_stock=False (bool) : 在没有持仓时,是否支持借入证券,融券
|
||||
"""
|
||||
|
||||
System.run.__doc__ = """
|
||||
run(self, stock, query[, reset=True])
|
||||
|
||||
运行系统,执行回测
|
||||
|
||||
:param Stock stock: 交易的证券
|
||||
:param Query query: K线数据查询条件
|
||||
:param bool reset: 是否同时复位所有组件,尤其是tm实例
|
||||
"""
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
# add doc-string for build_in func
|
||||
#------------------------------------------------------------------
|
||||
|
||||
getSystemPartName.__doc__ = """
|
||||
getSystemPartName(part)
|
||||
|
||||
获取部件的字符串名称
|
||||
|
||||
- System.Part.ENVIRONMENT - "EV"
|
||||
- System.Part.CONDITION - "CN"
|
||||
- System.Part.SIGNAL - "SG"
|
||||
- System.Part.STOPLOSS - "SL"
|
||||
- System.Part.TAKEPROFIT - "TP"
|
||||
- System.Part.MONEYMANAGER - "MM"
|
||||
- System.Part.PROFITGOAL - "PG"
|
||||
- System.Part.SLIPPAGE - "SP"
|
||||
- System.Part.INVALID - "--"
|
||||
|
||||
:param int part: System.Part 枚举值
|
||||
:rtype: str
|
||||
"""
|
||||
|
||||
getSystemPartEnum.__doc__ = """
|
||||
getSystemPartEnum(part_name)
|
||||
|
||||
根据系统部件的字符串名称获取相应的枚举值
|
||||
|
||||
:param str part_name: 系统部件的字符串名称,参见::py:func:`getSystemPartName`
|
||||
:rtype: System.Part
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user