更新SG系列,优化移除OP后的一些修改

This commit is contained in:
fasiondog 2023-10-14 02:29:40 +08:00
parent 42892b4145
commit bd5b6102ea
45 changed files with 506 additions and 734 deletions

View File

@ -40,7 +40,7 @@ Hikyuu Quant Framework是一款基于C++/Python的开源量化交易研究框架
my_tm = crtTM(init_cash = 300000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -11,7 +11,7 @@ Hikyuu Quant Framework是一款基于C++/Python的开源量化交易研究框架
my_tm = crtTM(init_cash = 300000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -25,7 +25,7 @@ Python中的订单代理包装
my_tm.broke_last_datetime=Datetime(201706010000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -19,38 +19,36 @@
双线交叉信号指示器
^^^^^^^^^^^^^^^^^^
.. py:function:: SG_Cross(fast, slow[, kpart = "CLOSE"])
.. py:function:: SG_Cross(fast, slow)
双线交叉指示器当快线从下向上穿越慢线时买入当快线从上向下穿越慢线时卖出。如5日MA上穿10日MA时买入5日MA线下穿MA10日线时卖出::
SG_Cross(OP(MA(n=10)), OP(MA(n=30)))
SG_Cross(MA(CLOSE(), n=10), OP(MA(n=30)))
:param Indicator fast: 快线
:param Indicator slow: 慢线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: 信号指示器
金叉信号指示器
^^^^^^^^^^^^^^^
.. py:function:: SG_CrossGold(fast, slow[, kpart = "CLOSE"])
.. py:function:: SG_CrossGold(fast, slow)
金叉指示器,当快线从下向上穿越慢线且快线和慢线的方向都是向上时为金叉,买入;
当快线从上向下穿越慢线且快线和慢线的方向都是向下时死叉,卖出。::
SG_CrossGold(OP(MA(n=10)), OP(MA(n=30)))
SG_CrossGold(MA(CLOSE(), n=10), MA(CLOSE(), n=30))
:param Indicator fast: 快线
:param Indicator slow: 慢线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: 信号指示器
单线拐点信号指示器
^^^^^^^^^^^^^^^^^^
.. py:function:: SG_Single(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
.. py:function:: SG_Single(ind[, filter_n = 10, filter_p = 0.1])
生成单线拐点信号指示器。使用《精明交易者》 [BOOK1]_ 中给出的曲线拐点算法判断曲线趋势,公式见下::
@ -63,10 +61,9 @@
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p: 过滤器百分比
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: 信号指示器
.. py:function:: SG_Single2(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
.. py:function:: SG_Single2(ind[, filter_n = 10, filter_p = 0.1])
生成单线拐点信号指示器2 [BOOK1]_::
@ -78,31 +75,28 @@
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p: 过滤器百分比
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: 信号指示器
自交叉单线拐点指示器
^^^^^^^^^^^^^^^^^^^^
.. py:function:: SG_Flex(ind, slow_n[, kpart = 'CLOSE'])
.. py:function:: SG_Flex(ind, slow_n)
使用自身的EMA(slow_n)作为慢线,自身作为快线,快线向上穿越慢线买入,快线向下穿越慢线卖出。
:param Indicator ind:
:param int slow_n: 慢线EMA周期
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: 信号指示器
布尔信号指示器
^^^^^^^^^^^^^^^^
.. py:function:: SG_Bool(buy, sell[, kpart='CLOSE'])
.. py:function:: SG_Bool(buy, sell)
布尔信号指示器使用运算结果为类似bool数组的Indicator分别作为买入、卖出指示。
:param Indicator buy: 买入指示结果Indicator中相应位置>0则代表买入
:param Indicator sell: 卖出指示结果Indicator中相应位置>0则代表卖出
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: 信号指示器

View File

@ -32,7 +32,7 @@
my_tm = crtTM(init_cash = 300000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -41,7 +41,7 @@ Hikyuu Quant Framework是一款基于C++/Python的开源量化交易研究框架
my_tm = crtTM(init_cash = 300000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -34,23 +34,14 @@
"""
from hikyuu import (
Query, StockManager, AMA, STDEV, CVAL, PRICELIST, EMA, CLOSE, HIGH, LOW, OPEN, KDATA, POS,
SG_Single, SG_Cross, SG_Flex, BUSINESS
)
from .drawplot import (
show_gcf, create_figure, ax_set_locator_formatter, adjust_axes_show, ax_draw_macd
Query, StockManager, AMA, STDEV, CVAL, PRICELIST, EMA, CLOSE, HIGH, LOW, OPEN, KDATA, POS, SG_Single, SG_Cross,
SG_Flex, BUSINESS
)
from .drawplot import (show_gcf, create_figure, ax_set_locator_formatter, adjust_axes_show, ax_draw_macd)
def draw(
stock,
query=Query(-130),
n=10,
filter_n=20,
filter_p=0.1,
sg_type="CROSS",
show_high_low=False,
arrow_style=1
stock, query=Query(-130), n=10, filter_n=20, filter_p=0.1, sg_type="CROSS", show_high_low=False, arrow_style=1
):
"""绘制佩里.J.考夫曼Perry J.Kaufman 自适应移动平均系统(AMA)"""
kdata = stock.get_kdata(query)
@ -77,7 +68,7 @@ def draw(
lama.plot(axes=ax1, color='g', legend_on=True, kref=kdata)
if sg_type == 'CROSS':
fast_op = AMA(n=n)
fast_op = AMA(CLOSE(), n=n)
slow_op = EMA(n=2 * n)(fast_op)
sg = SG_Cross(fast_op, slow_op)
sg.plot(axes=ax1, kdata=kdata)
@ -170,10 +161,10 @@ def draw2(
else:
print("sg_type only in ('CORSS', 'SINGLE')")
a = POS(block, query, SG_Flex(AMA(n=3), 6))
a = POS(block, query, SG_Flex(AMA(CLOSE(), n=3), 6))
a.name = "POS(3)"
a.plot(axes=ax2, color='b', marker='.', legend_on=True, kref=kdata)
a = POS(block, query, SG_Flex(AMA(n=30), 60))
a = POS(block, query, SG_Flex(AMA(CLOSE(), n=30), 60))
a.name = "POS(30)"
a.plot(axes=ax2, color='g', marker='.', legend_on=True, kref=kdata)

View File

@ -35,22 +35,11 @@ from hikyuu.util.mylog import spend_time
from hikyuu import Query
from hikyuu.indicator import Indicator, IF, MA, CLOSE, VOL, CVAL, PRICELIST, SG_Cross
from .drawplot import (
create_figure, get_current_draw_engine, ax_set_locator_formatter, adjust_axes_show,
ax_draw_macd, show_gcf
create_figure, get_current_draw_engine, ax_set_locator_formatter, adjust_axes_show, ax_draw_macd, show_gcf
)
def draw(
stock,
query=Query(-130),
ma1_n=5,
ma2_n=10,
ma3_n=20,
ma4_n=60,
ma5_n=100,
vma1_n=5,
vma2_n=10
):
def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60, ma5_n=100, vma1_n=5, vma2_n=10):
"""绘制普通K线图 + 成交量(成交金额)"""
kdata = stock.get_kdata(query)
close = CLOSE(kdata, )
@ -68,7 +57,7 @@ def draw(
ma4.plot(axes=ax1, legend_on=True, kref=kdata)
ma5.plot(axes=ax1, legend_on=True, kref=kdata)
sg = SG_Cross(MA(n=ma1_n), MA(n=ma2_n))
sg = SG_Cross(MA(CLOSE(), n=ma1_n), MA(CLOSE(), n=ma2_n))
sg.to = kdata
sg.plot(axes=ax1, kdata=kdata)
@ -94,17 +83,7 @@ def draw(
return show_gcf()
def draw2(
stock,
query=Query(-130),
ma1_n=7,
ma2_n=20,
ma3_n=30,
ma4_n=42,
ma5_n=100,
vma1_n=5,
vma2_n=10
):
def draw2(stock, query=Query(-130), ma1_n=7, ma2_n=20, ma3_n=30, ma4_n=42, ma5_n=100, vma1_n=5, vma2_n=10):
"""绘制普通K线图 + 成交量(成交金额)+ MACD"""
kdata = stock.get_kdata(query)
close = CLOSE(kdata)

View File

@ -68,9 +68,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

File diff suppressed because one or more lines are too long

View File

@ -9,17 +9,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"warning: can't import TA-Lib, will be ignored! You can fetch ta-lib from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib\n",
"std::cout are redirected to python::stdout\n",
"std::cerr are redirected to python::stderr\n",
"2021-02-10 22:54:27.023 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n",
"2021-02-10 22:54:27.025 [HKU-I] - Loading market information... (StockManager.cpp:473)\n",
"2021-02-10 22:54:27.026 [HKU-I] - Loading stock type information... (StockManager.cpp:486)\n",
"2021-02-10 22:54:27.027 [HKU-I] - Loading stock information... (StockManager.cpp:422)\n",
"2021-02-10 22:54:27.130 [HKU-I] - Loading stock weight... (StockManager.cpp:503)\n",
"2021-02-10 22:54:28.440 [HKU-I] - Loading KData... (StockManager.cpp:138)\n",
"2021-02-10 22:54:28.446 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:161)\n",
"2021-02-10 22:54:28.468 [HKU-I] - 0.03s Loaded Data. (StockManager.cpp:149)\n",
"Wall time: 2.72 s\n"
"2023-10-14 02:21:14.516 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n",
"2023-10-14 02:21:14.517 [HKU-I] - Loading market information... (StockManager.cpp:499)\n",
"2023-10-14 02:21:14.517 [HKU-I] - Loading stock type information... (StockManager.cpp:512)\n",
"2023-10-14 02:21:14.518 [HKU-I] - Loading stock information... (StockManager.cpp:426)\n",
"2023-10-14 02:21:14.572 [HKU-I] - Loading stock weight... (StockManager.cpp:529)\n",
"2023-10-14 02:21:14.988 [HKU-I] - Loading KData... (StockManager.cpp:134)\n",
"2023-10-14 02:21:14.993 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:157)\n",
"2023-10-14 02:21:14.994 [HKU-I] - Preloading all week kdata to buffer! (StockManager.cpp:160)\n",
"2023-10-14 02:21:14.994 [HKU-I] - Preloading all month kdata to buffer! (StockManager.cpp:163)\n",
"2023-10-14 02:21:15.008 [HKU-I] - 0.02s Loaded Data. (StockManager.cpp:145)\n",
"Wall time: 1.2 s\n"
]
}
],
@ -71,21 +74,19 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"全部数量: 6067\n"
"全部数量: 7928\n"
]
},
{
"data": {
"text/plain": [
"6067"
"7928"
]
},
"execution_count": 3,
@ -125,8 +126,16 @@
"output_type": "stream",
"text": [
"Stock(SH, 600175, 美都能源, A股, 0, 1999-04-08 00:00:00, +infinity)\n",
"Stock(SH, 600260, *ST凯乐, A股, 0, 2000-07-06 00:00:00, +infinity)\n",
"Stock(SH, 600240, *ST华业, A股, 0, 2000-06-28 00:00:00, +infinity)\n",
"Stock(SH, 600270, 外运发展, A股, 0, 2000-12-28 00:00:00, +infinity)\n"
"Stock(SH, 600614, *ST鹏起, A股, 0, 1992-08-28 00:00:00, +infinity)\n",
"Stock(SH, 600687, *ST刚泰, A股, 0, 1993-11-08 00:00:00, +infinity)\n",
"Stock(SH, 600093, 退市易见, A股, 0, 1997-06-26 00:00:00, +infinity)\n",
"Stock(SH, 600122, *ST宏图, A股, 0, 1998-04-20 00:00:00, +infinity)\n",
"Stock(SH, 600393, ST粤泰, A股, 0, 2001-03-19 00:00:00, +infinity)\n",
"Stock(SH, 600978, *ST宜生, A股, 0, 2004-08-24 00:00:00, +infinity)\n",
"Stock(SH, 600270, 外运发展, A股, 0, 2000-12-28 00:00:00, +infinity)\n",
"Stock(SH, 600856, 退市中天, A股, 0, 1994-04-25 00:00:00, +infinity)\n"
]
}
],
@ -159,7 +168,7 @@
"Stock(SZ, 002685, 华东重机, A股, 1, 2012-06-12 00:00:00, +infinity)\n",
"Stock(SZ, 002339, 积成电子, A股, 1, 2010-01-22 00:00:00, +infinity)\n",
"Stock(SZ, 000728, 国元证券, A股, 1, 1997-05-22 00:00:00, +infinity)\n",
"Stock(SZ, 000958, 东方能源, A股, 1, 1999-12-23 00:00:00, +infinity)\n",
"Stock(SZ, 000958, 电投产融, A股, 1, 1999-12-23 00:00:00, +infinity)\n",
"Stock(SZ, 000001, 平安银行, A股, 1, 1991-01-02 00:00:00, +infinity)\n",
"Stock(SH, 600601, 方正科技, A股, 1, 1990-12-19 00:00:00, +infinity)\n",
"Stock(SH, 600050, 中国联通, A股, 1, 2002-10-09 00:00:00, +infinity)\n",
@ -247,7 +256,11 @@
"Weight(2019-06-30 00:00:00, 0, 0, 0, 0, 0, 1.71704e+06, 1.71702e+06)\n",
"Weight(2019-09-18 00:00:00, 0, 0, 0, 0, 0, 1.94059e+06, 1.94058e+06)\n",
"Weight(2020-05-28 00:00:00, 0, 0, 0, 2.18, 0, 1.94059e+06, 1.94058e+06)\n",
"Weight(2020-12-31 00:00:00, 0, 0, 0, 0, 0, 1.94059e+06, 1.94058e+06)\n"
"Weight(2020-12-31 00:00:00, 0, 0, 0, 0, 0, 1.94059e+06, 1.94058e+06)\n",
"Weight(2021-05-14 00:00:00, 0, 0, 0, 1.799, 0, 1.94059e+06, 1.94058e+06)\n",
"Weight(2021-12-31 00:00:00, 0, 0, 0, 0, 0, 1.94059e+06, 1.94055e+06)\n",
"Weight(2022-07-22 00:00:00, 0, 0, 0, 2.279, 0, 1.94059e+06, 1.94055e+06)\n",
"Weight(2023-06-14 00:00:00, 0, 0, 0, 2.849, 0, 1.94059e+06, 1.94055e+06)\n"
]
}
],
@ -267,7 +280,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -281,9 +294,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,19 +9,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"warning: can't import TA-Lib, will be ignored! You can fetch ta-lib from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib\n",
"std::cout are redirected to python::stdout\n",
"std::cerr are redirected to python::stderr\n",
"2022-06-30 00:49:42.300 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n",
"2022-06-30 00:49:42.301 [HKU-I] - Loading market information... (StockManager.cpp:497)\n",
"2022-06-30 00:49:42.301 [HKU-I] - Loading stock type information... (StockManager.cpp:510)\n",
"2022-06-30 00:49:42.301 [HKU-I] - Loading stock information... (StockManager.cpp:424)\n",
"2022-06-30 00:49:42.348 [HKU-I] - Loading stock weight... (StockManager.cpp:527)\n",
"2022-06-30 00:49:42.714 [HKU-I] - Loading KData... (StockManager.cpp:139)\n",
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:162)\n",
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all week kdata to buffer! (StockManager.cpp:165)\n",
"2022-06-30 00:49:42.717 [HKU-I] - Preloading all month kdata to buffer! (StockManager.cpp:168)\n",
"2022-06-30 00:49:42.729 [HKU-I] - 0.01s Loaded Data. (StockManager.cpp:150)\n",
"Wall time: 1.08 s\n"
"2023-10-14 02:24:00.639 [HKU-I] - Using SQLITE3 BaseInfoDriver (BaseInfoDriver.cpp:58)\n",
"2023-10-14 02:24:00.640 [HKU-I] - Loading market information... (StockManager.cpp:499)\n",
"2023-10-14 02:24:00.640 [HKU-I] - Loading stock type information... (StockManager.cpp:512)\n",
"2023-10-14 02:24:00.641 [HKU-I] - Loading stock information... (StockManager.cpp:426)\n",
"2023-10-14 02:24:00.691 [HKU-I] - Loading stock weight... (StockManager.cpp:529)\n",
"2023-10-14 02:24:01.039 [HKU-I] - Loading KData... (StockManager.cpp:134)\n",
"2023-10-14 02:24:01.043 [HKU-I] - Preloading all day kdata to buffer! (StockManager.cpp:157)\n",
"2023-10-14 02:24:01.043 [HKU-I] - Preloading all week kdata to buffer! (StockManager.cpp:160)\n",
"2023-10-14 02:24:01.044 [HKU-I] - Preloading all month kdata to buffer! (StockManager.cpp:163)\n",
"2023-10-14 02:24:01.055 [HKU-I] - 0.02s Loaded Data. (StockManager.cpp:145)\n",
"Wall time: 1.09 s\n"
]
}
],
@ -32,9 +33,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"# 1 利用 TM 实现简单的记账本\n",
"\n",
@ -73,7 +72,7 @@
" current borrow_cash: 0.00,\n",
" current borrow_asset: 0.00,\n",
" Position: \n",
" SZ000001 平安银行 2017-01-03 00:00:00 1333 100.00 911.00 1464.00 553.00 60.70% 0.55%\n",
" SZ000001 平安银行 2017-01-03 00:00:00 1646 100.00 911.00 1100.00 189.00 20.75% 0.19%\n",
" Short Position: \n",
" Borrow Stock: \n",
"}\n"
@ -143,12 +142,12 @@
" <th>SZ000001</th>\n",
" <td>平安银行</td>\n",
" <td>2017-01-03</td>\n",
" <td>1333</td>\n",
" <td>1646</td>\n",
" <td>100</td>\n",
" <td>911.0</td>\n",
" <td>1464.0</td>\n",
" <td>553.0</td>\n",
" <td>60.702525</td>\n",
" <td>1100.0</td>\n",
" <td>189.0</td>\n",
" <td>20.746432</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
@ -157,7 +156,7 @@
"text/plain": [
" 证券名称 买入日期 已持仓天数 持仓数量 投入金额 当前市值 盈亏金额 盈亏比例\n",
"证券代码 \n",
"SZ000001 平安银行 2017-01-03 1333 100 911.0 1464.0 553.0 60.702525"
"SZ000001 平安银行 2017-01-03 1646 100 911.0 1100.0 189.0 20.746432"
]
},
"execution_count": 3,
@ -300,19 +299,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"买入SZ000001 18.300 1000\n",
"卖出SZ000001 17.510 1000\n",
"买入SZ000001 17.410 1000\n",
"卖出SZ000001 17.000 1000\n",
"买入SZ000001 17.340 1000\n",
"卖出SZ000001 16.500 1000\n",
"买入SZ000001 17.030 1000\n",
"卖出SZ000001 16.350 1000\n",
"买入SZ000001 15.110 1000\n",
"卖出SZ000001 14.880 1000\n",
"买入SZ000001 14.740 1000\n",
"卖出SZ000001 14.090 1000\n",
"买入SZ000001 14.470 1000\n"
"买入SZ000001 12.930 1000\n",
"卖出SZ000001 12.480 1000\n",
"买入SZ000001 12.940 1000\n",
"卖出SZ000001 12.580 1000\n",
"买入SZ000001 11.410 1000\n",
"卖出SZ000001 11.230 1000\n",
"买入SZ000001 11.330 1000\n",
"卖出SZ000001 11.450 1000\n",
"买入SZ000001 11.650 1000\n",
"卖出SZ000001 11.690 1000\n",
"买入SZ000001 11.400 1000\n",
"卖出SZ000001 11.280 1000\n"
]
}
],
@ -328,7 +326,7 @@
"my_tm.broker_last_datetime=Datetime(201701010000)\n",
"\n",
"#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出\n",
"my_sg = SG_Flex(EMA(n=5), slow_n=10)\n",
"my_sg = SG_Flex(EMA(C, n=5), slow_n=10)\n",
"\n",
"#固定每次买入1000股\n",
"my_mm = MM_FixedCount(1000)\n",
@ -362,9 +360,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -56,7 +56,7 @@ def SYS_Simple(tm=None, mm=None, ev=None, cn=None, sg=None, st=None, tp=None, pg
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越
#慢线时买入,反之卖出)
my_sg = SG_Flex(EMA(n=5), slow_n=10)
my_sg = SG_Flex(EMA(C, n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)

View File

@ -13,8 +13,7 @@
namespace hku {
SignalPtr HKU_API SG_Band(const Indicator& sig, price_t lower, price_t upper,
const string& kpart = "CLOSE");
SignalPtr HKU_API SG_Band(const Indicator& sig, price_t lower, price_t upper);
} /* namespace hku */

View File

@ -18,12 +18,10 @@ namespace hku {
* 线线穿线线穿线
* @param fast 线
* @param slow 线
* @param kpart KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
* @return
* @ingroup Signal
*/
SignalPtr HKU_API SG_Cross(const Indicator& fast, const Indicator& slow,
const string& kpart = "CLOSE");
SignalPtr HKU_API SG_Cross(const Indicator& fast, const Indicator& slow);
} /* namespace hku */

View File

@ -19,12 +19,10 @@ namespace hku {
* 线穿线线线
* @param fast 线
* @param slow 线
* @param kpart KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
* @return
* @ingroup Signal
*/
SignalPtr HKU_API SG_CrossGold(const Indicator& fast, const Indicator& slow,
const string& kpart = "CLOSE");
SignalPtr HKU_API SG_CrossGold(const Indicator& fast, const Indicator& slow);
} /* namespace hku */

View File

@ -10,8 +10,8 @@
namespace hku {
SignalPtr HKU_API SG_Flex(const Indicator& op, int slow_n, const string& kpart) {
SignalPtr sg = SG_Cross(op, EMA(slow_n)(op), kpart);
SignalPtr HKU_API SG_Flex(const Indicator& op, int slow_n) {
SignalPtr sg = SG_Cross(op, EMA(slow_n)(op));
sg->name("SG_Flex");
return sg;
}

View File

@ -19,11 +19,10 @@ namespace hku {
* 使EMA(slow_n)线线线穿线线穿线
* @param op
* @param slow_n 线EMA周期
* @param kpart KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
* @return
* @ingroup Signal
*/
SignalPtr HKU_API SG_Flex(const Indicator& op, int slow_n, const string& kpart = "CLOSE");
SignalPtr HKU_API SG_Flex(const Indicator& op, int slow_n);
} /* namespace hku */

View File

@ -28,12 +28,10 @@ namespace hku {
* @param ind
* @param filter_n N日周期
* @param filter_p
* @param kpart KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
* @return
* @ingroup Signal
*/
SignalPtr HKU_API SG_Single(const Indicator& ind, int filter_n = 20, double filter_p = 0.1,
const string& kpart = "CLOSE");
SignalPtr HKU_API SG_Single(const Indicator& ind, int filter_n = 20, double filter_p = 0.1);
/**
* 线2
@ -48,12 +46,10 @@ SignalPtr HKU_API SG_Single(const Indicator& ind, int filter_n = 20, double filt
* @param ind
* @param filter_n N日周期
* @param filter_p
* @param kpart KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
* @return
* @ingroup Signal
*/
SignalPtr HKU_API SG_Single2(const Indicator& ind, int filter_n = 20, double filter_p = 0.1,
const string& kpart = "CLOSE");
SignalPtr HKU_API SG_Single2(const Indicator& ind, int filter_n = 20, double filter_p = 0.1);
} /* namespace hku */

View File

@ -9,13 +9,10 @@
namespace hku {
BandSignal::BandSignal() : SignalBase("SG_Band") {
setParam<string>("kpart", "CLOSE");
}
BandSignal::BandSignal() : SignalBase("SG_Band") {}
BandSignal::BandSignal(const Indicator& ind, price_t lower, price_t upper, const string& kpart)
BandSignal::BandSignal(const Indicator& ind, price_t lower, price_t upper)
: SignalBase("SG_Band"), m_ind(ind), m_lower(lower), m_upper(upper) {
setParam<string>("kpart", kpart);
HKU_ERROR_IF(m_lower > m_upper, "BandSignal: lower track is greater than upper track");
}
@ -30,10 +27,7 @@ SignalPtr BandSignal::_clone() {
}
void BandSignal::_calculate() {
string kpart = getParam<string>("kpart");
Indicator kdata = KDATA_PART(m_kdata, kpart);
Indicator ind = m_ind(kdata);
Indicator ind = m_ind(m_kdata);
size_t discard = ind.discard();
size_t total = ind.size();
@ -46,9 +40,8 @@ void BandSignal::_calculate() {
}
}
SignalPtr HKU_API SG_Band(const Indicator& sig, price_t lower, price_t upper,
const string& kpart = "CLOSE") {
return SignalPtr(new BandSignal(sig, lower, upper, kpart));
SignalPtr HKU_API SG_Band(const Indicator& sig, price_t lower, price_t upper) {
return SignalPtr(new BandSignal(sig, lower, upper));
}
} // namespace hku

View File

@ -17,7 +17,7 @@ namespace hku {
class BandSignal : public SignalBase {
public:
BandSignal();
BandSignal(const Indicator& sig, price_t lower, price_t upper, const string& kpart);
BandSignal(const Indicator& sig, price_t lower, price_t upper);
virtual ~BandSignal();
virtual SignalPtr _clone() override;

View File

@ -10,14 +10,10 @@
namespace hku {
CrossGoldSignal::CrossGoldSignal() : SignalBase("SG_CrossGold") {
setParam<string>("kpart", "CLOSE");
}
CrossGoldSignal::CrossGoldSignal() : SignalBase("SG_CrossGold") {}
CrossGoldSignal::CrossGoldSignal(const Indicator& fast, const Indicator& slow, const string& kpart)
: SignalBase("SG_CrossGold"), m_fast(fast), m_slow(slow) {
setParam<string>("kpart", kpart);
}
CrossGoldSignal::CrossGoldSignal(const Indicator& fast, const Indicator& slow)
: SignalBase("SG_CrossGold"), m_fast(fast), m_slow(slow) {}
CrossGoldSignal::~CrossGoldSignal() {}
@ -29,10 +25,8 @@ SignalPtr CrossGoldSignal::_clone() {
}
void CrossGoldSignal::_calculate() {
string kpart = getParam<string>("kpart");
Indicator kdata = KDATA_PART(m_kdata, kpart);
Indicator fast = m_fast(kdata);
Indicator slow = m_slow(kdata);
Indicator fast = m_fast(m_kdata);
Indicator slow = m_slow(m_kdata);
HKU_ERROR_IF_RETURN(fast.size() != slow.size(), void(), "fast.size() != slow.size()");
size_t discard = fast.discard() > slow.discard() ? fast.discard() : slow.discard();
@ -48,8 +42,8 @@ void CrossGoldSignal::_calculate() {
}
}
SignalPtr HKU_API SG_CrossGold(const Indicator& fast, const Indicator& slow, const string& kpart) {
return SignalPtr(new CrossGoldSignal(fast, slow, kpart));
SignalPtr HKU_API SG_CrossGold(const Indicator& fast, const Indicator& slow) {
return SignalPtr(new CrossGoldSignal(fast, slow));
}
} /* namespace hku */

View File

@ -17,7 +17,7 @@ namespace hku {
class CrossGoldSignal : public SignalBase {
public:
CrossGoldSignal();
CrossGoldSignal(const Indicator& fast, const Indicator& slow, const string& kpart);
CrossGoldSignal(const Indicator& fast, const Indicator& slow);
virtual ~CrossGoldSignal();
virtual SignalPtr _clone() override;

View File

@ -10,14 +10,10 @@
namespace hku {
CrossSignal::CrossSignal() : SignalBase("SG_Cross") {
setParam<string>("kpart", "CLOSE");
}
CrossSignal::CrossSignal() : SignalBase("SG_Cross") {}
CrossSignal::CrossSignal(const Indicator& fast, const Indicator& slow, const string& kpart)
: SignalBase("SG_Cross"), m_fast(fast), m_slow(slow) {
setParam<string>("kpart", kpart);
}
CrossSignal::CrossSignal(const Indicator& fast, const Indicator& slow)
: SignalBase("SG_Cross"), m_fast(fast), m_slow(slow) {}
CrossSignal::~CrossSignal() {}
@ -29,10 +25,8 @@ SignalPtr CrossSignal::_clone() {
}
void CrossSignal::_calculate() {
string kpart = getParam<string>("kpart");
Indicator kdata = KDATA_PART(m_kdata, kpart);
Indicator fast = m_fast(kdata);
Indicator slow = m_slow(kdata);
Indicator fast = m_fast(m_kdata);
Indicator slow = m_slow(m_kdata);
HKU_ERROR_IF_RETURN(fast.size() != slow.size(), void(), "fast.size() != slow.size()");
size_t discard = fast.discard() > slow.discard() ? fast.discard() : slow.discard();
@ -46,8 +40,8 @@ void CrossSignal::_calculate() {
}
}
SignalPtr HKU_API SG_Cross(const Indicator& fast, const Indicator& slow, const string& kpart) {
return SignalPtr(new CrossSignal(fast, slow, kpart));
SignalPtr HKU_API SG_Cross(const Indicator& fast, const Indicator& slow) {
return SignalPtr(new CrossSignal(fast, slow));
}
} /* namespace hku */

View File

@ -17,7 +17,7 @@ namespace hku {
class CrossSignal : public SignalBase {
public:
CrossSignal();
CrossSignal(const Indicator& fast, const Indicator& slow, const string& kpart);
CrossSignal(const Indicator& fast, const Indicator& slow);
virtual ~CrossSignal();
virtual SignalPtr _clone() override;

View File

@ -15,13 +15,11 @@ namespace hku {
SingleSignal::SingleSignal() : SignalBase("SG_Single") {
setParam<int>("filter_n", 10);
setParam<double>("filter_p", 0.1);
setParam<string>("kpart", "CLOSE");
}
SingleSignal::SingleSignal(const Indicator& ind) : SignalBase("SG_Single"), m_ind(ind) {
setParam<int>("filter_n", 10);
setParam<double>("filter_p", 0.1);
setParam<string>("kpart", "CLOSE");
}
SingleSignal::~SingleSignal() {}
@ -35,9 +33,8 @@ SignalPtr SingleSignal::_clone() {
void SingleSignal::_calculate() {
int filter_n = getParam<int>("filter_n");
double filter_p = getParam<double>("filter_p");
string kpart(getParam<string>("kpart"));
Indicator ind = m_ind(KDATA_PART(m_kdata, kpart));
Indicator ind = m_ind(m_kdata);
Indicator dev = STDEV(DIFF(ind), filter_n);
size_t start = dev.discard();
@ -57,12 +54,10 @@ void SingleSignal::_calculate() {
}
}
SignalPtr HKU_API SG_Single(const Indicator& ind, int filter_n, double filter_p,
const string& kpart) {
SignalPtr HKU_API SG_Single(const Indicator& ind, int filter_n, double filter_p) {
SingleSignal* p = new SingleSignal(ind);
p->setParam<int>("filter_n", filter_n);
p->setParam<double>("filter_p", filter_p);
p->setParam<string>("kpart", kpart);
return SignalPtr(p);
}

View File

@ -18,13 +18,11 @@ namespace hku {
SingleSignal2::SingleSignal2() : SignalBase("SG_Single2") {
setParam<int>("filter_n", 10);
setParam<double>("filter_p", 0.1);
setParam<string>("kpart", "CLOSE");
}
SingleSignal2::SingleSignal2(const Indicator& ind) : SignalBase("SG_Single2"), m_ind(ind) {
setParam<int>("filter_n", 10);
setParam<double>("filter_p", 0.1);
setParam<string>("kpart", "CLOSE");
}
SingleSignal2::~SingleSignal2() {}
@ -38,9 +36,8 @@ SignalPtr SingleSignal2::_clone() {
void SingleSignal2::_calculate() {
int filter_n = getParam<int>("filter_n");
double filter_p = getParam<double>("filter_p");
string kpart(getParam<string>("kpart"));
Indicator ind = m_ind(KDATA_PART(m_kdata, kpart));
Indicator ind = m_ind(m_kdata);
Indicator dev = REF(STDEV(DIFF(ind), filter_n), 1);
size_t start = dev.discard();
@ -59,12 +56,10 @@ void SingleSignal2::_calculate() {
}
}
SignalPtr HKU_API SG_Single2(const Indicator& ind, int filter_n, double filter_p,
const string& kpart) {
SignalPtr HKU_API SG_Single2(const Indicator& ind, int filter_n, double filter_p) {
SingleSignal2* p = new SingleSignal2(ind);
p->setParam<int>("filter_n", filter_n);
p->setParam<double>("filter_p", filter_p);
p->setParam<string>("kpart", kpart);
return SignalPtr(p);
}

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/system/crt/SYS_Simple.h>
#include <hikyuu/trade_sys/signal/crt/SG_CrossGold.h>
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/EMA.h>
using namespace hku;
@ -30,13 +31,13 @@ TEST_CASE("test_PF_for_delay_and_no_adjust") {
StockManager& sm = StockManager::instance();
SYSPtr sys = SYS_Simple();
sys->setSG(SG_CrossGold(EMA(12), EMA(26)));
sys->setSG(SG_CrossGold(EMA(CLOSE(), 12), EMA(CLOSE(), 26)));
sys->setMM(MM_FixedCount(100));
SYSPtr pro_sys = sys->clone();
TMPtr tm = crtTM(Datetime(199001010000L), 500000);
SEPtr se = SE_Fixed();
se->addStockList({sm["sz000001"], sm["sz000063"],sm["sz000651"]}, sys);
se->addStockList({sm["sz000001"], sm["sz000063"], sm["sz000651"]}, sys);
AFPtr af = AF_EqualWeight();
PFPtr pf = PF_Simple(tm, se, af);

View File

@ -11,6 +11,7 @@
#include <hikyuu/trade_sys/selector/crt/SE_Fixed.h>
#include <hikyuu/trade_sys/signal/crt/SG_Cross.h>
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/MA.h>
using namespace hku;
@ -39,7 +40,7 @@ TEST_CASE("test_SE_Fixed") {
CHECK_EQ(result.size(), 0);
/** @arg 试图加入一个缺少MM的系统策略原型 */
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
CHECK_UNARY(!se->addStock(sm["sh600000"], sys));

View File

@ -14,6 +14,7 @@
#include <boost/archive/xml_iarchive.hpp>
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_sys/signal/build_in.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/AMA.h>
using namespace hku;
@ -30,7 +31,7 @@ TEST_CASE("test_SG_AMA_export") {
string filename(sm.tmpdir());
filename += "/SG_AMA.xml";
SignalPtr sg1 = SG_Single(AMA());
SignalPtr sg1 = SG_Single(AMA(CLOSE()));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -31,19 +32,19 @@ TEST_CASE("test_SYS_Simple_for_base") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
SYSPtr sys;

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -31,22 +32,22 @@ TEST_CASE("test_SYS_Simple_for_cn") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
STPtr st = ST_FixedPercent(0.01);
TPPtr tp = ST_Indicator(MA(5), "CLOSE");
TPPtr tp = ST_Indicator(MA(CLOSE(), 5));
SYSPtr sys;
EVPtr ev1 = make_shared<TestEV1>();

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -31,22 +32,22 @@ TEST_CASE("test_SYS_Simple_for_ev") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
STPtr st = ST_FixedPercent(0.01);
TPPtr tp = ST_Indicator(MA(5), "CLOSE");
TPPtr tp = ST_Indicator(MA(CLOSE(), 5));
SYSPtr sys;
EVPtr ev1 = make_shared<TestEV1>();

View File

@ -16,6 +16,7 @@
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/trade_sys/profitgoal/crt/PG_FixedPercent.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -32,22 +33,22 @@ TEST_CASE("test_SYS_Simple_for_pg") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
STPtr st = ST_FixedPercent(0.01);
TPPtr tp = ST_Indicator(MA(5), "CLOSE");
TPPtr tp = ST_Indicator(MA(CLOSE(), 5));
PGPtr pg = PG_FixedPercent(0.01);
SYSPtr sys;

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -31,19 +32,19 @@ TEST_CASE("test_SYS_Simple_for_st") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
STPtr st = ST_FixedPercent(0.01);
SYSPtr sys;

View File

@ -15,6 +15,7 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_FixedPercent.h>
#include <hikyuu/trade_sys/stoploss/crt/ST_Indicator.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
@ -31,22 +32,22 @@ TEST_CASE("test_SYS_Simple_for_tp") {
StockManager& sm = StockManager::instance();
//初始参数
Datetime init_date(199001010000LL); //账户初始日期
price_t init_cash = 100000; //账户初始金额
TradeCostPtr costfunc = TC_Zero(); //零成本函数
Stock stk = sm["sh600000"]; //选定标的
Datetime start_date(199911100000LL); //测试起始日期
Datetime end_date(200002250000LL); //测试结束日期
// 初始参数
Datetime init_date(199001010000LL); // 账户初始日期
price_t init_cash = 100000; // 账户初始金额
TradeCostPtr costfunc = TC_Zero(); // 零成本函数
Stock stk = sm["sh600000"]; // 选定标的
Datetime start_date(199911100000LL); // 测试起始日期
Datetime end_date(200002250000LL); // 测试结束日期
KQuery query = KQueryByDate(start_date, end_date, KQuery::DAY);
//构建系统部件
// 构建系统部件
TMPtr tm = crtTM(init_date, init_cash, costfunc, "TEST_TM");
SGPtr sg = SG_Cross(MA(5), MA(10), "CLOSE");
SGPtr sg = SG_Cross(MA(CLOSE(), 5), MA(CLOSE(), 10));
MMPtr mm = MM_FixedCount(100);
STPtr st = ST_FixedPercent(0.01);
TPPtr tp = ST_Indicator(MA(5), "CLOSE");
TPPtr tp = ST_Indicator(MA(CLOSE(), 5));
SYSPtr sys;
/** @arg 指定了TM、SG、MM、ST、TP但未指定其他策略组件非延迟操作 */

View File

@ -152,9 +152,8 @@ void export_Signal() {
:param Indicator sell: Indicator中相应位置>0
:return: )");
def("SG_Single", SG_Single,
(arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1, arg("kpart") = "CLOSE"),
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
def("SG_Single", SG_Single, (arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1),
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1])
线使 [BOOK1]_ 线线::
@ -167,12 +166,10 @@ void export_Signal() {
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Single2", SG_Single2,
(arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1, arg("kpart") = "CLOSE"),
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
def("SG_Single2", SG_Single2, (arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1),
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1])
线2 [BOOK1]_::
@ -184,49 +181,45 @@ void export_Signal() {
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Cross", SG_Cross, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"),
R"(SG_Cross(fast, slow[, kpart = "CLOSE"])
def("SG_Cross", SG_Cross, (arg("fast"), arg("slow")),
R"(SG_Cross(fast, slow)
线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
SG_Cross(OP(MA(n=10)), OP(MA(n=30)))
SG_Cross(MA(C, n=10), MA(C, n=30))
:param Indicator fast: 线
:param Indicator slow: 线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: )");
def("SG_CrossGold", SG_CrossGold, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"),
R"(SG_CrossGold(fast, slow[, kpart = "CLOSE"])
def("SG_CrossGold", SG_CrossGold, (arg("fast"), arg("slow")),
R"(SG_CrossGold(fast, slow)
线穿线线线
线穿线线线::
SG_CrossGold(OP(MA(n=10)), OP(MA(n=30)))
SG_CrossGold(MA(C, n=10), MA(C, n=30))
:param Indicator fast: 线
:param Indicator slow: 线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: )");
def("SG_Flex", SG_Flex, (arg("op"), arg("slow_n"), arg("kpart") = "CLOSE"),
R"(SG_Flex(ind, slow_n[, kpart = 'CLOSE'])
def("SG_Flex", SG_Flex, (arg("op"), arg("slow_n")),
R"(SG_Flex(ind, slow_n)
使EMA(slow_n)线线线穿线线穿线
:param Indicator ind:
:param int slow_n: 线EMA周期
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Band", SG_Band, (arg("ind"), arg("lower"), arg("upper"), arg("kpart") = "CLOSE"),
R"(SG_Band(ind, lower, upper[, kpart = 'CLOSE'])
def("SG_Band", SG_Band, (arg("ind"), arg("lower"), arg("upper")),
R"(SG_Band(ind, lower, upper)
,
::
SG_Band(OP(MA(n=10)), 100, 200)
SG_Band(MA(C, n=10), 100, 200)
)");
}

View File

@ -45,7 +45,7 @@ void export_System() {
my_tm = crtTM(init_cash = 300000)
#创建信号指示器以5日EMA为快线5日EMA自身的10日EMA作为慢线快线向上穿越慢线时买入反之卖出
my_sg = SG_Flex(EMA(n=5), slow_n=10)
my_sg = SG_Flex(EMA(C, n=5), slow_n=10)
#固定每次买入1000股
my_mm = MM_FixedCount(1000)