年化60.7%,最大回撤-16.5%,RSRS标准分择时效果差不多

原创内容第653篇,专注量化投资、个人成长与财富自由。

中秋节,祝大家中秋快乐!

人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共婵娟。

今天引入RSRS来择时,看下策略效果。

图片

年化60.7%,最大回撤-16.5%,RSRS标准分择时效果差不多。

图片

numpy版本的rsrs指标计算,性能还可以:

import numpy as np

from numpy.lib.stride_tricks import as_strided as strided


def rolling_window(a: np.array, window: int):
    '生成滚动窗口,以三维数组的形式展示'
    shape = a.shape[:-1] + (a.shape[-1] - window + 1, window)
    strides = a.strides + (a.strides[-1],)
    return strided(a, shape=shape, strides=strides)


def numpy_rolling_regress(x1, y1, window: int = 18, array: bool = False):
    '在滚动窗口内进行,每个矩阵对应进行回归'
    x_series = np.array(x1)
    y_series = np.array(y1)
    # 创建一个一维数组
    dd = x_series
    x = rolling_window(dd, window)
    yT = rolling_window(y_series, window)
    y = np.array([i.reshape(window, 1) for i in yT])
    ones_vector = np.ones((1, x.shape[1]))
    XT = np.stack([np.vstack([ones_vector, row]) for row in x])  # 加入常数项
    X = np.array([matrix.T for matrix in XT])  # 以行数组表示
    reg_result = np.linalg.pinv(XT @ X) @ XT @ y  # 线性回归公示

    if array:
        return reg_result
    else:
        frame = pd.DataFrame()
        result_const = np.zeros(x_series.shape[0])
        const = reg_result.reshape(-1, 2)[:, 0]
        result_const[-const.shape[0]:] = const
        frame['const'] = result_const
        frame.index = x1.index
        for i in range(1, reg_result.shape[1]):
            result = np.zeros(x_series.shape[0])
            beta = reg_result.reshape(-1, 2)[:, i]
            result[-beta.shape[0]:] = beta
            frame[f'factor{i}'] = result
        return frame


@calc_by_symbol
def RSRS(high: pd.Series, low: pd.Series, N: int = 18, M: int = 600):
    beta_series = numpy_rolling_regress(low, high, window=N, array=True)
    beta = beta_series.reshape(-1, 2)[:, 1]

    beta_rollwindow = rolling_window(beta, M)
    beta_mean = np.mean(beta_rollwindow, axis=1)
    beta_std = np.std(beta_rollwindow, axis=1)
    zscore = (beta[M - 1:] - beta_mean) / beta_std
    len_to_pad = len(low.index) - len(zscore)
    # print(len_to_pad)
    pad = [np.nan for i in range(len_to_pad)]
    pad.extend(zscore)
    zscore = pd.Series(pad, index=low.index)

    len_to_pad = len(low.index) - len(beta)
    pad = [np.nan for i in range(len_to_pad)]
    pad.extend(beta)
    beta = pd.Series(pad, index=low.index)

    return zscore

一点感受,复杂且高大上的指标,看起来很酷,其实过拟合和失效的可能性更高。有时候,回归到简单的指标,比如均线,ATR,RSI等经典指标反而会有惊喜。

代码下载:AI量化实验室 星球,已经运行三年多,1100+会员。quantlab代码交付至5.X版本,含几十个策略源代码,因子表达式引擎、遗传算法(Deap)因子挖掘引等,每周五迭代一次。

AI量化实验室——2024量化投资的星辰大海

02 五年财务自由退休

财富的核心永远是价值创造。 

把你擅长的事情,产品化。

把你热爱的事情,变得擅长。就是这个逻辑。 

重要的事(why),这是你的价值观,是一切的原点。 

擅长的事(how), 你才能交付你的价值,这是交换规律决定的。

喜欢的事(what),唯热爱可抵岁月长。

当身边的朋友开始消费降级。

当有人已经对未来找到工作不报任何希望。

真正的考验就将开始。

你身边有否这样的朋友?

似乎他们什么都知道,从宏大叙事到八卦野史。

但似乎就是什么也没有去做。

所谓“知行合一”。可能就要解决这样的问题吧。

重要的事:自由、简单,好奇,成果。

擅长的事:逻辑,本质,分享

喜欢的事:宏观,整合创造。

限时免费,感兴趣可入)五年之约,一起出发吧!

作者:AI量化实验室(专注量化投资、个人成长与财富自由)

 扩展  •  历史文章   

• 年化收益52%,最大回撤13%,卡玛比率3.77,ETF轮动系列大有可为(附策略代码和数据下载)。

• 年化12.6%,最大回撤才2.6的债券轮动策略,卡玛比4.79,稳稳的幸福

• 年化收益61.9%,最大回撤-13.3%,卡玛比率达到4.6,ETF趋势策略优化

• AI量化实验室——2024量化投资的星辰大海

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI量化投资实验室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值