mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 20:08:26 +08:00
继续完善数据驱动内容
This commit is contained in:
parent
98ae2ab3eb
commit
5cca3114cd
@ -38,7 +38,7 @@ PROJECT_NAME = Hikyuu
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.1
|
||||
PROJECT_NUMBER = 1.0.5
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
@ -10,6 +10,21 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const BaseInfoDriver& driver) {
|
||||
os << "BaseInfoDriver(" << driver.name() << ", " << driver.getParameter() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const BaseInfoDriverPtr& driver) {
|
||||
if (driver) {
|
||||
os << *driver;
|
||||
} else {
|
||||
os << "BaseInfoDriver(NULL)";
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
BaseInfoDriver::BaseInfoDriver(const string& name)
|
||||
: m_name(name) {
|
||||
boost::to_upper(m_name);
|
||||
|
@ -46,7 +46,6 @@ public:
|
||||
|
||||
/**
|
||||
* 驱动初始化,具体实现时应注意将之前打开的相关资源关闭。
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
virtual bool _init() = 0;
|
||||
@ -78,6 +77,9 @@ protected:
|
||||
|
||||
typedef shared_ptr<BaseInfoDriver> BaseInfoDriverPtr;
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const BaseInfoDriver&);
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const BaseInfoDriverPtr&);
|
||||
|
||||
|
||||
inline const string& BaseInfoDriver::name() const {
|
||||
return m_name;
|
||||
|
@ -10,6 +10,21 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const BlockInfoDriver& driver) {
|
||||
os << "BlockInfoDriver(" << driver.name() << ", " << driver.getParameter() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const BlockInfoDriverPtr& driver) {
|
||||
if (driver) {
|
||||
os << *driver;
|
||||
} else {
|
||||
os << "BlockInfoDriver(NULL)";
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
BlockInfoDriver::BlockInfoDriver(const string& name)
|
||||
: m_name(name) {
|
||||
boost::to_upper(m_name);
|
||||
|
@ -65,6 +65,10 @@ protected:
|
||||
typedef shared_ptr<BlockInfoDriver> BlockInfoDriverPtr;
|
||||
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const BlockInfoDriver&);
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const BlockInfoDriverPtr&);
|
||||
|
||||
|
||||
inline const string& BlockInfoDriver::name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "base_info/sqlite/SQLiteBaseInfoDriver.h"
|
||||
#include "block_info/qianlong/QLBlockInfoDriver.h"
|
||||
#include "kdata/hdf5/H5KDataDriver.h"
|
||||
#include "DataDriverFactory.h"
|
||||
#include "KDataDriver.h"
|
||||
|
||||
@ -25,9 +26,15 @@ map<string, BlockInfoDriverPtr> default_block_driver() {
|
||||
return result;
|
||||
}
|
||||
|
||||
map<string, KDataDriverPtr> default_kdata_driver() {
|
||||
map<string, KDataDriverPtr> result;
|
||||
result["HDF5"] = make_shared<H5KDataDriver>();
|
||||
return result;
|
||||
}
|
||||
|
||||
map<string, BaseInfoDriverPtr> DataDriverFactory::m_baseInfoDrivers(default_baseinfo_driver());
|
||||
map<string, BlockInfoDriverPtr> DataDriverFactory::m_blockDrivers(default_block_driver());
|
||||
map<string, KDataDriverPtr> DataDriverFactory::m_kdataDrivers;
|
||||
map<string, KDataDriverPtr> DataDriverFactory::m_kdataDrivers(default_kdata_driver());
|
||||
map<Parameter, KDataDriverPtr> DataDriverFactory::m_param_kdataDrivers;
|
||||
|
||||
|
||||
@ -53,21 +60,9 @@ BaseInfoDriverPtr DataDriverFactory
|
||||
BaseInfoDriverPtr result;
|
||||
if (iter != m_baseInfoDrivers.end()) {
|
||||
result = iter->second;
|
||||
} else {
|
||||
HKU_INFO("Can't get the type(" << type
|
||||
<< ") of BaseInfoDriver! "
|
||||
"Will use default sqlite3 BaseInfoDriver! "
|
||||
"[DataDriverFactory::getBaseInfoDriver]");
|
||||
iter = m_baseInfoDrivers.find("SQLITE3");
|
||||
if (iter != m_baseInfoDrivers.end()) {
|
||||
result = m_baseInfoDrivers["SQLITE3"];
|
||||
} else {
|
||||
result = make_shared<SQLiteBaseInfoDriver>();
|
||||
m_baseInfoDrivers["SQLITE3"] = result;
|
||||
}
|
||||
result->init(params);
|
||||
}
|
||||
|
||||
result->init(params);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -91,21 +86,9 @@ BlockInfoDriverPtr DataDriverFactory::getBlockDriver(const Parameter& params) {
|
||||
iter = m_blockDrivers.find(name);
|
||||
if (iter != m_blockDrivers.end()) {
|
||||
result = iter->second;
|
||||
} else {
|
||||
HKU_INFO("Can't get the type(" << name
|
||||
<< ") of BlockInfoDriver! "
|
||||
"Will use default qianlong BaseInfoDriver! "
|
||||
"[DataDriverFactory::getBlockDriver]");
|
||||
iter = m_blockDrivers.find("QIANLONG");
|
||||
if (iter != m_blockDrivers.end()) {
|
||||
result = iter->second;
|
||||
} else {
|
||||
result = make_shared<QLBlockInfoDriver>();
|
||||
m_blockDrivers["QIANLONG"] = result;
|
||||
}
|
||||
result->init(params);
|
||||
}
|
||||
|
||||
result->init(params);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
/**
|
||||
* 数据驱动工厂类
|
||||
* @ingroup DataDriver
|
||||
*/
|
||||
class HKU_API DataDriverFactory {
|
||||
public:
|
||||
//DataDriverFactory();
|
||||
|
@ -10,6 +10,21 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const KDataDriver& driver) {
|
||||
os << "KDataDriver(" << driver.name() << ", " << driver.getParameter() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream& os, const KDataDriverPtr& driver) {
|
||||
if (driver) {
|
||||
os << *driver;
|
||||
} else {
|
||||
os << "KDataDriver(NULL)";
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
KDataDriver::KDataDriver(): m_name("") {
|
||||
|
||||
}
|
||||
|
@ -94,6 +94,9 @@ private:
|
||||
typedef shared_ptr<KDataDriver> KDataDriverPtr;
|
||||
|
||||
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const KDataDriver&);
|
||||
HKU_API std::ostream & operator<<(std::ostream&, const KDataDriverPtr&);
|
||||
|
||||
inline const string& KDataDriver::name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
@ -12,6 +12,17 @@
|
||||
* 该文件仅用于doxygen生成文档
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* @mainpage 测试
|
||||
* Hikyuu Quant Framework是一款基于C++/Python的开源量化交易研究框架,用于策略分析及回测 (目前
|
||||
* 用于国内证券市场)。其核心思想基于当前成熟的系统化交易方法,将整个系统化交易抽象为由市场环境判断策略、
|
||||
* 系统有效条件、信号指示器、止损/止盈策略、资金管理策略、盈利目标策略、移滑价差算法七大组件,你可以分别
|
||||
* 构建这些组件的策略资产库,在实际研究中对它们自由组合来观察系统的有效性、稳定性以及单一种类策略的效果。
|
||||
*
|
||||
* 更多信息,请访问:<a href="http://hikyuu.org">http://hikyuu.org</a>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 核心库,包含股票数据的管理、指标实现、交易系统框架等
|
||||
* @defgroup Hikyuu Hikyuu 核心引擎库
|
||||
@ -32,6 +43,11 @@
|
||||
* @details 证券管理类、证券类等
|
||||
* @ingroup Base
|
||||
*
|
||||
* @defgroup DataDriver Data-Driver 数据驱动引擎
|
||||
* 读取市场信息、证券信息、板块数据、K线数据等
|
||||
* @details 读取市场信息、证券信息、板块数据、K线数据等;可根据需要实现自定义的数据驱动引擎。
|
||||
* @ingroup Base
|
||||
*
|
||||
* @defgroup Common-Utilities Common-Utilities 公共小工具
|
||||
* 独立的一些小函数、对象工具集合
|
||||
* @details 附加的公共工具集
|
||||
|
@ -27,6 +27,7 @@ void export_StockManager(){
|
||||
.def("instance", &StockManager::instance,
|
||||
return_value_policy<reference_existing_object>())
|
||||
.staticmethod("instance")
|
||||
.def("init", &StockManager::init)
|
||||
.def("tmpdir", &StockManager::tmpdir)
|
||||
.def("getAllMarket", &StockManager::getAllMarket)
|
||||
.def("getMarketInfo", &StockManager::getMarketInfo)
|
||||
|
@ -37,6 +37,7 @@ void export_BaseInfoDriver() {
|
||||
|
||||
class_<BaseInfoDriverWrap, boost::noncopyable>("BaseInfoDriver",
|
||||
init<const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", make_function(&BaseInfoDriver::name,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.def("getParam", &BaseInfoDriver::getParam<boost::any>)
|
||||
|
@ -41,6 +41,7 @@ void export_BlockInfoDriver() {
|
||||
|
||||
class_<BlockInfoDriverWrap, boost::noncopyable>("BlockInfoDriver",
|
||||
init<const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", make_function(&BlockInfoDriver::name,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.def("getParam", &BlockInfoDriver::getParam<boost::any>)
|
||||
|
@ -32,7 +32,6 @@ void export_DataDriverFactory() {
|
||||
.staticmethod("removeBlockDriver")
|
||||
;
|
||||
|
||||
register_ptr_to_python<BlockInfoDriverPtr>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,6 +96,7 @@ void export_KDataDriver() {
|
||||
|
||||
class_<KDataDriverWrap, boost::noncopyable>("KDataDriver", init<>())
|
||||
.def(init<const string&>())
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", make_function(&KDataDriver::name,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.def("getParam", &KDataDriver::getParam<boost::any>)
|
||||
|
@ -48,4 +48,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from .data_driver import *
|
||||
from .data_driver import (DataDriverFactory,
|
||||
BaseInfoDriver,
|
||||
BlockInfoDriver,
|
||||
KDataDriver)
|
||||
|
||||
__all__ = ['DataDriverFactory',
|
||||
'BaseInfoDriver',
|
||||
'BlockInfoDriver',
|
||||
'KDataDriver']
|
||||
|
@ -26,8 +26,18 @@
|
||||
|
||||
|
||||
|
||||
from ._data_driver import (DataDriverFactory,BaseInfoDriver,KDataDriver)
|
||||
from ._data_driver import (DataDriverFactory,
|
||||
BaseInfoDriver,
|
||||
BlockInfoDriver,
|
||||
KDataDriver)
|
||||
from hikyuu.util.unicode import (unicodeFunc, reprFunc)
|
||||
|
||||
|
||||
BaseInfoDriver.__unicode__ = unicodeFunc
|
||||
BaseInfoDriver.__repr__ = reprFunc
|
||||
|
||||
BlockInfoDriver.__unicode__ = unicodeFunc
|
||||
BlockInfoDriver.__repr__ = reprFunc
|
||||
|
||||
KDataDriver.__unicode__ = unicodeFunc
|
||||
KDataDriver.__repr__ = reprFunc
|
||||
|
72
tools/hikyuu/data_driver/pytdx_data_driver.py
Normal file
72
tools/hikyuu/data_driver/pytdx_data_driver.py
Normal file
@ -0,0 +1,72 @@
|
||||
#!/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 ._data_driver import KDataDriver
|
||||
from hikyuu import KRecord, Query
|
||||
|
||||
from pytdx.hq import TdxHq_API
|
||||
|
||||
|
||||
class PytdxKDataDriver(KDataDriver):
|
||||
def __init__(self):
|
||||
super(PytdxKDataDriver, self).__init__('pytdx')
|
||||
|
||||
def _init(self):
|
||||
ip = self.getParam('ip')
|
||||
port = self.getParam('port')
|
||||
self._tdx = TdxHq_API(heartbeat=True)
|
||||
return self._tdx.connect(ip, port)
|
||||
|
||||
def loadKData(self, market, code, ktype, start_ix, end_ix, out_buffer):
|
||||
new_market = self._trans_market(market)
|
||||
pass
|
||||
|
||||
def getCount(self, market, code, ktype):
|
||||
return 0
|
||||
|
||||
def getIndexRangeByDate(self, market, code, query, out_start, out_end):
|
||||
pass
|
||||
|
||||
def getKRecord(self, market, code, pos, ktype):
|
||||
return KRecord()
|
||||
|
||||
def _trans_market(self, market):
|
||||
market_map = {'SH': 1, 'SZ': 0}
|
||||
return market_map[market.upper()]
|
||||
|
||||
def _trans_ktype(self, ktype):
|
||||
ktype_map = {Query.MIN5: 0,
|
||||
Query.MIN15: 1,
|
||||
Query.MIN30: 2,
|
||||
Query.MIN60: 3,
|
||||
Query.DAY: 9,
|
||||
Query.WEEK: 5,
|
||||
Query.MONTH: 6,
|
||||
Query.MIN: 8,
|
||||
Query.QUARTER: 10,
|
||||
Query.YEAR: 11}
|
||||
return ktype_map[ktype]
|
@ -78,10 +78,41 @@ else:
|
||||
|
||||
#starttime = time.time()
|
||||
#print "Loading Day Data ..."
|
||||
hikyuu_init(config_file)
|
||||
sm = StockManager.instance()
|
||||
#hikyuu_init(config_file)
|
||||
#sm = StockManager.instance()
|
||||
#endtime = time.time()
|
||||
#print "%.2fs" % (endtime-starttime)
|
||||
import configparser
|
||||
ini = configparser.ConfigParser()
|
||||
ini.read(config_file)
|
||||
hku_param = Parameter()
|
||||
hku_param.set("tmpdir", ini.get('hikyuu', 'tmpdir'))
|
||||
if ini.has_option('hikyuu', 'logger'):
|
||||
hku_param.set("logger", ini['hikyuu']['logger'])
|
||||
|
||||
base_param = Parameter()
|
||||
base_info_config = ini.options('baseinfo')
|
||||
for p in base_info_config:
|
||||
base_param.set(p, ini.get('baseinfo', p))
|
||||
|
||||
block_param = Parameter()
|
||||
block_config = ini.options('block')
|
||||
for p in block_config:
|
||||
block_param.set(p, ini.get('block', p))
|
||||
|
||||
preload_param = Parameter()
|
||||
preload_config = ini.options('preload')
|
||||
for p in preload_config:
|
||||
#注意:proload参数是布尔类型
|
||||
preload_param.set(p, ini.getboolean('preload', p))
|
||||
|
||||
kdata_param = Parameter()
|
||||
kdata_config = ini.options('kdata')
|
||||
for p in kdata_config:
|
||||
kdata_param.set(p, ini.get('kdata', p))
|
||||
|
||||
sm = StockManager.instance()
|
||||
sm.init(base_param, block_param, kdata_param, preload_param, hku_param)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user