hikyuu2/hikyuu/trade_manage/trade_doc.py

653 lines
20 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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.
from .trade import *
from hikyuu.trade_manage._trade_manage import CostRecord, TradeCostBase,\
PositionRecord, FundsRecord, TradeManager
#------------------------------------------------------------------
# CostRecord
#------------------------------------------------------------------
CostRecord.__doc__ = """交易成本记录"""
CostRecord.commission.__doc__ = """佣金(float)"""
CostRecord.stamptax.__doc__ = """印花税(float)"""
CostRecord.transferfee.__doc__ = """过户费(float)"""
CostRecord.others.__doc__ = """其它费用(float)"""
CostRecord.total.__doc__ = """总成本(float)= 佣金 + 印花税 + 过户费 + 其它费用"""
#------------------------------------------------------------------
# PositionRecord
#------------------------------------------------------------------
PositionRecord.__doc__ = """持仓记录"""
PositionRecord.stock.__doc__ = """交易对象Stock"""
PositionRecord.takeDatetime.__doc__ = """初次建仓时刻Datetime"""
PositionRecord.cleanDatetime.__doc__ = """平仓日期,当前持仓记录中为 constant.null_datetime"""
PositionRecord.number.__doc__ = """当前持仓数量int"""
PositionRecord.stoploss.__doc__ = """当前止损价float"""
PositionRecord.goalPrice.__doc__ = """当前的目标价格float"""
PositionRecord.totalNumber.__doc__ = """累计持仓数量int"""
PositionRecord.buyMoney.__doc__ = """累计买入资金float"""
PositionRecord.totalCost.__doc__ = """累计交易总成本float"""
PositionRecord.totalRisk.__doc__ = """累计交易风险float = 各次 (买入价格-止损)*买入数量, 不包含交易成本"""
PositionRecord.sellMoney.__doc__ = """累计卖出资金float"""
PositionRecordList.__doc__ = """持仓记录列表C++ std::vector<PositionRecord>包装"""
#------------------------------------------------------------------
# TradeCost
#------------------------------------------------------------------
TradeCostBase.__doc__ = """
* :py:meth:`TradeCostBase.getBuyCost` -
* :py:meth:`TradeCostBase.getSellCost` -
* :py:meth:`TradeCostBase._clone` -
"""
TradeCostBase.name.__doc__ = """交易算法名称"""
TradeCostBase.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
TradeCostBase.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
TradeCostBase.clone.__doc__ = """
clone(self)
"""
TradeCostBase.getBuyCost.__doc__ = """
getBuyCost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param size_t num:
:return:
:rtype: CostRecord
"""
TradeCostBase.getSellCost.__doc__ = """
getSellCost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param int num:
:return:
:rtype: CostRecord
"""
TradeCostBase._clone.__doc__ = """
_clone(self)
"""
#------------------------------------------------------------------
# FundsRecord
#------------------------------------------------------------------
FundsRecord.__doc__ = """当前资产情况记录由TradeManager.getFunds返回"""
FundsRecord.cash.__doc__ = """当前现金float"""
FundsRecord.market_value.__doc__ = """当前多头市值float"""
FundsRecord.short_market_value.__doc__ = """当前空头仓位市值float"""
FundsRecord.base_cash.__doc__ = """当前投入本金float"""
FundsRecord.base_asset.__doc__ = """当前投入的资产价值float"""
FundsRecord.borrow_cash.__doc__ = """当前借入的资金float即负债"""
FundsRecord.borrow_asset.__doc__ = """当前借入证券资产价值float"""
#------------------------------------------------------------------
# OrderBroker
#------------------------------------------------------------------
OrderBrokerBase.__doc__ = """
Python中非必须使用 OrderBrokerBase Python
buysell方法 :py:class:`OrderBrokerWrap` _buy
_sell
* :py:meth:`OrderBrokerBase._buy` -
* :py:meth:`OrderBrokerBase._sell` -
"""
OrderBrokerBase.name.__doc__ = """名称(可读写)"""
OrderBrokerBase.buy.__doc__ = """
buy(self, code, price, num)
:param str code:
:param float price:
:param int num:
:return:
:rtype: Datetime
"""
OrderBrokerBase.sell.__doc__ = """
sell(self, code, price, num)
:param str code:
:param float price:
:param int num:
:return:
:rtype: Datetime
"""
OrderBrokerBase._buy.__doc__ = """
_buy(self, code, price, num)
:param str code:
:param float price:
:param int num:
"""
OrderBrokerBase._sell.__doc__ = """
_sell(self, code, price, num)
:param str code:
:param float price:
:param int num:
"""
#------------------------------------------------------------------
# TradeManager
#------------------------------------------------------------------
TradeManager.__doc__ = """
使 crtTM
reinvest=False (bool) :
precision=2 (int) :
support_borrow_cash=False (bool) :
support_borrow_stock=False (bool) :
save_action=True (bool) : Python命令序列
"""
TradeManager.__init__.__doc__ = """
__init__(self, datetime, initcash, costfunc, name)
:param Datetime datetime:
:param float initCash:
:param TradeCostBase costFunc:
:param str name:
"""
TradeManager.name.__doc__ = """名称"""
TradeManager.initCash.__doc__ = """(只读)初始资金"""
TradeManager.initDatetime.__doc__ = """(只读)账户建立日期"""
TradeManager.costFunc.__doc__ = """交易成本算法"""
TradeManager.firstDatetime.__doc__ = """
null_datetime
"""
TradeManager.lastDatetime.__doc__ = """
"""
TradeManager.reinvest.__doc__ = """
//reinvest
"""
TradeManager.precision.__doc__ = """
precision
"""
TradeManager.brokeLastDatetime.__doc__ = """
TradeManager会在执行买入//
TradeManager会在历史时刻就执行买入/
/
/ brokeLastDatetime
"""
TradeManager.getParam.__doc__ = """
getParam(self, name)
:param str name:
:return:
:raises out_of_range:
"""
TradeManager.setParam.__doc__ = """
setParam(self, name, value)
:param str name:
:param value:
:type value: int | bool | float | string
:raises logic_error: Unsupported type!
"""
TradeManager.reset.__doc__ = """
reset(self)
"""
TradeManager.clone.__doc__ = """
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)
getTradeList(self, start, end)
:param Datetime start:
:param Datetime end:
: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:
"""
TradeManager.addTradeRecord.__doc__ = """
addTradeRecord(self, tr)
:param TradeRecord tr:
:return: True | False
:rtype: bool
"""
#------------------------------------------------------------------
# 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__ = """仅用于测试"""