mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 20:08:26 +08:00
update
This commit is contained in:
parent
0ce5103078
commit
58633c6a67
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@
|
|||||||
.metadata
|
.metadata
|
||||||
.settings
|
.settings
|
||||||
/build
|
/build
|
||||||
|
/tools/hikyuu/docs/build
|
||||||
/docs/docs-web/build
|
/docs/docs-web/build
|
||||||
/docs/reference
|
/docs/reference
|
||||||
/docs/test-doc
|
/docs/test-doc
|
||||||
|
@ -41,9 +41,6 @@ IndicatorImp::IndicatorImp(const string& name, size_t result_num)
|
|||||||
: m_name(name), m_discard(0) {
|
: m_name(name), m_discard(0) {
|
||||||
memset(m_pBuffer, NULL, sizeof(PriceList*) * MAX_RESULT_NUM);
|
memset(m_pBuffer, NULL, sizeof(PriceList*) * MAX_RESULT_NUM);
|
||||||
m_result_num = result_num < MAX_RESULT_NUM ? result_num : 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) {
|
void IndicatorImp::_readyBuffer(size_t len, size_t result_num) {
|
||||||
@ -55,33 +52,22 @@ void IndicatorImp::_readyBuffer(size_t len, size_t result_num) {
|
|||||||
|
|
||||||
price_t null_price = Null<price_t>();
|
price_t null_price = Null<price_t>();
|
||||||
|
|
||||||
if (m_result_num <= result_num) {
|
for (size_t i = 0; i < result_num; ++i) {
|
||||||
for (size_t i = 0; i < m_result_num; ++i) {
|
if (!m_pBuffer[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) {
|
|
||||||
m_pBuffer[i] = new PriceList(len, null_price);
|
m_pBuffer[i] = new PriceList(len, null_price);
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//if (m_result_num > result_num)
|
|
||||||
for (size_t i = 0; i < result_num; ++i) {
|
|
||||||
m_pBuffer[i]->clear();
|
m_pBuffer[i]->clear();
|
||||||
m_pBuffer[i]->reserve(len);
|
m_pBuffer[i]->reserve(len);
|
||||||
for (size_t j = 0; j < len; ++j) {
|
for (size_t j = 0; j < len; ++j) {
|
||||||
m_pBuffer[i]->push_back(null_price);
|
m_pBuffer[i]->push_back(null_price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = result_num; i < m_result_num; ++i) {
|
for (size_t i = result_num; i < m_result_num; ++i) {
|
||||||
delete m_pBuffer[i];
|
delete m_pBuffer[i];
|
||||||
m_pBuffer[i] = NULL;
|
m_pBuffer[i] = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_result_num = result_num;
|
m_result_num = result_num;
|
||||||
|
@ -124,7 +124,15 @@ private:
|
|||||||
ar & BOOST_SERIALIZATION_NVP(m_params);
|
ar & BOOST_SERIALIZATION_NVP(m_params);
|
||||||
ar & BOOST_SERIALIZATION_NVP(m_discard);
|
ar & BOOST_SERIALIZATION_NVP(m_discard);
|
||||||
ar & BOOST_SERIALIZATION_NVP(m_result_num);
|
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;
|
std::stringstream buf;
|
||||||
buf << "result_" << i;
|
buf << "result_" << i;
|
||||||
ar & bs::make_nvp<PriceList>(buf.str().c_str(), *m_pBuffer[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_params);
|
||||||
ar & BOOST_SERIALIZATION_NVP(m_discard);
|
ar & BOOST_SERIALIZATION_NVP(m_discard);
|
||||||
ar & BOOST_SERIALIZATION_NVP(m_result_num);
|
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();
|
m_pBuffer[i] = new PriceList();
|
||||||
std::stringstream buf;
|
std::stringstream buf;
|
||||||
buf << "result_" << i;
|
buf << "result_" << i;
|
||||||
|
@ -43,7 +43,7 @@ void Ema::_calculate(const Indicator& indicator) {
|
|||||||
|
|
||||||
price_t multiplier = 2.0 / (n + 1);
|
price_t multiplier = 2.0 / (n + 1);
|
||||||
for (size_t i = startPos + 1; i < total; ++i) {
|
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);
|
_set(ema, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ void Macd::_calculate(const Indicator& data) {
|
|||||||
_set(dea, 0, 2);
|
_set(dea, 0, 2);
|
||||||
|
|
||||||
for (size_t i = 1; i < total; ++i) {
|
for (size_t i = 1; i < total; ++i) {
|
||||||
ema1 = data[i] * m1 + ema1 - ema1 * m1;
|
ema1 = (data[i] - ema1) * m1 + ema1;
|
||||||
ema2 = data[i] * m2 + ema2 - ema2 * m2;
|
ema2 = (data[i] - ema2) * m2 + ema2;
|
||||||
diff = ema1 - ema2;
|
diff = ema1 - ema2;
|
||||||
dea = diff * m3 + dea - dea * m3;
|
dea = diff * m3 + dea - dea * m3;
|
||||||
bar = diff - dea;
|
bar = diff - dea;
|
||||||
|
@ -90,6 +90,9 @@ public:
|
|||||||
/** 获取交易算法指针 */
|
/** 获取交易算法指针 */
|
||||||
TradeCostPtr costFunc() const { return m_costfunc; }
|
TradeCostPtr costFunc() const { return m_costfunc; }
|
||||||
|
|
||||||
|
/** 设置交易算法指针 */
|
||||||
|
void costFunc(const TradeCostPtr& func) { m_costfunc = func; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回当前现金
|
* 返回当前现金
|
||||||
* @note 仅返回当前信息,不会根据权息进行调整
|
* @note 仅返回当前信息,不会根据权息进行调整
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#ifndef TRADE_SYS_SIGNAL_CRT_SINGLE_SG_H_
|
#ifndef TRADE_SYS_SIGNAL_CRT_SINGLE_SG_H_
|
||||||
#define 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"
|
#include "../SignalBase.h"
|
||||||
|
|
||||||
namespace hku {
|
namespace hku {
|
||||||
@ -22,7 +22,7 @@ namespace hku {
|
|||||||
* @return
|
* @return
|
||||||
* @ingroup Signal
|
* @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,
|
int filter_n = 20, double filter_p = 0.1,
|
||||||
const string& kpart = "CLOSE");
|
const string& kpart = "CLOSE");
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ SingleSignal::SingleSignal(): SignalBase("SINGLE") {
|
|||||||
setParam<string>("kpart", "CLOSE");
|
setParam<string>("kpart", "CLOSE");
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleSignal::SingleSignal(const Indicator& ind)
|
SingleSignal::SingleSignal(const Operand& ind)
|
||||||
: SignalBase("SINGLE"), m_ind(ind) {
|
: SignalBase("SINGLE"), m_ind(ind) {
|
||||||
setParam<int>("filter_n", 20);
|
setParam<int>("filter_n", 20);
|
||||||
setParam<double>("filter_p", 0.1);
|
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) {
|
int filter_n, double filter_p, const string& kpart) {
|
||||||
SingleSignal *p = new SingleSignal(ind);
|
SingleSignal *p = new SingleSignal(ind);
|
||||||
p->setParam<int>("filter_n", filter_n);
|
p->setParam<int>("filter_n", filter_n);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#ifndef TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
|
#ifndef TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
|
||||||
#define TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
|
#define TRADE_SYS_SIGNAL_IMP_SINGLESIGNAL_H_
|
||||||
|
|
||||||
#include "../../../indicator/Indicator.h"
|
#include "../../../indicator/Operand.h"
|
||||||
#include "../SignalBase.h"
|
#include "../SignalBase.h"
|
||||||
|
|
||||||
namespace hku {
|
namespace hku {
|
||||||
@ -16,14 +16,14 @@ namespace hku {
|
|||||||
class SingleSignal: public SignalBase {
|
class SingleSignal: public SignalBase {
|
||||||
public:
|
public:
|
||||||
SingleSignal();
|
SingleSignal();
|
||||||
SingleSignal(const Indicator& ind);
|
SingleSignal(const Operand& ind);
|
||||||
virtual ~SingleSignal();
|
virtual ~SingleSignal();
|
||||||
|
|
||||||
virtual SignalPtr _clone();
|
virtual SignalPtr _clone();
|
||||||
virtual void _calculate();
|
virtual void _calculate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Indicator m_ind;
|
Operand m_ind;
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
// 序列化支持
|
// 序列化支持
|
||||||
|
@ -24,7 +24,9 @@ void export_KData() {
|
|||||||
|
|
||||||
.def("getDatetimeList", &KData::getDatetimeList)
|
.def("getDatetimeList", &KData::getDatetimeList)
|
||||||
.def("getKRecord", &KData::getKRecord)
|
.def("getKRecord", &KData::getKRecord)
|
||||||
|
.def("get", &KData::getKRecord)
|
||||||
.def("getKRecordByDate", &KData::getKRecordByDate)
|
.def("getKRecordByDate", &KData::getKRecordByDate)
|
||||||
|
.def("getByDate", &KData::getKRecordByDate)
|
||||||
.def("_getPos", &KData::getPos) //python中需要将Null的情况改写为None
|
.def("_getPos", &KData::getPos) //python中需要将Null的情况改写为None
|
||||||
|
|
||||||
.def("size", &KData::size)
|
.def("size", &KData::size)
|
||||||
|
@ -13,23 +13,6 @@
|
|||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
using namespace hku;
|
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
|
#if HKU_PYTHON_SUPPORT_PICKLE
|
||||||
struct TradeManager_pickle_suite : bp::pickle_suite {
|
struct TradeManager_pickle_suite : bp::pickle_suite {
|
||||||
static
|
static
|
||||||
@ -59,6 +42,27 @@ struct TradeManager_pickle_suite : bp::pickle_suite {
|
|||||||
#endif /* HKU_PYTHON_SUPPORT_PICKLE */
|
#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() {
|
void export_TradeManager() {
|
||||||
|
|
||||||
class_<TradeManager>("TradeManager", init<const Datetime&, price_t,
|
class_<TradeManager>("TradeManager", init<const Datetime&, price_t,
|
||||||
@ -76,7 +80,7 @@ void export_TradeManager() {
|
|||||||
.add_property("lastDatetime", &TradeManager::lastDatetime)
|
.add_property("lastDatetime", &TradeManager::lastDatetime)
|
||||||
.add_property("reinvest", &TradeManager::reinvest)
|
.add_property("reinvest", &TradeManager::reinvest)
|
||||||
.add_property("precision", &TradeManager::precision)
|
.add_property("precision", &TradeManager::precision)
|
||||||
.add_property("costFunc", &TradeManager::costFunc)
|
.add_property("costFunc", get_costFunc, set_costFunc)
|
||||||
|
|
||||||
.def("getParam", &TradeManager::getParam<boost::any>)
|
.def("getParam", &TradeManager::getParam<boost::any>)
|
||||||
.def("setParam", &TradeManager::setParam<object>)
|
.def("setParam", &TradeManager::setParam<object>)
|
||||||
|
@ -49,7 +49,6 @@ void export_Signal() {
|
|||||||
.def(init<const string&>())
|
.def(init<const string&>())
|
||||||
.def(self_ns::str(self))
|
.def(self_ns::str(self))
|
||||||
.add_property("name", get_name, set_name)
|
.add_property("name", get_name, set_name)
|
||||||
.add_property("kdata", &SignalBase::getTO)
|
|
||||||
//因为Indicator无法使用params['name']的形式,所以统一使用setParm/getParam
|
//因为Indicator无法使用params['name']的形式,所以统一使用setParm/getParam
|
||||||
//.add_property("params",
|
//.add_property("params",
|
||||||
// make_function(&SignalBase::getParameter,
|
// make_function(&SignalBase::getParameter,
|
||||||
|
@ -72,8 +72,8 @@
|
|||||||
<File name="tools\hikyuu\docs\source\user\signal.rst" />
|
<File name="tools\hikyuu\docs\source\user\signal.rst" />
|
||||||
</Folder>
|
</Folder>
|
||||||
<File name="tools\hikyuu\docs\source\conf.py" />
|
<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\index.rst" />
|
||||||
|
<File name="tools\hikyuu\docs\source\developer_guide.rst" />
|
||||||
<File name="tools\hikyuu\docs\source\user_guide.rst" />
|
<File name="tools\hikyuu\docs\source\user_guide.rst" />
|
||||||
</Project>
|
</Project>
|
||||||
</NotepadPlus>
|
</NotepadPlus>
|
||||||
|
@ -192,7 +192,7 @@ html_static_path = ['_static']
|
|||||||
# Sphinx supports the following languages:
|
# Sphinx supports the following languages:
|
||||||
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
|
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
|
||||||
# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
|
# '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.
|
# A dictionary with options for the search language support, empty by default.
|
||||||
# Now only 'ja' uses this config value
|
# Now only 'ja' uses this config value
|
||||||
|
@ -50,22 +50,3 @@
|
|||||||
::
|
::
|
||||||
|
|
||||||
> xelatex -interaction=nonstopmode Hikyuu.tex
|
> 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
|
|
@ -11,11 +11,11 @@ Welcome to Hikyuu's documentation!
|
|||||||
|
|
||||||
user_guide
|
user_guide
|
||||||
developer_guide
|
developer_guide
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
==================
|
==================
|
||||||
|
|
||||||
* :ref:`genindex`
|
* :ref:`genindex`
|
||||||
* :ref:`modindex`
|
* :ref:`modindex`
|
||||||
* :ref:`search`
|
* :ref:`search`
|
||||||
|
|
||||||
|
@ -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):
|
class SignalPython(SignalBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(SignalPython, self).__init__("SignalPython")
|
super(SignalPython, self).__init__("SignalPython")
|
||||||
self._x = 0
|
self._x = 0 #私有属性
|
||||||
self.setParam("test", 30)
|
self.setParam("test", 30)
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
@ -55,16 +64,16 @@
|
|||||||
信号指示器基类
|
信号指示器基类
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
自定义的信号指示器,应实现_clone, _reset, _calculate接口。
|
自定义的信号指示器,应实现 :py:meth:`SignalBase._clone`, :py:meth:`SignalBase._reset`, :py:meth:`SignalBase._calculate` 接口。
|
||||||
|
|
||||||
.. py:class:: SignalBase
|
.. py:class:: SignalBase([name])
|
||||||
|
|
||||||
信号指示器基类
|
信号指示器基类
|
||||||
|
|
||||||
.. py:attribute:: name
|
.. py:attribute:: name
|
||||||
|
|
||||||
信号指示器名称
|
信号指示器名称
|
||||||
|
|
||||||
.. py:method:: getParam(name)
|
.. py:method:: getParam(name)
|
||||||
|
|
||||||
获取指定的参数
|
获取指定的参数
|
||||||
@ -86,7 +95,7 @@
|
|||||||
|
|
||||||
:param KData k: 设置交易对象
|
:param KData k: 设置交易对象
|
||||||
|
|
||||||
.. py:method:: getTO
|
.. py:method:: getTO()
|
||||||
|
|
||||||
:return: 交易对象
|
:return: 交易对象
|
||||||
:rtype: KData
|
:rtype: KData
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# Aothor: fasiondog
|
# Aothor: fasiondog
|
||||||
# History: 20130128, Added by fasiondog
|
# History: 20160407, Added by fasiondog
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
from hikyuu.trade_sys.signal import SignalBase
|
from hikyuu.trade_sys.signal import SignalBase
|
||||||
@ -22,8 +22,8 @@ class TurtleSignal(SignalBase):
|
|||||||
n = self.getParam("n")
|
n = self.getParam("n")
|
||||||
k = self.getTO()
|
k = self.getTO()
|
||||||
c = CLOSE(k)
|
c = CLOSE(k)
|
||||||
h = REF(HHV(c, n), 1)
|
h = REF(HHV(c, n), 1) #前n日高点
|
||||||
L = REF(LLV(c, n), 1)
|
L = REF(LLV(c, n), 1) #前n日低点
|
||||||
for i in range(h.discard, len(k)):
|
for i in range(h.discard, len(k)):
|
||||||
if (c[i] >= h[i]):
|
if (c[i] >= h[i]):
|
||||||
self._addBuySignal(k[i].datetime)
|
self._addBuySignal(k[i].datetime)
|
||||||
@ -40,6 +40,6 @@ if __name__ == "__main__":
|
|||||||
dates = k.getDatetimeList()
|
dates = k.getDatetimeList()
|
||||||
for d in dates:
|
for d in dates:
|
||||||
if (sg.shouldBuy(d)):
|
if (sg.shouldBuy(d)):
|
||||||
print("买入:%s" % str(d))
|
print("买入:%s" % d)
|
||||||
elif (sg.shouldSell(d)):
|
elif (sg.shouldSell(d)):
|
||||||
print("卖出: %s" % str(d))
|
print("卖出: %s" % d)
|
||||||
|
Loading…
Reference in New Issue
Block a user