CQ9节拍

股票收益建模:线性情况

by

主题
发表

2023年3月9日

介绍

在算法交易中,对市场动态有一个准确的高层次的概述是至关重要的. 在荷尔蒙替代疗法, 许多交易团队建立自己的模型,以了解其投资组合的风险和表现概况. 在这里,我们将深入研究一类特定的模型 因素模型 并理解它是如何封装资产关系的, 允许投资组合优化, 并解释了投资绩效归因.

建模

的 first step to making money 和 managing risk in the stock market is having an accurate model of where the sources of profit 和 loss are coming from. We’ll go through some basic modeling assumptions 和 introduce some ways a portfolio manager might evaluate their positions in the market. 为简单起见,假设你观察一项资产的价格$p_t$(例如, apple)在一天结束时$t$. 的 close-to-close回报 定义为:

$$
R_t = \frac{p_t}{p_{t-1}} -1
$$

我们每项资产每天都有这样的回报. 如果这些回报可以用一个简单的模型来描述,那不是很好吗? 我们的目标不是所有模型中最花哨的(比如,) 涡轮增压encabulator (返回模型),而是更简单、更可靠的东西,但并非完全不酷和微不足道. 在这里,我们将深入研究一种经过实战考验的模型,即因子模型.

建模的回报

因素模型 线性模型描述一组资产的回报,基于:

$$
\mathbf r_t = \mathbf B_t\mathbf f_t + \mathbf \epsilon_t
$$

这类似于传统的线性回归,但符号不同:

  1. $\mathbf r_t \in \mathbb{R}^n$表示资产的收益;
  2. $\mathbf B_t \in \mathbb{R}^{n \乘以m}$是 载荷矩阵;
  3. $\mathbf f_t \in \mathbb{R}^m$是的向量 因素的回报;
  4. $\mathbf\epsilon_t \in \mathbb{R}^n$是的向量 剩余(或特殊)回报.

在实践中, 对于许多资产类别,资产n的数量远远大于因子m的数量. 加载矩阵包含将要素收益与资产收益联系起来的基本信息. 和传统回归有什么不同呢 动态 的关系. 因子返回$\mathbf f_t$是随机变量, drawn in every period from a multivariate distribution which is assumed to be independent from the previous 和 next ones. 类似地,“噪声”$\mathbf \epsilon_t$是随机的,独立于因子返回. 在这里,“特殊的”仅仅意味着“资产回报不能被负载和回报所解释”.每个返回$\epsilon_{t, I}$与$\epsilon_{s无关, J}$随时间变化(当$s\ne t$)和跨资产(当$i\ne J $). We can interpret this as a graphical model from underlying factors linearly impacting each asset’s return with some weight. 为了简化符号,假设我们已经固定了$t= t $并删除了下标.

$\mathbf B$的解释是什么? 每一列都是一个资产“特征”.例如,如果股票$i$是一家科技公司,$b_{i,1}$可以取值1,否则取0. 科技公司的日收益是正相关的: google, 微软apple 经常一起活动. 对此的一种解释是,第一个因素(“科技行业”因素)正在上升或下降, 科技公司在一定程度上受到这个因素的驱动. 还有其他因素也会起作用. 例如, 有些公司比其他公司更赚钱, “盈利能力”可能是另一个因素. 和最后一个, 有一个“噪音”$\epsilon_i$:这是一个公司非常特定的东西, 就像财报公布当天的回报率一样. 当记者说“在危机中所有的相关性都趋于1”时,他们 真的 均值是“在危机中,一些因素的变化远远超过特定资产的回报, 因此,资产回报变得更加相关.”

资产回报和因素之间的这种关系似乎很直观, 但它编码了很多CQ9市场的微妙信息. 让我们看看用这个简单但功能强大的工具可以回答的一些问题!

协方差矩阵估计

拥有我们可以交易的所有资产的协方差矩阵是有用的. 为什么? 因为它允许我们估计任何投资组合的波动性. “波动率”是一个金融术语,表示“某一时间范围内某事物的标准差”.“在我们的例子中,假设我们投资了$w_1=$ - 3000万美元 汽车厂商, $w_2=$ 1000万美元 apple 等等......。. 的 vector of our net dollar holdings is $\mathbf w$ 和 the returns covariance matrix of these assets is $\mathbf\Sigma_r$. 我们投资组合的波动率是$\sqrt{\mathbf w ' \mathbf\Sigma_r \mathbf w}$. 这是我们投资组合每日美元PnL的标准差. For many reasons we want to have a first estimate of the uncertainty at short horizon: we need to be adequately funded, 我们需要为我们的摇摆设定期望. 有一个问题:$\mathbf\Sigma_r$可以 真的 big. 美洲之间, 欧洲, 和亚洲, 很容易就有10个,000年液体, 可交易资产,估计价值5000万. 这个计算同样需要n^2的运算, 这要求很高, 尤其是如果你每天要跑这么多次的话, 甚至每小时很多次.

因子模型的拯救! 如果我们知道因子收益的分布,我们就可以估计 无中心经验协方差矩阵 的因素:$ \ mathbf \ Sigma_ {\ mathbf f} = T ^ {1} \ sum_ {T = 1} ^ T f {T} \ \ mathbf mathbf f_t的美元. 这是估计因子方差和协方差的一种很好的方法, 假设因子回报均值非常小,在计算中不会产生影响. 如果我们知道特殊收益,计算就更容易了. 因为这些回报是两两不相关的, 协方差矩阵是具有项$[\mathbf\Sigma_{\epsilon}]_{i的对角矩阵,i} = \frac{1}{T} \sum_{T =1}^T\epsilon^2_{T,i}$. 现在,我们有了资产的协方差矩阵. 做一点代数运算,我们得到:

$$
\mathbf\Sigma_r = \text{Var}(\mathbf r) = \text{Var}(\mathbf B\mathbf f + \mathbf\epsilon) = \text{Var}(\mathbf B\mathbf f) + \text{Var}(\mathbf\epsilon) \mathbf =\mathbf B\mathbf\Sigma_{\mathbf f}\mathbf B’ + \mathbf\Sigma_{\mathbf\epsilon}
$$

存储这个矩阵需要$mn$个数,而不是$n^2$. 因为通常只有不到一百个因素, $m \ll n$, 这在空间上节省了2到4个数量级! 计算我们投资组合的波动性也要快得多. 因为我们想计算$\sqrt{\mathbf w ' \mathbf \Sigma_r \mathbf w}$, 我们可以首先计算向量$\mathbf b:=\mathbf b ' \mathbf w$, 哪一个需要$ $ $ $ $ $ $ $的操作. 剩下的就很快了, since computing $\mathbf b’\mathbf\Sigma_{\mathbf f}\mathbf b+ \mathbf w’\mathbf\Sigma_{\mathbf \epsilon}\mathbf w$ takes only $\sim m^2+n$ operations. 最重要的是, covariance matrices from 因素模型 often give more accurate volatility estimations than the empirical ones. [1]

优化投资组合和绩效 事前

You have developed a sophisticated prediction system based on deep learning running on a quantum computer located in the brain of the 宇宙的乌龟. 每天,它都会为你生成一个不起眼的向量$\mathbf \alpha\in\mathbb R^n$. 这样的向量包含了你的股票世界一天前的预期回报. 你会怎么做??

你可以做的一件事是找到一个能使你的盈利最大化的投资组合, 以风险单位衡量. 换句话说:你用投资组合的预期PnL除以其波动性, 最大化这个比率. 如果我们忽略了很多重要的细节,比如执行成本, 融资成本, 税收, multiperiod注意事项, 监管约束, 等.,问题可表述为:

$$
\max_{\mathbf w} \frac{\mathbf \alpha ' \mathbf w}{\sqrt{\mathbf w ' \mathbf\Sigma_r \mathbf w}}
$$

目标函数是 夏普比率 战略的和是一个常用的目标. 在实践中,它并不总是最相关的公式, 但这是解释投资组合优化的最简单、最有见地的方法之一. 因子模型有什么帮助? 的 objective function $f(\mathbf w)$ does not depend on the unit of currency: if you measure a portfolio in dollars or cents, the 夏普比率 stays the same; ditto if you fix your unit of currency, 或者通过一些常数乘数来增加或减少你的投资组合.[2] 我们可以将分母固定为某个值,比如1,从而使目标最大化, 现在是$\mathbf\alpha ' \mathbf w$:

$$
开始\{对齐}
\ max_ {\ mathbf w} \, & \mathbf \alpha \mathbf w \\
文本\{年代.t.} \,& \mathbf w ' \mathbf\Sigma_r \mathbf w\le
结束\{对齐}
$$

解是 协方差矩阵(有时称为 精度矩阵):

$$
\mathbf w^\star=\frac{\mathbf \Sigma_{\mathbf r}^{-1}\mathbf \alpha}{\sqrt{\mathbf \alpha’\mathbf \Sigma_{\mathbf r}^{-1}\mathbf \alpha}}
$$

目标函数夏普比的最优值为$\alpha ' \mathbf w^\star$,即:

$$
\text{最佳夏普比率}={\sqrt{\mathbf \alpha ' \mathbf \Sigma_{\mathbf r}^{-1}\mathbf \alpha}}
$$

This highlights the importance of estimating accurately both the covariance matrix for volatility targeting 和 the 精度矩阵 for Sharpe maximization, 它们之间有着惊人的联系.

但是,因子模型可以获得更多的见解. In the formula $\mathbf r_t = \mathbf B_t\mathbf f_t + \mathbf \epsilon_t$ we did not say anything about the expected values of $\mathbf f_t$ 和 $\mathbf \epsilon_t$. 在剩下的部分中, we can express returns as the sum of an expected value term 和 a zero-mean term: $\mathbf \mu_{\mathbf f} +\tilde{\mathbf f}_t$, $\mathbf \mu_{\mathbf \epsilon} +\tilde{\mathbf \epsilon}_t$. 的 expected returns of my asset universe are $\mathbf \alpha:=\mathbf B \mathbf \mu_{\mathbf f}+ \mu_{\mathbf \epsilon}$. This suggests that we have some degree of freedom in choosing $\mu_{\mathbf f}$ 和 美元\ mu_ {\ mathbf \ε}$. 例如, if we add a shift term $\mathbf a$ to $\mu_{\mathbf f}$ 和 I subtract a term $\mathbf B\mathbf a$ from $\mathbf \mu_{\mathbf \epsilon}$, 资产的预期收益不变. 为了消除这种不确定性, we impose that $\mathbf \mu_{\mathbf \epsilon}$ be orthogonal to the columns of $\mathbf B$; i.e., $\mathbf B ' \mathbf \mu_{\mathbf \epsilon}=0$. 当我们使用这个正交分解时,经常调用$\mathbf \mu_{\mathbf \epsilon}$ α正交 表示$\mathbf\alpha_{\perp}$,而$\mathbf\alpha_{||}:=\mathbf B\mathbf \mu_{\mathbf f}$为 α平行,因为与因子“平行”.

Now we replace $\alpha$ with $\mathbf \mu_{\mathbf \epsilon}+\mathbf B \mathbf \mu_{\mathbf f}$ in the 夏普比率 formula. 让公式简单一点, 我们假设所有的特殊波动率都等于$\sigma$. 在一些矩阵操作之后[3] 我们有一个简洁的夏普比率公式:

$$
开始\{对齐}
\ mathbf H: = & \mathbf B\ mathbf B\\
\text{夏普比率}= &\sigma^{-1}\left(|| \mu_{\mathbf \epsilon}||^2 + \mu_{\mathbf f}’ \left[ \mathbf H – \mathbf H(\sigma^2\mathbf\Sigma_{\mathbf f}^{-1} + \mathbf H )^{-1} \mathbf H’ \right] \mu_{\mathbf f} \right)^{1/2}
结束\{对齐}
$$

经风险调整后的绩效可分解为 α平行,它与由资产特征生成的PnL相关联,以及 α正交:资产的超额收益,不能用这些相同的特征来解释,是特定于资产的.

  • 在大特质风险的极限下,因子风险可以忽略不计. 结果模型简化了$\mathbf r_t=\mathbf \alpha+\sigma\tilde{\mathbf\epsilon}_t$. 在上面的公式中,夏普比率接近$\sigma^{-2}||\mathbf\alpha||^2$. 公式中没有出现因子项是不足为奇的.
  • 当特质风险较小时,SR趋于$\sigma^{-2} ||\mu_{\mathbf \epsilon}||^2$. Notice that $\lim_{\sigma\downarrow 0} SR=\infty$: if there are little excess returns that are not explainable by factors, 如果大多数风险是因素风险, 那么夏普确实可以很高. 这也许可以解释为什么很多工作都在寻找“正交”.”

理解性能 事后

控制风险是件好事,但拥有一个有利可图的策略才是好事 伟大的. 高效交易者的一个习惯是回顾他们的历史损益(或PnL)。, 了解它的起源. 假设我们有一个每周期预期收益的预测$\mathbf \alpha_t = \mathbf B \mu_{\mathbf f, T} + \mu_{\mathbf \epsilon, t}$和实际返回$\mathbf r_t = \mathbf B (\mu_{\mathbf f, t} + \波浪号{\ mathbf f} _t) + (\ mu_ {\ mathbf \ε, T} + \tilde{\epsilon}_t)$使得我们期望因子和idio返回$\mu_{\mathbf f,t}$, 美元\ mu_ {\ mathbf \ε,T}$(注意在上一节中我们假设$\alpha$是平稳的).当我们看PnL和归因于因素回报或特殊回报, 我们可以将其分解如下:

开始\{对齐} \text{PnL} =& \sum_t\text{PnL}_t \\ = &\mathbf w_t \mathbf r_t \\ = &\sum_t \mathbf w_t’\mathbf\alpha_t + \sum_t \mathbf w_t'(\mathbf B_t \tilde{\mathbf f}_t) + \sum_t \mathbf w_t’ \tilde{\mathbf \epsilon}_t \\ = & \mathbf\mu_{\mathbf f,T} + \sum_t \mathbf w_t \mathbf \mu_{\mathbf \epsilon,T} +\sum_t \mathbf b_t ' \tilde{\mathbf f}_t +\sum_t \mathbf w_t ' \tilde{\mathbf \epsilon}_t \\ \approx &\; \text{factor tilt PnL} \\ &+\text{特殊倾斜PnL} \\ &+\text{factor timing PnL}\\ &+\text{特殊计时PnL} 结束\{对齐}

当我们估计投资组合波动时,我们遇到了$\mathbf b_t \in \mathbb{R}^m$. 它被称为 因子暴露载体 在投资组合中. 对于每个因素,这是该因素特征的美元加权总和. A way to see $\mathbf b_t$ is like a low-dimensional sk等h of a high-dimensional object – instead of having to list the dollar positions in 汽车厂商, apple, GME, 哪一种既乏味又缺乏洞察力, 你可以在鸡尾酒会上告诉别人你很喜欢科技产品.e., have more long positions than short positions in tech stocks) 和 that you are also long meme stocks (or at least, 在给出一个不受欢迎的答案之前,先读一读房间里的人).

第一项是学习(或学习)产生的PnL 倾斜)转化为具有非零预期收益的因素. 第二项与此类似,但针对的是预期收益. 最后两项表示 时间的技能. 为什么时间? Because in order to have positive timing PnL we need to guess the signs right – we should have positive exposure to a factor with positive returns 和 negative exposures otherwise. 换句话说,因子暴露与因子回报之间的协方差是正的. 以下是因子计时的精确表述(idio计时也可以类似地表述):

开始\{对齐} \sum_t \mathbf b_t ' \tilde{\mathbf f}_t =& \sum_t \sum_i b_{t,i} \波浪{f}_{t,i}\\ =& T T \ sum_i \压裂{1}{}\ sum_t (b_ {T,我}\波浪号{f} _ {T,我}- E (b_ {T,我}]E [\ f {T,我波浪号 }]))    \\ =&  T \ sum_i \文本{x} (\ mathbf b_我}{\ cdot \波浪号{\ mathbf f} _ {\ cdot,我})\{对齐}结束

的 factor timing component is the sum of the time-series covariances of exposures 和 centered 因素的回报. It should not come as a surprise that the timing PnL is almost always negligible in the long run unless you have the cosmic turtle on your side.


进一步的阅读

我们只触及了这个话题的表面. 例如, 我们还没有涉及到评估问题, the connection between generalized linear models 和 alpha research (aka 的 Brain of 的 宇宙的乌龟). 对于感兴趣的读者,这里有一些有用的参考资料,按复杂程度递增:

高级投资组合管理 由Paleologo. 威利 (2021)

资产收益的因子模型 Connor和Korajczyk. 数量金融百科全书(2010)

投资组合风险分析 作者:Connor, Goldberg和Korajczyk. 普林斯顿大学出版社 (2010)

数据科学的统计基础 范,李,张,邹. CRC的新闻 (2020)

大维随机矩阵的谱分析 作者:Bai和Silverstein. 施普林格 (2017)

笔记

  1. Here is a pathological example: Choose a test portfolio $\textbf w$ that is orthogonal to each vector of historical returns $\textbf w’\textbf r_t=0$ for all $t$. 这样的投资组合保证存在,因为从估计中使用的周期数是250-500), much smaller than the number of assets (>1000). 因此,使用经验协方差矩阵预测的vol为0, 因为$\textbf w (\sum_t T^{-1}\textbf r_t\textbf r_t ') \textbf w=0$. 这是对风险的严重低估.

  2. 夏普比率是0次齐次的:对于任何正数$a$, 它是$f(a\mathbf w)=f(\mathbf w)$.

  3. 要推导结果,使用 伍德伯里的身份 对于矩阵反演. Note that even if individual idiosyncratic volatilities differ so that $\mathbf \Sigma_\epsilon \neq \sigma^2I$, this still provides a computationally efficient way of inverting the estimated covariance matrix as long as $\mathbf \Sigma_\epsilon$ is diagonal.

不要错过任何一个节拍

关注我们,了解CQ9在工程、数学和自动化方面的最新信息.