hikyuu2/hikyuu/trade_sys/slippage.py

191 lines
5.1 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
2017-10-04 00:34:24 +08:00
#
# 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.
2015-01-07 01:26:14 +08:00
2017-10-05 01:04:40 +08:00
from ._trade_sys import (SlippageBase, SL_FixedPercent, SL_FixedValue)
2015-01-07 01:26:14 +08:00
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
2017-10-05 01:04:40 +08:00
2015-01-07 01:26:14 +08:00
SlippageBase.__unicode__ = unicodeFunc
SlippageBase.__repr__ = reprFunc
def sl_init(self, name, params):
super(self.__class__, self).__init__(name)
self._name = name
self._params = params
for k,v in params.items():
self.setParam(k, v)
def crtSL(func, params={}, name='crtSL'):
"""
:param func:
:param {} params:
:param str name:
:return:
"""
meta_x = type(name, (SlippageBase,), {'__init__': sl_init})
meta_x._clone = lambda self: meta_x(self._name, self._params)
meta_x._calculate = func
return meta_x(name, params)
2017-10-05 01:04:40 +08:00
#------------------------------------------------------------------
# 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:
"""
2017-10-05 01:04:40 +08:00
SL_FixedValue.__doc__ = """
SP_FixedValuet([p=0.001])
= + = -
:param float p:
:return:
"""