mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
完善Python帮助信息
This commit is contained in:
parent
6443c8f9c3
commit
9985ff25a8
@ -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&>())
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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>())
|
||||
|
@ -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))
|
||||
|
@ -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>())
|
||||
;
|
||||
}
|
||||
|
@ -54,5 +54,4 @@ def getVersion():
|
||||
return __version__
|
||||
|
||||
from .core import *
|
||||
from .core_doc import *
|
||||
|
||||
|
@ -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
|
||||
|
@ -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线数据)增加临时的Stock,可用于只有CSV格式的K线数据时,进行临时测试。
|
||||
|
||||
CSV文件第一行为标题,需含有 Datetime(或Date、日期)、OPEN(或开盘价)、HIGH(或最高价)、LOW(或最低价)、CLOSE(或收盘价)、AMOUNT(或成交金额)、VOLUME(或VOL、COUNT、成交量)。
|
||||
|
||||
: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)
|
||||
|
||||
同 getKRecord。获取指定索引位置的K线记录
|
||||
|
||||
: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
|
||||
#------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user