完善帮助信息

This commit is contained in:
fasiondog 2017-10-04 00:34:24 +08:00
parent 56b642b03a
commit 509c785451
16 changed files with 1382 additions and 161 deletions

View File

@ -60,8 +60,12 @@
* 使 crtTM
* @ingroup TradeManager
*
* @defgroup OrderBroker TradeManager
*
* @defgroup OrderBroker OrderBroker
*
* @ingroup TradeManager
*
* @defgroup Performance Performance
*
* @ingroup TradeManager
*
* @defgroup TradeSystem TradeSystem

View File

@ -13,27 +13,41 @@
namespace hku {
/*
/**
*
* @ingroup Performance
*/
class HKU_API Performance {
public:
Performance();
virtual ~Performance();
/** 复位,清除已计算的结果 */
void reset();
/** 按指标名称获取指标值,必须在运行 statistics 或 report 之后生效 */
double get(const string& name) const;
/** 同 get */
double operator[](const string& name) const { return get(name); }
/**
*
* @param tm
* @param datetime
* @return
*/
string report(const TradeManagerPtr& tm,
const Datetime& datetime = Datetime::now());
/*
* , datetime必须大于等于lastDatetime
/**
* , datetime必须大于等于lastDatetime
* 便
* @param tm
* @param datetime
*/
void statistics(const TradeManagerPtr& tm, const Datetime& datetime);
void statistics(const TradeManagerPtr& tm,
const Datetime& datetime = Datetime::now());
typedef map<string, double> map_type;

View File

@ -14,8 +14,10 @@ using namespace hku;
void export_Performance() {
class_<Performance>("Performance", init<>())
.def("reset", &Performance::reset)
.def("report", &Performance::report)
.def("statistics", &Performance::statistics)
.def("report", &Performance::report,
(arg("tm"), arg("datetime")=Datetime::now()))
.def("statistics", &Performance::statistics,
(arg("tm"), arg("datetime")=Datetime::now()))
.def("get", &Performance::get)
.def("__getitem__", &Performance::get)
;

View File

@ -89,12 +89,12 @@ void export_TradeManager() {
.def("regBroker", &TradeManager::regBroker)
.def("clearBroker", &TradeManager::clearBroker)
.def("getMarginRate", &TradeManager::getMarginRate)
//.def("getMarginRate", &TradeManager::getMarginRate)
.def("have", &TradeManager::have)
.def("getStockNumber", &TradeManager::getStockNumber)
.def("getShortStockNumber", &TradeManager::getShortStockNumber)
//.def("getShortStockNumber", &TradeManager::getShortStockNumber)
.def("getHoldNumber", &TradeManager::getHoldNumber)
.def("getShortHoldNumber", &TradeManager::getShortHoldNumber)
//.def("getShortHoldNumber", &TradeManager::getShortHoldNumber)
.def("getTradeList", &TradeManager::getTradeList,
return_value_policy<copy_const_reference>())
.def("getPositionList", &TradeManager::getPositionList)
@ -104,9 +104,9 @@ void export_TradeManager() {
.def("getBuyCost", &TradeManager::getBuyCost)
.def("getSellCost", &TradeManager::getSellCost)
//.def("getBorrowCashCost", &TradeManager::getBorrowCashCost)
.def("getReturnCashCost", &TradeManager::getReturnCashCost)
.def("getBorrowStockCost", &TradeManager::getBorrowStockCost)
.def("getReturnStockCost", &TradeManager::getReturnStockCost)
//.def("getReturnCashCost", &TradeManager::getReturnCashCost)
//.def("getBorrowStockCost", &TradeManager::getBorrowStockCost)
//.def("getReturnStockCost", &TradeManager::getReturnStockCost)
.def("cash", &TradeManager::cash, cash_overload())
.def("getFunds", getFunds_1, getFunds_1_overload())
.def("getFunds", getFunds_2, getFunds_2_overload())
@ -117,12 +117,12 @@ void export_TradeManager() {
.def("checkin", &TradeManager::checkin)
.def("checkout", &TradeManager::checkout)
.def("checkinStock", &TradeManager::checkinStock)
.def("checkoutStock", &TradeManager::checkoutStock)
.def("borrowCash", &TradeManager::borrowCash)
.def("returnCash", &TradeManager::returnCash)
.def("borrowStock", &TradeManager::borrowStock)
.def("returnStock", &TradeManager::returnStock)
//.def("checkinStock", &TradeManager::checkinStock)
//.def("checkoutStock", &TradeManager::checkoutStock)
//.def("borrowCash", &TradeManager::borrowCash)
//.def("returnCash", &TradeManager::returnCash)
//.def("borrowStock", &TradeManager::borrowStock)
//.def("returnStock", &TradeManager::returnStock)
//.def("buy", &TradeManager::buy, buy_overload())
.def("buy", &TradeManager::buy,
buy_overload(args("datetime", "stock", "realPrice",
@ -131,8 +131,8 @@ void export_TradeManager() {
.def("sell", &TradeManager::sell,
sell_overload(args("datetime", "stock", "realPrice",
"num", "stoploss", "goalPrice", "planPrice", "part")))
.def("buyShort", &TradeManager::buyShort, buyShort_overload())
.def("sellShort", &TradeManager::sellShort, sellShort_overload())
//.def("buyShort", &TradeManager::buyShort, buyShort_overload())
//.def("sellShort", &TradeManager::sellShort, sellShort_overload())
.def("tocsv", &TradeManager::tocsv)

View File

@ -21,6 +21,7 @@ void export_Selector();
void export_AllocateMoney();
BOOST_PYTHON_MODULE(_trade_sys) {
docstring_options doc_options(false);
export_Environment();
export_Condition();
export_MoneyManager();

View File

@ -128,52 +128,3 @@ try:
except:
pass
TC_FixedA.__doc__ = """
201581A股交易成本算法,
1
2
1.85
1
commission 1.80.0018
lowest_commission 5
stamptax 0.001
transferfee 0.001
lowest_transferfee 1
"""
TC_FixedA2015.__doc__ = """
201581A股交易成本算法,
1
2
5
0.02
commission 1.80.0018
lowest_commission 5
stamptax 0.001
transferfee 0.001
"""
crtTM.__doc__ = """
使
使
:
datetime , 1990-1-1
initCash 100000
costFunc ,TC_Zero()
name SYS
"""

View File

@ -305,4 +305,335 @@ clone(self)
:rtype: TradeManager
"""
TradeManager.regBroker.__doc__ = """
regBroker(self, broker)
:param OrderBrokerBase broker:
"""
TradeManager.clearBroker.__doc__ = """
clearBroker(self)
"""
TradeManager.have.__doc__ = """
have(self, stock)
:param Stock stock:
:rtype: bool
"""
TradeManager.getStockNumber.__doc__ = """
getStockNumber(self)
:rtype: int
"""
TradeManager.getHoldNumber.__doc__ = """
getHoldNumber(self, datetime, stock)
:param Datetime datetime:
:param Stock stock:
:rtype: int
"""
TradeManager.getTradeList.__doc__ = """
getTradeList(self)
:rtype: TradeRecordList
"""
TradeManager.getPositionList.__doc__ = """
getPositionList(self)
:rtype: PositionRecordList
"""
TradeManager.getHistoryPositionList.__doc__ = """
getHistoryPositionList(self)
:rtype: PositionRecordList
"""
TradeManager.getPosition.__doc__ = """
getPosition(self, stock)
PositionRecord()
:param Stock stock:
:rtype: PositionRecord
"""
TradeManager.getBuyCost.__doc__ = """
getBuyCost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param int num:
:rtype: CostRecord
"""
TradeManager.getSellCost.__doc__ = """
getSellCost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param int num:
:rtype: CostRecord
"""
TradeManager.cash.__doc__ = """
cash(self, datetime[, ktype=KQuery.KType.DAY])
:param Datetime datetime:
:param ktype: K线类型
:rtype: float
"""
TradeManager.getFunds.__doc__ = """
getFunds(self[,ktype = KQuery.DAY])
:param KQuery.KType ktype: K线类型
:rtype: FundsRecord
getFunds(self, datetime, [ktype = KQuery.DAY])
:param Datetime datetime:
:param KQuery.KType ktype: K线类型
:rtype: FundsRecord
"""
TradeManager.getFundsCurve.__doc__ = """
getFundsCurve(self, dates[, ktype = KQuery.DAY])
线
:param DatetimeList dates: 线
:param KQuery.KType ktype: K线类型
:return:
:rtype: PriceList
"""
TradeManager.getProfitCurve.__doc__ = """
getProfitCurve(self, dates[, ktype = KQuery.DAY])
线线
:param DatetimeList dates: 线
:param KQuery.KType ktype: K线类型
:return: 线
:rtype: PriceList
"""
TradeManager.checkin.__doc__ = """
checkin(self, datetime, cash)
:param Datetime datetime:
:param float cash:
:rtype: TradeRecord
"""
TradeManager.checkout.__doc__ = """
checkout(self, datetime, cash)
:param Datetime datetime:
:param float cash:
:rtype: TradeRecord
"""
TradeManager.buy.__doc__ = """
buy(self, datetime, stock, realPrice, number[, stoploss=0.0, goalPrice=0.0, planPrice=0.0, part=System.INVALID])
:param Datetime datetime:
:param Stock stock:
:param float realPrice:
:param int num:
:param float stoploss:
:param float goalPrice:
:param float planPrice:
:param SystemPart part:
:rtype: TradeRecord
"""
TradeManager.sell.__doc__ = """
sell(self, datetime, stock, realPrice[, number=Constant.null_size, stoploss=0.0, goalPrice=0.0, planPrice=0.0, part=System.INVALID])
:param Datetime datetime:
:param Stock stock:
:param float realPrice:
:param int num: Constant.null_size
:param float stoploss:
:param float goalPrice:
:param float planPrice:
:param SystemPart part:
:rtype: TradeRecord
"""
TradeManager.tocsv.__doc__ = """
tocsv(self, path)
csv格式输出交易记录线
:param string path:
"""
#------------------------------------------------------------------
# Performance
#------------------------------------------------------------------
Performance.__doc__ = """简单绩效统计"""
Performance.reset.__doc__ = """
reset(self)
"""
Performance.report.__doc__ = """
report(self, tm[, datetime=Datetime.now()])
:param TradeManager tm:
:param Datetime datetime:
:rtype: str
"""
Performance.statistics.__doc__ = """
statistics(self, tm[, datetime=Datetime.now()])
, datetime必须大于等于lastDatetime
:param TradeManager tm:
:param Datetime datetime:
"""
Performance.get.__doc__ = """
get(self, name)
statistics report
:param str name:
:rtype: float
"""
Performance.__getitem__.__doc__ = """
__getitem__(self, name)
get statistics report
:param str name:
:rtype: float
"""
#------------------------------------------------------------------
# build_in
#------------------------------------------------------------------
crtTM.__doc__ = """
crtTM([datetime = Datetime(199001010000), initcash = 100000, costfunc = TC_Zero(), name = "SYS"])
使
:param Datetime datetime:
:param float initcash:
:param TradeCost costfunc:
:param string name:
:rtype: TradeManager
"""
TC_TestStub.__doc__ = """
"""
TC_FixedA.__doc__ = """
TC_FixedA([commission=0.0018, lowestCommission=5.0, stamptax=0.001, transferfee=0.001, lowestTransferfee=1.0])
201581A股交易成本算法11
::
1
2
5
:param float commission:
:param float lowestCommission:
:param float stamptax:
:param float transferfee:
:param float lowestTransferfee:
:return: :py:class:`TradeCostBase`
"""
TC_FixedA2015.__doc__ = """
TC_FixedA2015([commission=0.0018, lowestCommission=5.0, stamptax=0.001, transferfee=0.00002])
201581A股交易成本算法0.02
::
1
2
5
:param float commission:
:param float lowestCommission:
:param float stamptax:
:param float transferfee:
:return: :py:class:`TradeCostBase`
"""
TC_Zero.__doc__ = """
TC_Zero()
"""
TC_TestStub.__doc__ = """仅用于测试"""

View File

@ -1,11 +1,29 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130213, Added by fasiondog
#===============================================================================
__all__ = ['system', 'environment', 'condition', 'moneymanager', 'signal',
'stoploss', 'profitgoal', 'slippage']

View File

@ -1,27 +1,36 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from ._trade_sys import ConditionBase, CN_OPLine
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
ConditionBase = csys.ConditionBase
ConditionBase.__unicode__ = unicodeFunc
ConditionBase.__repr__ = reprFunc
CN_OPLine = csys.CN_OPLine
CN_OPLine.__doc__ += """\n
使线op值线op时
:param Operand op: Operand实例
:return:
"""
def cn_init(self, name, params):
super(self.__class__, self).__init__(name)
@ -45,3 +54,153 @@ def crtCN(func, params={}, name='crtCN'):
return meta_x(name, params)
#------------------------------------------------------------------
# add doc-string
#------------------------------------------------------------------
ConditionBase.__doc__ = """
ConditionBase._calculate() -
ConditionBase._clone() -
ConditionBase._reset() -
"""
ConditionBase.name.__doc__ = """名称"""
ConditionBase.__init__.__doc__ = """
__init__(self[, name="ConditionBase"])
:param str name:
"""
ConditionBase.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
ConditionBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
ConditionBase.isValid.__doc__ = """
isValid(self, datetime)
:param Datetime datetime:
:return: True | False
"""
ConditionBase.setTO.__doc__ = """
setTO(self, k)
:param KData k:
"""
ConditionBase.getTO.__doc__ = """
getTO(self)
:return:
:rtype: KData
"""
ConditionBase.setTM.__doc__ = """
setTM(self, tm)
:param TradeManager tm:
"""
ConditionBase.getTM.__doc__ = """
getTM(self)
:return:
:rtype: TradeManager
"""
ConditionBase.setSG.__doc__ = """
setSG(self, sg)
:param SignalBase sg:
"""
ConditionBase.getSG.__doc__ = """
getSG(self)
:rtype: SignalBase
"""
ConditionBase.reset.__doc__ = """
reset(self)
"""
ConditionBase.clone.__doc__ = """
clone(self)
"""
ConditionBase._addValid.__doc__ = """
_addValid(self, datetime)
_calculate中调用
:param Datetime datetime:
"""
ConditionBase._calculate.__doc__ = """
_calculate(self)
"""
ConditionBase._reset.__doc__ = """
_reset(self)
"""
ConditionBase._clone.__doc__ = """
_clone(self)
"""
#------------------------------------------------------------------
# add doc-string for build_in func
#------------------------------------------------------------------
CN_OPLine.__doc__ = """
CN_OPLine(op)
使线op值线op时
:param Operand op: Operand实例
:return:
:rtype: ConditionBase
"""

View File

@ -1,20 +1,37 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from ._trade_sys import EnvironmentBase, EV_TwoLine
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
EnvironmentBase = csys.EnvironmentBase
EnvironmentBase.__unicode__ = unicodeFunc
EnvironmentBase.__repr__ = reprFunc
EV_TwoLine = csys.EV_TwoLine
def ev_init(self, name, params):
super(self.__class__, self).__init__(name)
@ -23,6 +40,7 @@ def ev_init(self, name, params):
for k,v in params.items():
self.setParam(k, v)
def crtEV(func, params={}, name='crtEV'):
"""
@ -38,7 +56,124 @@ def crtEV(func, params={}, name='crtEV'):
return meta_x(name, params)
EV_TwoLine.__doc__ += """\n
#------------------------------------------------------------------
# add doc-string
#------------------------------------------------------------------
EnvironmentBase.__doc__ = """
EnvironmentBase._calculate() -
EnvironmentBase._clone() -
EnvironmentBase._reset() -
"""
EnvironmentBase.__init__.__doc__ = """
__init__(self[, name='EnvironmentBase'])
:param str name:
"""
EnvironmentBase.name.__doc__ = """名称"""
EnvironmentBase.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
EnvironmentBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
EnvironmentBase.setQuery.__doc__ = """
setQuery(self, query)
:param KQuery query:
"""
EnvironmentBase.getQuery.__doc__ = """
getQuery(self)
:return:
:rtype: KQuery
"""
EnvironmentBase.isValid.__doc__ = """
isValid(self, datetime)
:param Datetime datetime:
:return: True | False
"""
EnvironmentBase._addValid.__doc__ = """
_addValid(self, datetime)
_calculate中调用
:param Datetime datetime:
"""
EnvironmentBase.reset.__doc__ = """
reset(self)
"""
EnvironmentBase.clone.__doc__ = """
clone(self)
"""
EnvironmentBase._reset.__doc__ = """
_reset(self)
"""
EnvironmentBase._clone.__doc__ = """
_clone(self)
"""
EnvironmentBase._calculate.__doc__ = """
_calculate(self)
"""
#------------------------------------------------------------------
# add doc-string for build_in func
#------------------------------------------------------------------
EV_TwoLine.__doc__ = """
EV_TwoLine(fast, slow[, market = 'SH'])
线线线
:param Operand fast: 线

View File

@ -1,27 +1,44 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from ._trade_sys import (MoneyManagerBase,
MM_Nothing,
MM_FixedRisk,
MM_FixedCapital,
MM_FixedCount,
MM_FixedPercent,
MM_FixedUnits,
MM_WilliamsFixedRisk)
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
MoneyManagerBase = csys.MoneyManagerBase
MoneyManagerBase.__unicode__ = unicodeFunc
MoneyManagerBase.__repr__ = reprFunc
MM_FixedRisk = csys.MM_FixedRisk
MM_FixedCapital = csys.MM_FixedCapital
MM_FixedCount = csys.MM_FixedCount
MM_FixedPercent = csys.MM_FixedPercent
MM_FixedUnits = csys.MM_FixedUnits
MM_FixedCapital = csys.MM_FixedCapital
MM_WilliamsFixedRisk = csys.MM_WilliamsFixedRisk
MM_Nothing = csys.MM_Nothing
def mm_init(self, name, params):
super(self.__class__, self).__init__(name)
@ -44,21 +61,224 @@ def crtMM(func, params={}, name='crtMM'):
meta_x._calculate = func
return meta_x(name, params)
MM_Nothing.__doc__ += """\n
#------------------------------------------------------------------
# add doc-string
#------------------------------------------------------------------
MoneyManagerBase.__doc__ = """
auto-checkin=False (bool) :
checkin
max-stock=200 (int) :
MoneyManagerBase.buyNotify() -
MoneyManagerBase.sellNotify() -
MoneyManagerBase._getBuyNumber() -
MoneyManagerBase._getSellNumber() -
MoneyManagerBase._reset() -
MoneyManagerBase._clone() -
"""
MoneyManagerBase.name.__doc__ = """名称"""
MoneyManagerBase.__init__.__doc__ = """
__init__(self[, name="MoneyManagerBase])
:param str name:
"""
MoneyManagerBase.getParam.__doc__ = """
getParam(self, name)
.. note::
auto-checkinbool类型False
checkin
:param str name:
:return:
:raises out_of_range:
"""
MoneyManagerBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
MoneyManagerBase.reset.__doc__ = """
reset(self)
"""
MoneyManagerBase.clone.__doc__ = """
clone(self)
"""
MoneyManagerBase.buyNotify.__doc__ = """
buyNotify(self, trade_record)
:param TradeRecord trade_record:
"""
MoneyManagerBase.sellNotify.__doc__ = """
sellNotify(self, trade_record)
:param TradeRecord trade_record:
"""
MoneyManagerBase.getBuyNumber.__doc__ = """
getBuyNumber(self, datetime, stock, price, risk)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param float risk: 00
:return:
:rtype: int
"""
MoneyManagerBase.getSellNumber.__doc__ = """
getSellNumber(self, datetime, stock, price, risk)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param float risk: 00
:return:
:rtype: int
"""
MoneyManagerBase._getBuyNumber.__doc__ = """
_getBuyNumber(self, datetime, stock, price, risk)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param float risk: 00
:return:
:rtype: int
"""
MoneyManagerBase._getSellNumber.__doc__ = """
_getSellNumber(self, datetime, stock, price, risk)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param float risk: 00
:return:
:rtype: int
"""
MoneyManagerBase._reset.__doc__ = """
_reset(self)
"""
MoneyManagerBase._clone.__doc__ = """
_clone(self)
"""
#------------------------------------------------------------------
# add doc-string for build_in func
#------------------------------------------------------------------
MM_Nothing.__doc__ = """
MM_Nothing()
"""
MM_FixedCount.__doc__ += """\n
MM_FixedRisk.__doc__ = """
MM_FixedRisk([risk = 1000.00])
1000 = /
:param float risk:
:return:
"""
MM_FixedCapital.__doc__ = """
MM_FixedCapital([capital = 10000.0])
:param float capital:
:return:
"""
MM_FixedCount.__doc__ = """
MM_FixedCount([n = 100])
:param int n:
:return:
"""
MM_FixedPercent.__doc__ += """\n
P * / R[BOOK3]_, [BOOK4]_ .
MM_FixedPercent.__doc__ = """
MM_FixedPercent([p = 0.03])
P * / R
:param float p:
:return:
"""
MM_FixedUnits.__doc__ = """
MM_FixedUnits([n = 33])
:param int n: n个资金单位
:return:
"""
MM_WilliamsFixedRisk.__doc__ = """
MM_WilliamsFixedRisk([p=0.1, max_loss=1000.0])
"""

View File

@ -1,11 +1,29 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
@ -17,13 +35,13 @@ ProfitGoalBase.__repr__ = reprFunc
PG_NoGoal = csys.PG_NoGoal
PG_FixedPercent = csys.PG_FixedPercent
PG_NoGoal.__doc__ += """\n
PG_NoGoal.__doc__ = """\n
:return:
"""
PG_FixedPercent.__doc__ += """\n
PG_FixedPercent.__doc__ = """\n
= * (1 + p)
:param float p:

View File

@ -1,25 +1,43 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from ._trade_sys import (SignalBase,
SG_Bool,
SG_Single,
SG_Single2,
SG_Cross,
SG_CrossGold,
SG_Flex)
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
SignalBase = csys.SignalBase
SignalBase.__unicode__ = unicodeFunc
SignalBase.__repr__ = reprFunc
SG_Single = csys.SG_Single
SG_Single2 = csys.SG_Single2
SG_Cross = csys.SG_Cross
SG_CrossGold = csys.SG_CrossGold
SG_Flex = csys.SG_Flex
SG_Bool = csys.SG_Bool
def sig_init(self, name, params):
super(self.__class__, self).__init__(name)
@ -42,7 +60,222 @@ def crtSG(func, params={}, name='crtSG'):
meta_x._calculate = func
return meta_x(name, params)
SG_Flex.__doc__ += """\n
#------------------------------------------------------------------
# add doc-string
#------------------------------------------------------------------
SignalBase.__doc__ = """
alternate (bool|True) 线
线
SignalBase._calculate() -
SignalBase._clone() -
SignalBase._reset() -
1:
from hikyuu.trade_sys.signal import SignalBase
from hikyuu.indicator import HHV, LLV, CLOSE, REF
class TurtleSignal(SignalBase):
def __init__(self, n = 20):
super(TurtleSignal, self).__init__("TurtleSignal")
self.setParam("n", 20)
def _clone(self):
return TurtleSignal()
def _calculate(self):
n = self.getParam("n")
k = self.getTO()
c = CLOSE(k)
h = REF(HHV(c, n), 1) #n日高点
L = REF(LLV(c, n), 1) #n日低点
for i in range(h.discard, len(k)):
if (c[i] >= h[i]):
self._addBuySignal(k[i].datetime)
elif (c[i] <= L[i]):
self._addSellSignal(k[i].datetime)
if __name__ == "__main__":
from examples_init import *
sg = TurtleSignal()
s = getStock("sh000001")
k = s.getKData(Query(-500))
#只有设置交易对象时,才会开始实际计算
sg.setTO(k)
dates = k.getDatetimeList()
for d in dates:
if (sg.shouldBuy(d)):
print("买入:%s" % d)
elif (sg.shouldSell(d)):
print("卖出: %s" % d)
2:
class SignalPython(SignalBase):
def __init__(self):
super(SignalPython, self).__init__("SignalPython")
self._x = 0 #
self.setParam("test", 30)
def _reset(self):
self._x = 0
def _clone(self):
p = SignalPython()
p._x = self._x
return p
def _calculate(self):
self._addBuySignal(Datetime(201201210000))
self._addSellSignal(Datetime(201201300000))
"""
SignalBase.name.__doc__ = """名称"""
SignalBase.__init__.__doc__ = """
__init__(self[, name="SignalBase"])
:param str name:
"""
SignalBase.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
SignalBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
SignalBase.setTO.__doc__ = """
setTO(self, k)
:param KData k:
"""
SignalBase.getTO.__doc__ = """
getTO(self)
:return:
:rtype: KData
"""
SignalBase.shouldBuy.__doc__ = """
shouldBuy(self, datetime)
:param Datetime datetime:
:rtype: bool
"""
SignalBase.shouldSell.__doc__ = """
shouldSell(self, datetime)
:param Datetime datetime:
:rtype: bool
"""
SignalBase.getBuySignal.__doc__ = """
getBuySignal(self)
:rtype: DatetimeList
"""
SignalBase.getSellSignal.__doc__ = """
getSellSignal(self)
:rtype: DatetimeList
"""
SignalBase._addBuySignal.__doc__ = """
_addBuySignal(self, datetime)
_calculate中调用
:param Datetime datetime:
"""
SignalBase._addSellSignal.__doc__ = """
_addSellSignal(self, datetime)
_calculate中调用
:param Datetime datetime:
"""
SignalBase.reset.__doc__ = """
reset(self)
"""
SignalBase.clone.__doc__ = """
clone(self)
"""
SignalBase._calculate.__doc__ = """
_calculate(self)
"""
SignalBase._reset.__doc__ = """
_reset(self)
"""
SignalBase._clone.__doc__ = """
_clone(self)
"""
#------------------------------------------------------------------
# add doc-string for build_in func
#------------------------------------------------------------------
SG_Flex.__doc__ = """
SG_Flex(ind, slow_n[, kpart = 'CLOSE'])
使EMA(slow_n)线线线穿线线穿线
:param Operand ind:
@ -51,10 +284,10 @@ SG_Flex.__doc__ += """\n
:return:
"""
SG_Cross.__doc__ += """\n
线线穿线
线穿线
5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
SG_Cross.__doc__ = """
SG_Cross(fast, slow[, kpart = "CLOSE"])
线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
SG_Cross(OP(MA(n=10)), OP(MA(n=30)))
@ -64,7 +297,9 @@ SG_Cross.__doc__ += """\n
:return:
"""
SG_CrossGold.__doc__ += """\n
SG_CrossGold.__doc__ = """
SG_CrossGold(fast, slow[, kpart = "CLOSE"])
线穿线线线
线穿线线线::
@ -73,10 +308,12 @@ SG_CrossGold.__doc__ += """\n
:param Operand fast: 线
:param Operand slow: 线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return:
:return:
"""
SG_Single.__doc__ += """\n
SG_Single.__doc__ = """
SG_Single(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
线使 [BOOK1]_ 线线::
filter = percentage * STDEV((AMA-AMA[1], N)
@ -92,7 +329,9 @@ SG_Single.__doc__ += """\n
:return:
"""
SG_Single2.__doc__ += """\n
SG_Single2.__doc__ = """
SG_Single2(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
线2 [BOOK1]_::
filter = percentage * STDEV((AMA-AMA[1], N)
@ -107,8 +346,10 @@ SG_Single2.__doc__ += """\n
:return:
"""
SG_Bool.__doc__ += """\n
使bool数组的Operand分别作为买入
SG_Bool.__doc__ = """
SG_Bool(buy, sell[, kpart='CLOSE'])
使bool数组的Operand分别作为买入
:param Operand buy: Indicator中相应位置>0
:param Operand sell: Indicator中相应位置>0

View File

@ -1,11 +1,29 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
@ -39,14 +57,14 @@ def crtSL(func, params={}, name='crtSL'):
return meta_x(name, params)
SL_FixedPercent.__doc__ += """\n
SL_FixedPercent.__doc__ = """\n
= * (1 + p) = * (1 - p)
:param float p:
:return:
"""
SL_FixedValue.__doc__ += """\n
SL_FixedValue.__doc__ = """\n
= + = -
:param float p:

View File

@ -1,11 +1,29 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
@ -39,23 +57,96 @@ def crtST(func, params={}, name='crtST'):
meta_x._calculate = func
return meta_x(name, params)
ST_FixedPercent.__doc__ += """\n
#------------------------------------------------------------------
# add doc-string
#------------------------------------------------------------------
StoplossBase.__doc__ = """
/
/
SignalBase._calculate() -
SignalBase._clone() -
SignalBase._reset() -
"""
StoplossBase.name.__doc__ = """名称"""
StoplossBase.__init__.__doc__ = """
__init__(self[, name="StoplossBase"])
:param str name:
"""
StoplossBase.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
StoplossBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
StoplossBase.setTM.__doc__ = """
setTM(self, tm)
:param TradeManager tm:
"""
StoplossBase.getTM.__doc__ = """
getTM(self)
:rtype: TradeManager
"""
#------------------------------------------------------------------
# add doc-string for build_in func
#------------------------------------------------------------------
ST_FixedPercent.__doc__ = """
ST_FixedPercent([p=0.03])
:param float p: (0,1]
:return: /
"""
ST_Indicator.__doc__ += """\n
ST_Indicator.__doc__ = """
ST_Indicator(op[, kpart="CLOSE"])
使使10EMA作为止损::
ST_Indicator(OP(EMA(n=10)))
:param Operand op:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: /
"""
ST_Saftyloss.__doc__ += """\n
ST_Saftyloss.__doc__ = """
ST_Saftyloss([n1=10, n2=3, p=2.0])
2007 .(Alexander Elder) P202
1020穿穿

View File

@ -1,11 +1,29 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120130419, Added by fasiondog
#===============================================================================
from . import _trade_sys as csys
from hikyuu.util.unicode import (unicodeFunc, reprFunc)