继续完善数据驱动内容

This commit is contained in:
fasiondog 2017-10-20 02:11:57 +08:00 committed by wingc
parent 98ae2ab3eb
commit 5cca3114cd
19 changed files with 215 additions and 34 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -14,6 +14,10 @@
namespace hku {
/**
*
* @ingroup DataDriver
*/
class HKU_API DataDriverFactory {
public:
//DataDriverFactory();

View File

@ -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("") {
}

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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>)

View File

@ -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>)

View File

@ -32,7 +32,6 @@ void export_DataDriverFactory() {
.staticmethod("removeBlockDriver")
;
register_ptr_to_python<BlockInfoDriverPtr>();
}

View File

@ -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>)

View File

@ -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']

View File

@ -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

View 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]

View File

@ -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)
#==============================================================================