传统移动平均线(MA)的缺点
移动平均线(MA)是技术分析中常用的一类趋势跟踪指标,其可以在一定程度上刻画股票价格或指数的变动方向。MA 的计算天数越多,平滑性越好,但时滞带来的延迟影响也越严重。因此,在使用 MA 指标进行趋势跟踪时,容易出现“跟不紧”甚至“跟不上”的情况。平滑性和延迟性在 MA 指标中成为了不可避免的矛盾,这就促使我们去寻找化解这一矛盾的工具和方法。
低延迟趋势线(LLT)的构造
与 MA 类似的均线指标还有 EMA,其本质是在计算中对靠近计算日的价格赋予更大的权重。EMA 指标的计算方式在信号处理理论中恰好对应着一类一阶低通滤波器,其可以将信号的高频分量进行有效的过滤。通过分析,我们认为如果希望滤波效果更好,则需要选择合适阶数的滤波器。上述一阶滤波的效果相对较差,通带和阻带间的过渡带太长;阶数越高,滤波器传输函数在截止频率附近衰减得越快,但同时通带会变得不平,也就是靠近截止频率的信号会有些放大。因此折中来看,可以选择二阶滤波器,我们根据二阶滤波器设计了 LLT 低延迟趋势线,发现其在低频部分的输出信号较强,同时相比 MA 均线和 EMA 均线,延迟大幅下降。
LLT 趋势线可以实现交易性趋势择时
我们将 LLT 趋势择时应用于沪深 300、上证指数、深证成指等市场指数的日数据,通过切线法进行方向判断,获得良好的风险收益情况。相比MA 趋势择时,我们发现 LLT 模型的择时周期更短,稳定性也更好。不过采用切线法对趋势线进行追踪有一个问题,就是在趋势拐点附近,切线斜率容易在零附近震荡,从而造成多次择时判断且正确率下降的情况,这相当于在择时模型中内嵌了一定的止损机制,因此我们将这类择时方法称为交易性择时。对于 LLT 指标,趋势一旦确立,持仓可以保持相对较长的盈利时间,而在拐点附近的震荡交易次数虽多,但持仓时间往往都很短。因此对于交易性择时来说,在判断正确率相对较低的情况下,判断正确的时间占比却往往较高,并且盈利也主要来自于这一部分的贡献。
LLT 趋势择时可应用于股票、ETF、期货等金融产品的交易
基于 LLT 对趋势跟踪的有效性,我们认为 LLT 趋势择时可应用于股票、ETF、期货等金融产品的交易。在本篇报告中,我们实证计算了 LLT 在 ETF趋势交易中的应用,获得了良好的风险收益表现。
一、 传统均线系统
跟随市场趋势是一种简单有效的投资方式。在市场处于上升趋势时,投资者可以买入并持有;当市场转为下降趋势时,投资者可以选择卖空或空仓。
跟随趋势最简单的办法是采用移动平均(Moving Average)线,其算法为:
图片
其中 price一般选择收盘价,MA(n)即为T日的n日均线指标。对于MA指标,n越大,趋势线的平滑性越好。MA指标可以很好地刻画指数或股票价格趋势,但其最大的问题在于存在延迟。
如下图所示的指数日线及 MA 均线系统,蓝色、橙色、紫色、绿色分别代表 5 日、 10 日、30 日和 60 日均线。可以看出,随着均线分母n的增加,MA 指标的局部波动显著减小(即平滑性越来越好),但趋势跟随也出现了越来越高的延迟。
import dai
# ---------------------------------------------------------------------------新版 AIStudio 开发环境暂不支持
# 默认导入,需要手动导入相关模块,请在当前或上方代码块中添加如下代码:
from bigdatasource.api import DataSource
df=dai.query("""
SELECT *
FROM cn_stock_index_bar1d
WHERE date > '2020-01-01';
""").df()
# df1=df[df['name']=='科创50指数']
df=df[df['instrument']=='000300.SH']
print(df)
#df.instrument = df.instrument.str.replace("SHI", "SH")
#ds = DataSource.write_df(df)
/home/aiuser/.local/lib/python3.8/site-packages/numpy/core/getlimits.py:500: UserWarning: The value of the smallest subnormal fortype is zero. setattr(self, word, getattr(machar, word).flat[0]) /home/aiuser/.local/lib/python3.8/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. return self._float_to_str(self.smallest_subnormal) /home/aiuser/.local/lib/python3.8/site-packages/numpy/core/getlimits.py:500: UserWarning: The value of the smallest subnormal for type is zero. setattr(self, word, getattr(machar, word).flat[0]) /home/aiuser/.local/lib/python3.8/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. return self._float_to_str(self.smallest_subnormal)
date instrument name pre_close open high \ 2 2020-01-02 000300.SH 沪深300指数 4096.5821 4121.3487 4172.6555 12 2020-01-03 000300.SH 沪深300指数 4152.2408 4161.2185 4164.2989 22 2020-01-06 000300.SH 沪深300指数 4144.9649 4120.5211 4170.6384 32 2020-01-07 000300.SH 沪深300指数 4129.2954 4137.4019 4161.2504 42 2020-01-08 000300.SH 沪深300指数 4160.2274 4139.6315 4149.8130 ... ... ... ... ... ... ... 8965 2023-07-31 000300.SH 沪深300指数 3992.7400 4018.8900 4064.3600 8976 2023-08-01 000300.SH 沪深300指数 4014.6300 4009.1800 4031.7000 8987 2023-08-02 000300.SH 沪深300指数 3998.0000 3985.7000 4008.3300 8998 2023-08-03 000300.SH 沪深300指数 3969.9000 3962.1300 4005.0000 9009 2023-08-04 000300.SH 沪深300指数 4004.9800 4033.7200 4058.2400 low close volume amount change change_ratio 2 4121.3487 4152.2408 18211677200 2.701055e+11 55.6587 0.0136 12 4131.8640 4144.9649 14282624400 2.152163e+11 -7.2759 -0.0018 22 4102.3796 4129.2954 17530995300 2.501821e+11 -15.6695 -0.0038 32 4135.0972 4160.2274 13948903100 1.963891e+11 30.9320 0.0075 42 4101.9801 4112.3172 16758585000 2.124063e+11 -47.9102 -0.0115 ... ... ... ... ... ... ... 8965 4002.0800 4014.6300 199606800 3.665440e+11 21.8900 0.0055 8976 3983.0300 3998.0000 142286900 2.556210e+11 -16.6300 -0.0041 8987 3958.5100 3969.9000 125855700 2.048760e+11 -28.1100 -0.0070 8998 3962.1300 4004.9800 129006600 2.248100e+11 35.0900 0.0088 9009 4011.6200 4020.5800 178267200 3.165300e+11 15.6000 0.0039 [871 rows x 12 columns]
import bigcharts
from bigcharts import opts
data=df
bigcharts.Chart(
data=data[-100:],
type_="kline"
).render()
因此,在使用 MA 指标进行趋势跟踪时,容易出现“跟不紧”甚至“跟不上”的 情况。本篇低延迟趋势线 LLT 指标(Low-lag Trendline),通过信号处理理论中的一些滤波方法,克服了 MA 指标的上述缺点,可以实现低延迟趋势跟踪。
低延迟趋势线 LLT 的构造
import matplotlib.pyplot as plt
import pandas as pd
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
price_df=df
for i in [5,10,30,60]:
price_df['MA_{}'.format(i)] = price_df['close'].rolling(i).mean()
price_df[['close','MA_5','MA_10','MA_30',"MA_60"]].plot(figsize=(18,8),title='传统MA均线指标')
plt.show()
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans. /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 20256 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 32479 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 22343 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 32447 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25351 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 26631 missing from current font. font.set_text(s, 0.0, flags=flags) findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans. /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 20256 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 32479 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 22343 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 32447 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25351 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 26631 missing from current font. font.set_text(s, 0, flags=flags)
import pandas as pd
def cal_LLT(price: pd.Series, alpha: float):
LLT = []
price_value = price.values
LLT.append(price_value[0])
LLT.append(price_value[1])
for i, e in enumerate(price_value):
if i > 1:
v = (alpha - alpha**2 / 4) * e + (alpha**2 / 2) * price_value[i - 1] - (
alpha - 3 * (alpha**2) / 4) * price_value[i - 2] + 2 * (
1 - alpha) * LLT[i - 1] - (1 - alpha)**2 * LLT[i - 2]
LLT.append(v)
return LLT
# 计算EMA
price_df['EMA'] = price_df['close'].ewm(alpha=0.05,adjust=False).mean()
# 画图
plt.rcParams['font.family']='serif'
price_df['MA30'] = price_df['close'].rolling(30).mean()
price_df['LLT'] = cal_LLT(price_df['close'],0.05)
price_df[['close','MA30','LLT','EMA']].plot(figsize=(18,8),title='Comparison of various trend lines')
plt.show()
对比传统 MA 均线指标、EMA 指标、修正 EMA 指标,以及低延迟趋势线 LLT 指标, 可以看出,相对其他趋势线指标,LLT 具有更显著的拐点和更低的延迟
对于低延迟趋势线 LLT,可以看出,无论 𝛼 取多少,其零频附近的延迟都接近于零; 随着频率增大至截止频率,其延迟也都低于 MA 及 EMA 指标。不过 LLT 趋势线仍然具有“ 𝛼 越小, 延迟越高,平滑性越好”的特点。分别计算 𝛼 0.01,0.01,0.03------0.1
price_df=df[-300:]
import numpy as np
data=pd.DataFrame()
data['close']=price_df['close']
data['EMA']=price_df['EMA']
for i in np.linspace(0.01,0.1,10):
data['alpha_{}'.format(i)]=cal_LLT(data['close'],i)
data.plot(figsize=(18,8))
plt.show()
import bigcharts
from bigcharts import opts
data=df
bigcharts.Chart(
data=data,
type_="kline"
).render()
基于 LLT 趋势线的交易性择时 由于 LLT 趋势线中有且仅有参数 𝛼 ,因此我们有必要对这一参数进行较为细致的研究。 𝛼 参数等价于 EMA 指标的计算中用到了多少个交易日d 的历史价格数据。因此,我们这里选择d等于20 到 90 的情况(窗口间隔为 10 个交易日),分别计算了多、空双向交易的累积收益情况(未考虑交易成本),回测标的(上证指数)和回测时间不变: a=1/d+1
# alpha
alpha_all = [2/(d+1) for d in range(20,91,10)]
for a in alpha_all:
price_df[f'LLT(%0.5s)'%a] = cal_LLT(price_df['close'],a)
print(price_df)
/tmp/ipykernel_324/3393508058.py:5: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy price_df[f'LLT(%0.5s)'%a] = cal_LLT(price_df['close'],a)
date instrument name pre_close open high \ 5720 2022-05-17 000300.SH 沪深300指数 3956.5378 3961.7605 4005.8934 5731 2022-05-18 000300.SH 沪深300指数 4005.8934 4015.0134 4017.3410 5742 2022-05-19 000300.SH 沪深300指数 3991.9069 3938.2964 3999.5984 5753 2022-05-20 000300.SH 沪深300指数 3999.5984 4020.8162 4077.6016 5764 2022-05-23 000300.SH 沪深300指数 4077.5998 4080.9694 4080.9694 ... ... ... ... ... ... ... 8965 2023-07-31 000300.SH 沪深300指数 3992.7400 4018.8900 4064.3600 8976 2023-08-01 000300.SH 沪深300指数 4014.6300 4009.1800 4031.7000 8987 2023-08-02 000300.SH 沪深300指数 3998.0000 3985.7000 4008.3300 8998 2023-08-03 000300.SH 沪深300指数 3969.9000 3962.1300 4005.0000 9009 2023-08-04 000300.SH 沪深300指数 4004.9800 4033.7200 4058.2400 low close volume amount ... MA30 \ 5720 3955.1018 4005.8934 10966145400 2.101175e+11 ... 4055.741777 5731 3964.7503 3991.9069 10807423300 2.018007e+11 ... 4047.002043 5742 3933.7452 3999.5984 11629342000 2.102067e+11 ... 4039.568763 5753 4020.8162 4077.5998 14706917300 2.656091e+11 ... 4032.950157 5764 4029.0846 4053.9823 13047781000 2.259815e+11 ... 4025.954863 ... ... ... ... ... ... ... 8965 4002.0800 4014.6300 199606800 3.665440e+11 ... 3876.077933 8976 3983.0300 3998.0000 142286900 2.556210e+11 ... 3877.232903 8987 3958.5100 3969.9000 125855700 2.048760e+11 ... 3878.532640 8998 3962.1300 4004.9800 129006600 2.248100e+11 ... 3881.224050 9009 4011.6200 4020.5800 178267200 3.165300e+11 ... 3886.442307 LLT LLT(0.095) LLT(0.064) LLT(0.048) LLT(0.039) \ 5720 3890.536102 4005.893400 4005.893400 4005.893400 4005.893400 5731 3891.066733 3991.906900 3991.906900 3991.906900 3991.906900 5742 3891.504395 3979.935815 3979.296423 3978.964968 3978.762183 5753 3896.391092 3978.246732 3973.768515 3971.423978 3969.981899 5764 3903.842062 3982.467572 3972.652771 3967.381117 3964.094078 ... ... ... ... ... ... 8965 3863.953408 3901.728800 3877.702448 3862.890842 3856.775365 8976 3876.922711 3922.662242 3893.717036 3875.571311 3866.967809 8987 3886.742443 3936.398417 3905.361292 3885.200602 3874.853898 8998 3896.192408 3948.723011 3916.321702 3894.484677 3882.572415 9009 3907.451445 3963.874771 3929.426446 3905.548316 3891.826668 LLT(0.032) LLT(0.028) LLT(0.024) LLT(0.021) 5720 4005.893400 4005.893400 4005.893400 4005.893400 5731 3991.906900 3991.906900 3991.906900 3991.906900 5742 3978.625328 3978.526748 3978.452355 3978.394222 5753 3969.005387 3968.300343 3967.767390 3967.350377 5764 3961.849196 3960.218894 3958.981270 3958.009741 ... ... ... ... ... 8965 3856.813491 3859.949802 3863.651783 3866.134562 8976 3865.104889 3866.792637 3869.400192 3871.063473 8987 3871.558764 3872.114973 3873.854079 3874.865765 8998 3877.944166 3877.425658 3878.329140 3878.708016 9009 3885.683443 3883.946211 3883.896092 3883.543479 [300 rows x 27 columns]
采用切线法:通过向前差分计算,我们可以在每个交易日结束后得到 LLT 趋势线在该点处切线的斜率k。当k>0时,看多市场;当 k<0时,看空市场;当k=0时,维持之前的方向判断。
# 计算llt的差值
## 不同的差分日期期对收益也会有影响
diff_llt = price_df[[f'LLT(%0.5s)'%(2/(d+1)) for d in range(20,91,10)]].diff().shift(1)
# 1为多头,-1为空头
cond = ((diff_llt>0)*1+(diff_llt<0)*-1)
# 计算收益率
ret_sreies = price_df['close'].pct_change()
ret_shape = np.broadcast_to(np.expand_dims(ret_sreies.values,1),diff_llt.shape)
# 计算策略收益
strategy_ret = cond*ret_shape
# 计算净值
strategy_cum = (1+strategy_ret).cumprod()
print(strategy_ret)
LLT(0.095) LLT(0.064) LLT(0.048) LLT(0.039) LLT(0.032) LLT(0.028) \ 5720 NaN NaN NaN NaN NaN NaN 5731 -0.000000 -0.000000 -0.000000 -0.000000 -0.000000 -0.000000 5742 -0.001927 -0.001927 -0.001927 -0.001927 -0.001927 -0.001927 5753 -0.019502 -0.019502 -0.019502 -0.019502 -0.019502 -0.019502 5764 0.005792 0.005792 0.005792 0.005792 0.005792 0.005792 ... ... ... ... ... ... ... 8965 0.005482 0.005482 0.005482 0.005482 0.005482 0.005482 8976 -0.004142 -0.004142 -0.004142 -0.004142 -0.004142 -0.004142 8987 -0.007029 -0.007029 -0.007029 -0.007029 -0.007029 -0.007029 8998 0.008836 0.008836 0.008836 0.008836 0.008836 0.008836 9009 0.003895 0.003895 0.003895 0.003895 0.003895 0.003895 LLT(0.024) LLT(0.021) 5720 NaN NaN 5731 -0.000000 -0.000000 5742 -0.001927 -0.001927 5753 -0.019502 -0.019502 5764 0.005792 0.005792 ... ... ... 8965 0.005482 0.005482 8976 -0.004142 -0.004142 8987 -0.007029 -0.007029 8998 0.008836 0.008836 9009 0.003895 0.003895 [300 rows x 8 columns]
#LLT采用切线法开平仓
strategy_cum.plot(figsize=(18,8),title='LLT adopts tangent method to open and close positions')
plt.show()
#安装第三方库
!pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package akshare
序号 代码 名称 现价 涨跌幅 涨跌 涨速 换手 量比 振幅 成交额 \ 0 1 688023 安恒信息 172.1 2.83 4.73 -0.16 0.76 1.02 3.59 1.02亿 1 2 688256 寒武纪 172.86 2.76 4.65 -0.08 3.15 1.02 3.96 13.14亿 2 3 301316 慧博云通 33.3 9.9 3.0 0.85 76.29 1.98 15.48 9.45亿 3 4 301085 亚康股份 64.39 4.51 2.78 0.09 15.87 2.81 9.04 3.26亿 4 5 300624 万兴科技 94.73 2.05 1.9 0.0 6.08 0.92 2.98 6.89亿 .. ... ... ... ... ... ... ... ... ... ... ... 134 135 601116 三江购物 13.32 -3.34 -0.46 0.0 3.96 0.67 4.35 2.94亿 135 136 688215 瑞晟智能 35.9 -1.29 -0.47 0.0 1.68 0.85 2.5 0.10亿 136 137 301017 漱玉平民 19.18 -3.86 -0.77 0.05 2.1 1.31 4.26 0.44亿 137 138 301366 一博科技 38.03 -2.29 -0.89 -0.03 12.02 0.9 2.21 1.60亿 138 139 688608 恒玄科技 124.39 -1.88 -2.38 -0.09 1.42 1.06 3.36 1.42亿 流通股 流通市值 市盈率 0 0.79亿 135.31亿 -- 1 2.44亿 422.05亿 -- 2 0.37亿 12.21亿 256.75 3 0.32亿 20.49亿 61.44 4 1.20亿 114.01亿 156.37 .. ... ... ... 134 5.48亿 72.95亿 42.20 135 0.16亿 5.72亿 100.74 136 1.09亿 20.96亿 30.11 137 0.35亿 13.26亿 63.54 138 0.79亿 98.76亿 -- [139 rows x 14 columns]
#买入持有,不进行择时操作
import quantstats as qs
strategy_ret['date']=pd.to_datetime(price_df['date'])
strategy_ret.index=strategy_ret['date']
qs.reports.full(strategy_ret['LLT(0.095)'])
Strategy ------------------------- ---------- Start Period 2022-05-18 End Period 2023-08-04 Risk-Free Rate 0.0% Time in Market 100.0% Cumulative Return -2.64% CAGR﹪ -1.51% Sharpe -0.06 Prob. Sharpe Ratio 47.34% Smart Sharpe -0.06 Sortino -0.09 Smart Sortino -0.08 Sortino/√2 -0.06 Smart Sortino/√2 -0.06 Omega 0.99 Max Drawdown -16.12% Longest DD Days 186 Volatility (ann.) 15.98% Calmar -0.09 Skew 0.0 Kurtosis 0.88 Expected Daily % -0.01% Expected Monthly % -0.17% Expected Yearly % -1.33% Kelly Criterion -0.5% Risk of Ruin 0.0% Daily Value-at-Risk -1.66% Expected Shortfall (cVaR) -1.66% Max Consecutive Wins 5 Max Consecutive Losses 6 Gain/Pain Ratio -0.01 Gain/Pain (1M) -0.04 Payoff Ratio 1.04 Profit Factor 0.99 Common Sense Ratio 1.05 CPC Index 0.5 Tail Ratio 1.07 Outlier Win Ratio 3.18 Outlier Loss Ratio 3.27 MTD 0.15% 3M -3.14% 6M -12.33% YTD -7.0% 1Y -10.79% 3Y (ann.) -1.51% 5Y (ann.) -1.51% 10Y (ann.) -1.51% All-time (ann.) -1.51% Best Day 3.27% Worst Day -3.58% Best Month 9.62% Worst Month -6.17% Best Year 4.7% Worst Year -7.0% Avg. Drawdown -4.2% Avg. Drawdown Days 34 Recovery Factor 0.07 Ulcer Index 0.07 Serenity Index -0.01 Avg. Up Month 3.57% Avg. Down Month -3.71% Win Days % 48.66% Win Month % 50.0% Win Quarter % 33.33% Win Year % 50.0%
#指数的分析
price_df.index=pd.to_datetime(price_df['date'])
qs.reports.full(price_df['close'].pct_change())
Strategy ------------------------- ---------- Start Period 2022-05-17 End Period 2023-08-03 Risk-Free Rate 0.0% Time in Market 100.0% Cumulative Return 1.22% CAGR﹪ 0.69% Sharpe 0.14 Prob. Sharpe Ratio 56.22% Smart Sharpe 0.14 Sortino 0.22 Smart Sortino 0.21 Sortino/√2 0.15 Smart Sortino/√2 0.15 Omega 1.02 Max Drawdown -21.96% Longest DD Days 395 Volatility (ann.) 16.02% Calmar 0.03 Skew 0.43 Kurtosis 0.84 Expected Daily % 0.0% Expected Monthly % 0.08% Expected Yearly % 0.61% Kelly Criterion 1.1% Risk of Ruin 0.0% Daily Value-at-Risk -1.65% Expected Shortfall (cVaR) -1.65% Max Consecutive Wins 7 Max Consecutive Losses 6 Gain/Pain Ratio 0.02 Gain/Pain (1M) 0.08 Payoff Ratio 1.16 Profit Factor 1.02 Common Sense Ratio 1.07 CPC Index 0.56 Tail Ratio 1.04 Outlier Win Ratio 3.47 Outlier Loss Ratio 3.27 MTD -0.24% 3M -0.6% 6M -4.21% YTD 3.44% 1Y -2.48% 3Y (ann.) 0.69% 5Y (ann.) 0.69% 10Y (ann.) 0.69% All-time (ann.) 0.69% Best Day 3.58% Worst Day -2.93% Best Month 9.81% Worst Month -7.78% Best Year 3.44% Worst Year -2.15% Avg. Drawdown -3.47% Avg. Drawdown Days 46 Recovery Factor 0.12 Ulcer Index 0.11 Serenity Index 0.01 Avg. Up Month 5.19% Avg. Down Month -3.64% Win Days % 46.82% Win Month % 43.75% Win Quarter % 66.67% Win Year % 50.0%
plt.figure(figsize=(10,6))
plt.title('不同d参数下的LLT趋势择时累积收益率')
plt.bar(x=[f'd=%s'%x for x in range(20,91,10)],height=(strategy_cum.iloc[-1]-1).values)
plt.show()
/usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 19981 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21516 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21442 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25968 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 19979 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 30340 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 36235 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21183 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25321 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 26102 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 32047 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 31215 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25910 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 30410 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 19981 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21516 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21442 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25968 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 19979 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 30340 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 36235 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21183 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25321 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 26102 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 32047 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 31215 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25910 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 30410 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0, flags=flags)
# 计算斜率
def cal_shope(arr):
return np.mean(arr[1:])/np.mean(arr[:-1])
# 计算LLT的每日斜率进行开平仓
shope_df = price_df[[f'LLT(%0.5s)' % (2 / (d + 1)) for d in range(20, 91, 10)
]].rolling(22).apply(
cal_shope, raw=True)
cond = (shope_df > 1) * 1 + (shope_df < 1) * -1
strategy_ret_a = cond * ret_shape
strategy_cum_a = (1 + strategy_ret_a).cumprod()
strategy_cum_a.plot(figsize=(18,8),title='LLT斜率开平仓')
plt.show()
/usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 26012 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 24320 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 24179 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 20179 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 26012 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 24320 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 24179 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 20179 missing from current font. font.set_text(s, 0, flags=flags)
plt.figure(figsize=(10,6))
plt.title('不同d参数下的LLT趋势择时累积收益率')
/usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 19981 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21516 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21442 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25968 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 19979 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 30340 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 36235 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 21183 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25321 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 26102 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 32047 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 31215 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 25910 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 30410 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0.0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 19981 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21516 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21442 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25968 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 19979 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 30340 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 36235 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 21183 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25321 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 26102 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 32047 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 31215 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 25910 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 30410 missing from current font. font.set_text(s, 0, flags=flags) /usr/local/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 29575 missing from current font. font.set_text(s, 0, flags=flags)
plt.bar(x=[f'd=%s'%x for x in range(20,91,10)],height=(strategy_cum_a.iloc[-1]-1).values)