完善帮助信息

This commit is contained in:
fasiondog 2017-10-05 01:04:40 +08:00
parent 509c785451
commit cb60a10bad
8 changed files with 502 additions and 63 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -12,6 +12,10 @@
namespace hku {
/**
*
* @ingroup System
*/
class HKU_API TradeRequest {
public:
TradeRequest();

View File

@ -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)

View File

@ -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:
"""

View File

@ -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:

View File

@ -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)
"""
#------------------------------------------------------------------

View File

@ -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时没有任何输出
tmsgmm
tm:
mm:
ev:
cn:
sg:
sl:
tp:
pg:
sp:
tmsgmm使 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
"""