This commit is contained in:
fasiondog 2016-04-08 13:02:08 +08:00
parent 0ce5103078
commit 58633c6a67
18 changed files with 81 additions and 86 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
.metadata
.settings
/build
/tools/hikyuu/docs/build
/docs/docs-web/build
/docs/reference
/docs/test-doc

View File

@ -41,9 +41,6 @@ IndicatorImp::IndicatorImp(const string& name, size_t result_num)
: m_name(name), m_discard(0) {
memset(m_pBuffer, NULL, sizeof(PriceList*) * MAX_RESULT_NUM);
m_result_num = result_num < MAX_RESULT_NUM ? result_num : MAX_RESULT_NUM;
for (size_t i = 0; i < m_result_num; ++i) {
m_pBuffer[i] = new PriceList();
}
}
void IndicatorImp::_readyBuffer(size_t len, size_t result_num) {
@ -55,34 +52,23 @@ void IndicatorImp::_readyBuffer(size_t len, size_t result_num) {
price_t null_price = Null<price_t>();
if (m_result_num <= result_num) {
for (size_t i = 0; i < m_result_num; ++i) {
m_pBuffer[i]->clear();
m_pBuffer[i]->reserve(len);
for (size_t j = 0; j < len; ++j) {
m_pBuffer[i]->push_back(null_price);
}
}
for (size_t i = m_result_num; i < result_num; ++i) {
for (size_t i = 0; i < result_num; ++i) {
if (!m_pBuffer[i]) {
m_pBuffer[i] = new PriceList(len, null_price);
}
} else {
//if (m_result_num > result_num)
for (size_t i = 0; i < result_num; ++i) {
m_pBuffer[i]->clear();
m_pBuffer[i]->reserve(len);
for (size_t j = 0; j < len; ++j) {
m_pBuffer[i]->push_back(null_price);
}
}
}
for (size_t i = result_num; i < m_result_num; ++i) {
delete m_pBuffer[i];
m_pBuffer[i] = NULL;
}
}
m_result_num = result_num;
}

View File

@ -124,7 +124,15 @@ private:
ar & BOOST_SERIALIZATION_NVP(m_params);
ar & BOOST_SERIALIZATION_NVP(m_discard);
ar & BOOST_SERIALIZATION_NVP(m_result_num);
for (size_t i = 0; i < m_result_num; ++i) {
int act_result_num = 0;
size_t i = 0;
while (i < m_result_num) {
if (m_pBuffer[i++])
act_result_num++;
}
ar & BOOST_SERIALIZATION_NVP(act_result_num);
for (size_t i = 0; i < act_result_num; ++i) {
std::stringstream buf;
buf << "result_" << i;
ar & bs::make_nvp<PriceList>(buf.str().c_str(), *m_pBuffer[i]);
@ -138,7 +146,9 @@ private:
ar & BOOST_SERIALIZATION_NVP(m_params);
ar & BOOST_SERIALIZATION_NVP(m_discard);
ar & BOOST_SERIALIZATION_NVP(m_result_num);
for (size_t i = 0; i < m_result_num; ++i) {
int act_result_num = 0;
ar & BOOST_SERIALIZATION_NVP(act_result_num);
for (size_t i = 0; i < act_result_num; ++i) {
m_pBuffer[i] = new PriceList();
std::stringstream buf;
buf << "result_" << i;

View File

@ -43,7 +43,7 @@ void Ema::_calculate(const Indicator& indicator) {
price_t multiplier = 2.0 / (n + 1);
for (size_t i = startPos + 1; i < total; ++i) {
ema = indicator[i] * multiplier + ema - ema * multiplier;
ema = (indicator[i] - ema) * multiplier + ema;
_set(ema, i);
}
}

View File

@ -56,8 +56,8 @@ void Macd::_calculate(const Indicator& data) {
_set(dea, 0, 2);
for (size_t i = 1; i < total; ++i) {
ema1 = data[i] * m1 + ema1 - ema1 * m1;
ema2 = data[i] * m2 + ema2 - ema2 * m2;
ema1 = (data[i] - ema1) * m1 + ema1;
ema2 = (data[i] - ema2) * m2 + ema2;
diff = ema1 - ema2;
dea = diff * m3 + dea - dea * m3;
bar = diff - dea;

View File

@ -90,6 +90,9 @@ public:
/** 获取交易算法指针 */
TradeCostPtr costFunc() const { return m_costfunc; }
/** 设置交易算法指针 */
void costFunc(const TradeCostPtr& func) { m_costfunc = func; }
/**
*
* @note

View File

@ -8,7 +8,7 @@
#ifndef TRADE_SYS_SIGNAL_CRT_SINGLE_SG_H_
#define TRADE_SYS_SIGNAL_CRT_SINGLE_SG_H_
#include "../../../indicator/Indicator.h"
#include "../../../indicator/Operand.h"
#include "../SignalBase.h"
namespace hku {
@ -22,7 +22,7 @@ namespace hku {
* @return
* @ingroup Signal
*/
SignalPtr HKU_API Single_SG(const Indicator& ind,
SignalPtr HKU_API Single_SG(const Operand& ind,
int filter_n = 20, double filter_p = 0.1,
const string& kpart = "CLOSE");

View File

@ -18,7 +18,7 @@ SingleSignal::SingleSignal(): SignalBase("SINGLE") {
setParam<string>("kpart", "CLOSE");
}
SingleSignal::SingleSignal(const Indicator& ind)
SingleSignal::SingleSignal(const Operand& ind)
: SignalBase("SINGLE"), m_ind(ind) {
setParam<int>("filter_n", 20);
setParam<double>("filter_p", 0.1);
@ -62,7 +62,7 @@ void SingleSignal::_calculate() {
}
}
SignalPtr HKU_API Single_SG(const Indicator& ind,
SignalPtr HKU_API Single_SG(const Operand& ind,
int filter_n, double filter_p, const string& kpart) {
SingleSignal *p = new SingleSignal(ind);
p->setParam<int>("filter_n", filter_n);

View File

@ -8,7 +8,7 @@
#ifndef TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
#define TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
#include "../../../indicator/Indicator.h"
#include "../../../indicator/Operand.h"
#include "../SignalBase.h"
namespace hku {
@ -16,14 +16,14 @@ namespace hku {
class SingleSignal: public SignalBase {
public:
SingleSignal();
SingleSignal(const Indicator& ind);
SingleSignal(const Operand& ind);
virtual ~SingleSignal();
virtual SignalPtr _clone();
virtual void _calculate();
private:
Indicator m_ind;
Operand m_ind;
//============================================
// 序列化支持

View File

@ -24,7 +24,9 @@ void export_KData() {
.def("getDatetimeList", &KData::getDatetimeList)
.def("getKRecord", &KData::getKRecord)
.def("get", &KData::getKRecord)
.def("getKRecordByDate", &KData::getKRecordByDate)
.def("getByDate", &KData::getKRecordByDate)
.def("_getPos", &KData::getPos) //python中需要将Null的情况改写为None
.def("size", &KData::size)

View File

@ -13,23 +13,6 @@
using namespace boost::python;
using namespace hku;
TradeManagerPtr (*crtTM1)(const Datetime&, price_t, const TradeCostPtr&, const string&) = crtTM;
BOOST_PYTHON_FUNCTION_OVERLOADS(crtTM1_overloads, crtTM, 0, 4);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(cash_overload, cash, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFundsCurve_overload, getFundsCurve, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getProfitCurve_overload, getProfitCurve, 1, 2);
FundsRecord (TradeManager::*getFunds_1)(KQuery::KType) const = &TradeManager::getFunds;
FundsRecord (TradeManager::*getFunds_2)(const Datetime&, KQuery::KType) = &TradeManager::getFunds;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFunds_1_overload, TradeManager::getFunds, 0, 1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFunds_2_overload, TradeManager::getFunds, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(buy_overload, buy, 4, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sell_overload, sell, 3, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(buyShort_overload, buyShort, 3, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sellShort_overload, sellShort, 4, 8);
#if HKU_PYTHON_SUPPORT_PICKLE
struct TradeManager_pickle_suite : bp::pickle_suite {
static
@ -59,6 +42,27 @@ struct TradeManager_pickle_suite : bp::pickle_suite {
#endif /* HKU_PYTHON_SUPPORT_PICKLE */
TradeManagerPtr (*crtTM1)(const Datetime&, price_t, const TradeCostPtr&, const string&) = crtTM;
BOOST_PYTHON_FUNCTION_OVERLOADS(crtTM1_overloads, crtTM, 0, 4);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(cash_overload, cash, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFundsCurve_overload, getFundsCurve, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getProfitCurve_overload, getProfitCurve, 1, 2);
FundsRecord (TradeManager::*getFunds_1)(KQuery::KType) const = &TradeManager::getFunds;
FundsRecord (TradeManager::*getFunds_2)(const Datetime&, KQuery::KType) = &TradeManager::getFunds;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFunds_1_overload, TradeManager::getFunds, 0, 1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getFunds_2_overload, TradeManager::getFunds, 1, 2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(buy_overload, buy, 4, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sell_overload, sell, 3, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(buyShort_overload, buyShort, 3, 8);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sellShort_overload, sellShort, 4, 8);
TradeCostPtr (TradeManager::*get_costFunc)() const = &TradeManager::costFunc;
void (TradeManager::*set_costFunc)(const TradeCostPtr&) = &TradeManager::costFunc;
void export_TradeManager() {
class_<TradeManager>("TradeManager", init<const Datetime&, price_t,
@ -76,7 +80,7 @@ void export_TradeManager() {
.add_property("lastDatetime", &TradeManager::lastDatetime)
.add_property("reinvest", &TradeManager::reinvest)
.add_property("precision", &TradeManager::precision)
.add_property("costFunc", &TradeManager::costFunc)
.add_property("costFunc", get_costFunc, set_costFunc)
.def("getParam", &TradeManager::getParam<boost::any>)
.def("setParam", &TradeManager::setParam<object>)

View File

@ -49,7 +49,6 @@ void export_Signal() {
.def(init<const string&>())
.def(self_ns::str(self))
.add_property("name", get_name, set_name)
.add_property("kdata", &SignalBase::getTO)
//因为Indicator无法使用params['name']的形式所以统一使用setParm/getParam
//.add_property("params",
// make_function(&SignalBase::getParameter,

View File

@ -72,8 +72,8 @@
<File name="tools\hikyuu\docs\source\user\signal.rst" />
</Folder>
<File name="tools\hikyuu\docs\source\conf.py" />
<File name="tools\hikyuu\docs\source\developer_guide.rst" />
<File name="tools\hikyuu\docs\source\index.rst" />
<File name="tools\hikyuu\docs\source\developer_guide.rst" />
<File name="tools\hikyuu\docs\source\user_guide.rst" />
</Project>
</NotepadPlus>

View File

@ -192,7 +192,7 @@ html_static_path = ['_static']
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
#html_search_language = 'en'
html_search_language = 'zh'
# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value

View File

@ -50,22 +50,3 @@
::
> xelatex -interaction=nonstopmode Hikyuu.tex
如何去除
d:\workspace\fasiondog\trunk\libs\galaxy\galaxy\tradesys\cost\../TradeCostBase.h : warning C4819: 该文件包含
不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
rule configure-version-specific ( toolset : version : conditions )
{
toolset.push-checking-for-flags-module unchecked ;
# Starting with versions 7.0, the msvc compiler have the /Zc:forScope and
# /Zc:wchar_t options that improve C++ standard conformance, but those
# options are off by default. If we are sure that the msvc version is at
# 7.*, add those options explicitly. We can be sure either if user specified
# version 7.* explicitly or if we auto-detected the version ourselves.
if ! [ MATCH ^(6\\.) : $(version) ]
{
toolset.flags $(toolset).compile CFLAGS $(conditions) : /Zc:forScope /Zc:wchar_t ;
toolset.flags $(toolset).compile.c++ C++FLAGS $(conditions) : /wd4675 ;
toolset.flags $(toolset).compile.c++ C++FLAGS $(conditions) : /wd4819 ;
b2 -j 4 release link=shared address-model=64

View File

@ -12,10 +12,10 @@ Welcome to Hikyuu's documentation!
user_guide
developer_guide
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -5,7 +5,8 @@
信号指示器
==========
信号指示器模块,包括各种信号指示器构造函数。信号指示器负责产生买入、卖出信号。
信号指示器负责产生买入、卖出信号。
通用信号指示器
--------------
@ -31,12 +32,20 @@
自定义信号指示器
----------------
自定义信号指示器,必须实现 :py:meth:`SignalBase._clone`:py:meth:`SignalBase_calculate` 方法如示例1。如果含有私有属性还需实现 :py:meth:`SignalBase._reset` 方法如示例2
示例1不含私有变量海龟交易策略:
.. literalinclude:: ../../../examples/Turtle_SG.py
示例2含私有属性:
::
class SignalPython(SignalBase):
def __init__(self):
super(SignalPython, self).__init__("SignalPython")
self._x = 0
self._x = 0 #私有属性
self.setParam("test", 30)
def _reset(self):
@ -55,9 +64,9 @@
信号指示器基类
--------------
自定义的信号指示器应实现_clone, _reset, _calculate接口。
自定义的信号指示器,应实现 :py:meth:`SignalBase._clone`, :py:meth:`SignalBase._reset`, :py:meth:`SignalBase._calculate` 接口。
.. py:class:: SignalBase
.. py:class:: SignalBase([name])
信号指示器基类
@ -86,7 +95,7 @@
:param KData k: 设置交易对象
.. py:method:: getTO
.. py:method:: getTO()
:return: 交易对象
:rtype: KData

View File

@ -4,7 +4,7 @@
#===============================================================================
# Aothor: fasiondog
# History: 20130128, Added by fasiondog
# History: 20160407, Added by fasiondog
#===============================================================================
from hikyuu.trade_sys.signal import SignalBase
@ -22,8 +22,8 @@ class TurtleSignal(SignalBase):
n = self.getParam("n")
k = self.getTO()
c = CLOSE(k)
h = REF(HHV(c, n), 1)
L = REF(LLV(c, n), 1)
h = REF(HHV(c, n), 1) #前n日高点
L = REF(LLV(c, n), 1) #前n日低点
for i in range(h.discard, len(k)):
if (c[i] >= h[i]):
self._addBuySignal(k[i].datetime)
@ -40,6 +40,6 @@ if __name__ == "__main__":
dates = k.getDatetimeList()
for d in dates:
if (sg.shouldBuy(d)):
print("买入:%s" % str(d))
print("买入:%s" % d)
elif (sg.shouldSell(d)):
print("卖出: %s" % str(d))
print("卖出: %s" % d)