完善Python帮助信息

This commit is contained in:
fasiondog 2017-09-28 01:59:12 +08:00
parent 6443c8f9c3
commit 9985ff25a8
8 changed files with 432 additions and 13 deletions

View File

@ -13,6 +13,8 @@ using namespace boost::python;
using namespace hku;
void export_KData() {
docstring_options doc_options(false);
class_<KData>("KData", init<>())
.def(init<const KData&>())
.def(init<const Stock&, const KQuery&>())

View File

@ -16,6 +16,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(KQueryByDate_overload, KQueryByDate, 0, 4);
BOOST_PYTHON_FUNCTION_OVERLOADS(KQueryByIndex_overload, KQueryByIndex, 0, 4);
void export_KQuery() {
docstring_options doc_options(false);
def("KQueryByDate", KQueryByDate, KQueryByDate_overload());
def("KQueryByIndex", KQueryByIndex, KQueryByIndex_overload());

View File

@ -15,6 +15,8 @@ using namespace hku;
bool (*krecord_eq)(const KRecord&, const KRecord&) = operator==;
void export_KReord() {
docstring_options doc_options(false);
class_<KRecord>("KRecord", init<>())
.def(init<const Datetime&>())
.def(init<const Datetime&, price_t, price_t, price_t, price_t, price_t, price_t>())

View File

@ -26,6 +26,8 @@ DatetimeList (Stock::*getDatetimeList2)(const KQuery&) const = &Stock::getDateti
void export_Stock() {
docstring_options doc_options(false);
class_<Stock>("Stock", init<>())
.def(init<const string&, const string&, const string&>())
//.def(self_ns::str(self))

View File

@ -21,11 +21,14 @@ BlockList (StockManager::*getBlockList_1)(const string&) = &StockManager::getBlo
BlockList (StockManager::*getBlockList_2)() = &StockManager::getBlockList;
void export_StockManager(){
docstring_options doc_options(false);
class_<StockManager>("StockManager", no_init)
.def("instance", &StockManager::instance,
return_value_policy<reference_existing_object>())
.staticmethod("instance")
.def("tmpdir", &StockManager::tmpdir)
.def("getAllMarket", &StockManager::getAllMarket)
.def("getMarketInfo", &StockManager::getMarketInfo)
.def("getStockTypeInfo", &StockManager::getStockTypeInfo)
.def("size", &StockManager::size)
@ -33,18 +36,16 @@ void export_StockManager(){
.def("getBlock", &StockManager::getBlock)
.def("getBlockList", getBlockList_1)
.def("getBlockList", getBlockList_2)
.def("getTradingCalendar", &StockManager::getTradingCalendar,
getTradingCalendar_overloads())
//.def("getTradingCalendar", &StockManager::getTradingCalendar,
// (arg("market")="SH", arg("start")=Datetime::min(),
// arg=("end")=Datetime::max()))
// getTradingCalendar_overloads())
.def("getTradingCalendar", &StockManager::getTradingCalendar,
(arg("query"), arg("market")="SH"))
.def("addTempCsvStock", &StockManager::addTempCsvStock,
addTempCsvStock_overloads())
.def("removeTempCsvStock", &StockManager::removeTempCsvStock)
.def("__len__", &StockManager::size)
.def("__getitem__", &StockManager::getStock)
//.def("__iter__", iterator<StockManager>())
.def("__iter__", iterator<const StockManager>())
;
}

View File

@ -54,5 +54,4 @@ def getVersion():
return __version__
from .core import *
from .core_doc import *

View File

@ -31,7 +31,7 @@ if sys.version > '3':
else:
IS_PY3 = False
from ._hikyuu import *
from .core_doc import *
from hikyuu.util.mylog import escapetime
from hikyuu.util.slice import list_getitem
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
@ -149,6 +149,7 @@ Datetime.isNull = Datetime_isNull
#------------------------------------------------------------------
#重定义KQuery
#------------------------------------------------------------------
class Query(KQuery):
"""重新定义KQuery目的如下
1使
@ -227,8 +228,11 @@ KQuery.BACKWARD = KQuery.RecoverType.BACKWARD
KQuery.EQUAL_FORWARD = KQuery.RecoverType.EQUAL_FORWARD
KQuery.EQUAL_BACKWARD = KQuery.RecoverType.EQUAL_BACKWARD
#================================================================
#封装KData
#------------------------------------------------------------------
# 增强 KData 的遍历
#------------------------------------------------------------------
def KData_getitem(kdata, i):
if isinstance(i, int):
length = len(kdata)
@ -252,6 +256,12 @@ def KData_iter(kdata):
yield kdata[i]
def KData_getPos(kdata, datetime):
"""
:param Datetime datetime:
:return: None
"""
pos = kdata._getPos(datetime)
return pos if pos != constant.null_size else None
@ -261,7 +271,9 @@ KData.__iter__ = KData_iter
KData.getPos = KData_getPos
#================================================================
#------------------------------------------------------------------
# 封装增强其他C++ vector类型的遍历
#------------------------------------------------------------------
PriceList.__getitem__ = list_getitem
DatetimeList.__getitem__ = list_getitem
@ -269,7 +281,10 @@ StringList.__getitem__ = list_getitem
BlockList.__getitem__ = list_getitem
#================================================================
#------------------------------------------------------------------
# 增加转化为 np.array、pandas.DataFrame 的功能
#------------------------------------------------------------------
try:
import numpy as np
import pandas as pd

View File

@ -25,7 +25,7 @@
# SOFTWARE.
from .core import *
from hikyuu._hikyuu import *
#------------------------------------------------------------------
@ -59,7 +59,6 @@ Datetime.__doc__ = """日期时间类,精确到秒"""
Datetime.max.__doc__ += """
"""
Datetime.min.__doc__ += """
"""
@ -157,3 +156,400 @@ StockWeightList.__doc__ = """std::vector<StockWeight> 包装"""
#------------------------------------------------------------------
# from _StockManager.cpp
#------------------------------------------------------------------
StockManager.__doc__ = """证券信息管理类"""
StockManager.instance.__doc__ = """
instance()
StockManager单例实例
"""
StockManager.tmpdir.__doc__ = """
tmpdir()
m_config中的tmpdir
"""
StockManager.getAllMarket.__doc__ = """
getAllMarket()
:rtype: StringList
"""
StockManager.getMarketInfo.__doc__ = """
getMarketInfo(market)
:param string market:
:return: Null<MarketInfo>()
:rtype: MarketInfo
"""
StockManager.getStockTypeInfo.__doc__ = """
getStockTypeInfo(stk_type)
:param int stk_type: :py:data:`constant`
:return: Null<StockTypeInfo>()
:rtype: StockTypeInfo
"""
StockManager.size.__doc__ = """\n
size()
"""
StockManager.__len__.__doc__ = """\n
"""
StockManager.getStock.__doc__ = """
getStock(querystr)
"市场简称证券代码"
:param str querystr: "sh000001"
:return: Null<Stock>()
:rtype: Stock
"""
StockManager.__getitem__.__doc__ = """
getStock
"""
StockManager.getBlock.__doc__ = """
getBlock(category, name)
:param str category:
:param str name:
:return: Block
:rtype: Block
"""
StockManager.getBlockList.__doc__ = """
getBlockList([category])
:param str category:
:return:
:rtype: BlockList
"""
StockManager.getTradingCalendar.__doc__ = """
getTradingCalendar(query[, market='SH'])
:param KQuery query: Query查询条件
:param str market:
:return:
:rtype: DatetimeList
"""
StockManager.addTempCsvStock.__doc__ = """
addTempCsvStock(code, day_filename, min_filename[, tick=0.01, tickValue=0.01, precision=2, minTradeNumber = 1, maxTradeNumber=1000000])
CSV文件K线数据StockCSV格式的K线数据时
CSV文件第一行为标题 DatetimeDateOPENHIGHLOWCLOSEAMOUNTVOLUMEVOLCOUNT
:param str code: Stock相同Null<Stock>
:param str day_filename: 线CSV文件名
:param str min_filename: 线CSV文件名
:param float tick: 0.01
:param float tickValue: 0.01
:param int precision: 2
:param int minTradeNumber: 1
:param int maxTradeNumber: 1000000
:return: Stock
:rtype: Stock
"""
StockManager.removeTempCsvStock.__doc__ = """
removeTempCsvStock(code)
Stock
:param str code:
"""
#------------------------------------------------------------------
# from _KQuery.cpp
#------------------------------------------------------------------
KQueryByDate.__doc__ = """
KQueryByDate(start, end, kType, recoverType)
[start, end) K线数据条件
:param Datetime start:
:param Datetime end:
:param KQuery.KType kType: K线数据类型线线
:param KQuery.RecoverType recoverType:
:return:
:rtype: KQuery
"""
KQueryByIndex.__doc__ = """
KQueryByIndex(start, end, kType, recoverType)
[start, end) K线数据条件使 Query
:param ind start:
:param ind end:
:param KQuery.KType kType: K线数据类型线线
:param KQuery.RecoverType recoverType:
:return:
:rtype: KQuery
"""
KQuery.__doc__ = """K线数据查询条件一般在Python中使用 Query 即可,不用指明 KQuery"""
KQuery.getQueryTypeName.__doc__ = """
getQueryTypeName(queryType)
queryType名称
:param KQuery.QueryType queryType:
:rtype: str
"""
KQuery.getKTypeName.__doc__ = """
getKTypeName(kType)
KType名称
:param KQuery.KType kType: K线类型
:rtype: str
"""
KQuery.getRecoverTypeName.__doc__ = """
getRecoverTypeName(recoverType)
recoverType名称
:param KQuery.RecoverType recoverType:
:rtype: str
"""
KQuery.getQueryTypeEnum.__doc__ = """
getQueryTypeEnum(queryType)
queryType枚举值
:param str queryType: DATE
:rtype: KQuery.QueryType
"""
KQuery.getKTypeEnum.__doc__ = """
getKTypeEnum(ktype)
:param str ktype: DAY
:rtype: KQuery.KType
"""
KQuery.getRecoverTypeEnum.__doc__ = """
getRecoverTypeEnum(recoverType)
:param str recoverType: NO_RECOVER
:rtype: KQuery.RecoverType
"""
KQuery.QueryType.__doc__ = """
- DATE -
- INDEX -
"""
KQuery.KType.__doc__ = """
K线类型枚举定义
- DAY - 线
- WEEK - 线
- MONTH - 线
- QUARTER - 线
- HALFYEAR - 线
- YEAR - 线
- MIN - 1线
- MIN5 - 5线
- MIN15 - 15线
- MIN30 - 30线
- MIN60 - 60线
"""
KQuery.RecoverType.__doc__ = """
K线复权类别枚举定义
- NO_RECOVER -
- FORWARD -
- BACKWARD -
- EQUAL_FORWARD -
- EQUAL_BACKWARD -
"""
KQuery.start.__doc__ = """
constant.null_int64
"""
KQuery.end.__doc__ = """
constant.null_int64
"""
KQuery.startDatetime.__doc__ = """
constant.null_datetime
"""
KQuery.endDatetime.__doc__ = """
constant.null_datetime
"""
KQuery.queryType.__doc__ = """
"""
KQuery.kType.__doc__ = """
K线类型
"""
KQuery.recoverType.__doc__ = """
"""
#------------------------------------------------------------------
# from _KRecord.cpp
#------------------------------------------------------------------
KRecord.__doc__ = """K线记录组成K线数据属性可读写"""
KRecord.datetime.__doc__ = """日期时间"""
KRecord.openPrice.__doc__ = """开盘价"""
KRecord.highPrice.__doc__ = """最高价"""
KRecord.lowPrice.__doc__ = """最低价"""
KRecord.closePrice.__doc__ = """收盘价"""
KRecord.transAmount.__doc__ = """成交金额"""
KRecord.transCount.__doc__ = """成交量"""
KRecordList.__doc__ = """C++ std::vector<KRecord>包装"""
#------------------------------------------------------------------
# from _KData.cpp
#------------------------------------------------------------------
KData.__doc__ = """
Stock.getKData K线数据 KRecord list
"""
KData.startPos.__doc__ = """
K线记录中对应的起始位置KData为空返回0
"""
KData.endPos.__doc__ = """
K线记录中对应范围的下一条记录的位置0,lastPos + 1
"""
KData.lastPos.__doc__ = """
K线记录中对应的最后一条记录的位置0,endPos - 1
"""
KData.getDatetimeList.__doc__ = """
getDatetimeList()
:rtype: DatetimeList
"""
KData.getKRecord.__doc__ = """
getKRecord(pos)
K线记录
:param int pos:
:rtype: KRecord
"""
KData.get.__doc__ = """
get(pos)
getKRecordK线记录
:param int pos:
:rtype: KRecord
"""
KData.getKRecordByDate.__doc__ = """
getKRecordByDate(datetime)
K线记录
:param Datetime datetime:
:rtype: KRecord
"""
KData.getByDate.__doc__ = """
getByDate(datetime)
K线记录 getKRecordByDate
:param Datetime datetime:
:rtype: KRecord
"""
KData.size.__doc__ = """
size()
K线记录数量 __len__
"""
KData.empty.__doc__ = """
empty()
:rtype: bool
"""
KData.getQuery.__doc__ = """
getQuery()
:rtype: KQuery
"""
KData.getStock.__doc__ = """
getStock()
Stock
:rtype: Stock
"""
KData.tocsv.__doc__ = """
tocsv(filename)
CSV文件
:param str filename:
"""
#------------------------------------------------------------------
# from _Stock.cpp
#------------------------------------------------------------------