风险评估模型蒙特卡洛模型_R模型中的蒙特卡洛模型使投资
组合表现更好
风险评估模型蒙特卡洛模型
Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our , we do not endor each author’s contribution. You should not rely on an author’s works without eking professional advice. See our for details.
Towards Data Science编辑的注意事项: 尽管我们允许独⽴作者按照我们的发表⽂章,但我们不认可每位作者的贡献。您不应在未征求专业意见的情况下依赖作者的作品。有关详细信息,请参见我们的。
A common problem when evaluating a portfolio manager is that the history of returns is often so short that estimates of risk and performance measures can be highly unreliable. A similar problem occurs when testing a new trading strategy. Even if you have a fairly long history for the strategy’s performance, often you only have obrvations over a single market cycle which can make it difficult to evaluate how your strategy would have held up in other markets. If you trade stocks you have probably heard the refrain: “I’ve never en a bad back test”.
在评估投资组合经理时,⼀个常见的问题是收益的历史通常很短,以⾄于风险和绩效指标的估计可能⾮常不可靠。 测试新的交易策略时会发⽣类似的问题。 即使您对策略的执⾏历史已有很长的历史,但通常您只能在单个市场周期中观察到,这可能使您难以评估您的策略在其他市场中的表现。 如果您交易股票,您可能会听到这样的话:“我从未见过糟糕的回测”。
One method to address this deficiency is through Factor Model Monte Carlo (FMMC). FMMC can be ud to estimate a factor model bad on a t of financial and economic factors that reliably explain the returns of the fund manager. We can then simulate returns to determine how the manager would have performed in a wide variety of market environments. The end result is a model that produces considerably better estimates for risk and performance than if we simply ud the return ries available to us.
解决此缺陷的⼀种⽅法是通过因素模型蒙特卡洛(FMMC) 。 FMMC可⽤于基于⼀组可靠地解释基⾦经理收益的财务和经济因素来估计因素模型。 然后,我们可以模拟收益,以确定经理在各种市场环境中的表现。 最终结果是,与仅使⽤可⽤的收益序列相⽐,该模型可以更好地估算风险和绩效。
任务和设置 (The Task and Set Up)
For this ca study, we will be analyzing the returns for the new hedge fund Aric’s Hedge Fund; here
after known as AHF. The hedge fund ca is particularly interesting becau hedge funds can u leverage, invest in any ast class, go long or short, and u many different instruments. Hedge funds are often very cretive about their strategy and holdings. Thus, having a reliable risk model to explain the source of their returns is esntial.
在本案例研究中,我们将分析新对冲基⾦Aric's Hedge Fund的回报; 以下简称AHF 。 对冲基⾦的案例特别有趣,因为对冲基⾦可以利⽤杠杆,投资于任何资产类别,做多或做空以及使⽤许多不同的⼯具。 对冲基⾦通常对其策略和持股⾮常保密。 因此,拥有可靠的风险模型来解释其收益的来源⾄关重要。
Keep in mind that Aric’s Hedge Fund is not a real hedge fund (I’m Aric, I don’t have a hedge fund), but this is a real ries of returns. I obtained the returns for a hedge fund in operation that we invest in where I work so the results of this study are applicable to a real-world scenario.
请记住,Aric的对冲基⾦不是真正的对冲基⾦(我是Aric,我没有对冲基⾦), 但这是⼀系列真实的回报。 我获得了对冲基⾦的回报,该对冲基⾦投资于我⼯作的地⽅,因此本研究的结果适⽤于现实情况。
We have data for Aric’s Hedge Fund from January 2010 to March 2020. For the purpo of this post
and evaluating the accuracy of our model we will pretend as though AHF is pretty new to the scene and that we only have data from January 2017 through March 2020. To overcome the data deficiency, we will build a factor model on the basis of this “obrved data” and then utilize the entire data ries to evaluate the accuracy of our simulation for asssing the risk and performance statistics.
我们拥有2010年1⽉⾄2020年3⽉Aric对冲基⾦的数据。出于这篇⽂章的⽬的,并评估我们模型的准确性,我们将假装 AHF尚不成熟,并且我们仅提供2017年1⽉⾄3⽉的数据。 2020年。为克服数据不⾜,我们将在此“观察数据”的基础上建⽴⼀个因⼦模型,然后利⽤整个数据系列来评估模拟的准确性,以评估风险和绩效统计数据。
The below graph shows the cumulative return of AHF since January 2010. The data to the right of the red line reprents the “obrved period”.
下图显⽰了⾃2010年1⽉以来AHF的累计收益。红线右侧的数据代表“观察期”。
Image for post
We will be conducting the analysis in R using the extensive library of packages available therein incl
uding: and . Aside from the hedge fund returns ries, all of the factor data can be obtained freely from , the Federal Rerve Bank of St. Louis , and the ; you have to sign up for Credit Suis to access the indices, but still…free.
我们将使⽤其中提供的⼴泛的软件包库在R中进⾏分析,包括: 和 。 除了对冲基⾦收益系列以外,所有因⼦数据都可以从免费获得。 ,圣路易斯联邦储备银⾏和 ; 您必须注册瑞⼠信贷才能访问该指数,但仍然…免费。
模型估计 (Model Estimation)
A common technique in empirical finance is to explain changes in ast prices bad on a t of common risk factors. The simplest and most well-known factor model is the Capital Ast Pricing Model (CAPM) of William Sharpe. The CAPM is specified as follows:
经验⾦融中的⼀种常见技术是基于⼀组常见风险因素来解释资产价格的变化。 最简单和最著名的因素模型是William Sharpe的资本资产定价模型(CAPM)。 CAPM指定如下:
Image for post
Where:
哪⾥:的反义词是什么
ri = Return of ast ‘i’
ri =资产“ i”的收益
m = Return of market index ‘m’
m =市场指数“ m”的回报
∝= Excess return
∝ =超额收益
ẞ = Exposure to the Market Risk factor仓储业
ẞ=暴露于市场风险因素
Ɛi = Idiosyncratic error term
= i =特异误差项
Market risk, or “systematic” risk, rves as a summary measure for all of the risks to which financial asts are expod. This may include recessions, inflation, changes in interest rates, political turmoil, natural disasters, etc. Market risk is usually proxied by the returns on a large index like the S&P 500 and cannot be reduced through diversification.课本剧格式
市场风险或“系统性”风险,是⾦融资产所⾯临的所有风险的汇总度量。 这可能包括衰退,通货膨胀,利率变化,政治动荡,⾃然灾害等。市场风险通常由标普500指数等⼤型指数的回报所替代,并且⽆法通过多元化降低。
ẞ (i.e. Beta) reprents an ast’s exposure to market risk. A Beta = 1 would imply that the ast is as risky as the market, Beta >1 would imply more risk than the market, while a Beta < 1 would imply less risk.
ẞ(即Beta)代表资产的市场风险。 Beta = 1表⽰资产的风险与市场⼀样,Beta> 1的风险⽐市场⾼,⽽Beta <1的风险⽐市场低。
Ɛ is idiosyncratic risk and reprents the portion of the return that cannot be explained by the Market Risk factor.
Ɛ是特质风险,代表不能由市场风险因素解释的收益部分。
We will extend the CAPM to include additional risk factors which the literature have shown to be important for explaining ast returns. Aric’s Hedge Fund runs a complicated strategy using many different ast class and instruments so it’s certainly plausible that it would be expod to a broader t of risks beyond the traditional market index. The general form of our factor model is as follows:
我们将把CAPM扩展到包括其他风险因素,这些因素已被⽂献证明对于解释资产收益很重要。 Aric的对冲基⾦使⽤许多不同的资产类别和⼯具来执⾏⼀项复杂的策略,因此,它可能会⾯临⽐传统市场指数更⼴泛的风险。 我们的因⼦模型的⼀般形式如下:
Image for post
南山暖气片
All the above says is that returns (r) are explained by a t of risk factors j=1…k where r j is the return for factor ‘j’ and ẞ j is the exposure. Ɛ is the idiosyncratic error. Thus, if we can estimate the ẞ j, then we can leverage the long history of factor returns (r j) calculate conditional returns for AHF. Finally, if we can reasonably estimate the distribution of Ɛ then we can build randomness into AHF’s return ries. This enables us to fully capture the variety of returns that we could obrve.
上⾯所说的全部是,回报(r)由⼀组风险因⼦j = 1…k解释,其中rj是因⼦“ j”的回报,⽽ẞj是风险敞⼝。
Ɛ是特质错误。 因此,如果我们可以估计ẞj,那么我们就可以利⽤长期的要素收益率(rj)计算AHF的条件收益率。 最后,如果我们可以合理估计distribution的分布,则可以将随机性构建到AHF的收益序列中。 这使我们能够充分捕捉我们可以观察到的各种回报。
The FMMC method will take place in three parts:
FMMC⽅法将分为三个部分:
Part A: Data Acquisition, Clean Up and Processing
A部分:数据采集,清理和处理
Part B: Model Estimation
B部分:模型估算
Part C: Monte Carlo Simulation
C部分:蒙特卡洛模拟
A部分:数据采集,清理和处理 (Part A: Data Acquisition, Clean Up and Processing)西红柿豆腐汤
For the factor model I will be using a t of financial and economic variables aimed at measuring different sources of risk and return. Again, all the data ud in this study are freely available from Yahoo! Finance, the FRED Databa, and Credit Suis.
对于因⼦模型,我将使⽤⼀组⾦融和经济变量,旨在衡量风险和回报的不同来源。 同样,本研究中使⽤的所有数据均可从Yahoo!免费获得。 ⾦融,FRED数据库和瑞⼠信贷。
We’ll begin with the FRED data. Next to each variable I have placed the unique identifier that you can query from the databa.
我们将从FRED数据开始。 在每个变量旁边,我放置了可以从数据库查询的唯⼀标识符。
FRED Variables:
插入英语FRED变量:齿痕舌是什么原因
5-Year Inflation Expectations, 5-Years Forward. (T5YIFRM)
未来5年通胀预期,未来5年。 (T5YIFRM)
Term Spread: 10-Year minus 3-month Treasury Yield Spread. (T10Y3M)
期限利差:10年期减去3个⽉的美国国债收益率利差。 (T10Y3M)
Credit spread premium: Moody’s Baa corp bond yield minus 10-year Treasury yield. (BAA10Y)
信⽤利差溢价:穆迪的Baa公司债券收益率减去10年期美国国债收益率。 (BAA10Y)
3-month T-bill rate. (DGS3MO)
3个⽉期国库券利率。 (DGS3MO)
TED Spread: 3-Month LIBOR Minus 3-Month Treasury Yield. (TEDRATE)
TED利差:3个⽉伦敦银⾏同业拆借利率减去3个⽉国库券收益率。 (TEDRATE)
International bond yield: 10-Year government bond yields for Euro Area. (IRLTLT01EZM156N)
国际债券收益率:欧元区10年期政府债券收益率。 (IRLTLT01EZM156N)
Corporate Bond Total Return Index: ICE BofAML Corp bond master total return index; in levels. (BAMLCC0A0CMTRIV)
公司债券总收益指数:ICE BofAML Corp债券主总收益指数; 在⽔平上。 (BAMLCC0A0CMTRIV)
CBOE Volatility Index (i.e. the VIX). (VIXCLS)
CBOE波动率指数(即VIX)。 (VIXCLS)
CBOE Volatility Index of US 10-Year Treasuries (i.e. the Treasury VIX). (VXTYN)
美国10年期美国国债(即美国国债VIX)的CBOE波动率指数。 (VXTYN)
The FRED API leaves something to be desired and does not allow you to pull data in a consistent way. The returns of AHF are monthly so our model will need to be estimated using monthly data. However, FRED retrieves data at the highest available frequency so daily data always comes in as daily. Furthermore, the data is retrieved from the beginning of the ries, so you end up getting a lot of NAs. As such, we will need to do a little clean up before we proceed.
FRED API有⼀些不⾜之处,并且不允许您以⼀致的⽅式提取数据。 AHF的回报是每⽉的,因此我们的模型需要使⽤每⽉的数据进⾏估算。但是,FRED会以最⾼可⽤频率检索数据,因此每⽇数据始终以每⽇形式出现。 此外,数据是从本系列的开始检索的,因此您最终会获得很多NA。 因此,在继续之前,我们需要进⾏⼀些清理。
The following gments of R code show loading the identifiers into variables and parate queries to
FRED for the daily and monthly data. The daily data is cleaned and converted to a monthly frequency. I’ve tried to comment the code as much as possible so you can e what’s happening.
R代码的以下各节显⽰将标识符加载到变量中,并分别向FRED查询每⽇和每⽉数据。 每⽇数据将被清理并转换为每⽉⼀次。 我尝试了尽可能多地注释代码,以便您可以看到发⽣了什么。
The FRED data is good to go. The other t of variables that we will need are financial market indices. Growth, Value and Size indices feature prominently in ast pricing models such as the Fama-French 3-Factor Model and I take the same approach here. Returns from financial indices are obtained from the venerable Yahoo! Finance.
FRED数据很好。 我们将需要的另⼀组变量是⾦融市场指数。 增长,价值和规模指数在诸如Fama-French 3-Factor Model之类的资产定价模型中具有突出的地位,在此我采⽤相同的⽅法。 财务指数的收益来⾃古⽼的Yahoo! ⾦融。
Yahoo! Finance Variables:
雅虎! 财务变量:
Value: Rusll 1000 Value Index (^RLV)
值:罗素1000价值指数(^ RLV)
Growth: Rusll 1000 Growth Index (^RLG)
成长:罗素1000成长指数(^ RLG)
Size: Rusll 2000 Index (^RUT)
⼤⼩:罗素2000指数(^ RUT)
Market: S&P 500 Index (^GSPC)
市场:标普500指数(^ GSPC)
International: MSCI EAFE (EFA)
国际:MSCI EAFE(EFA)
Bonds: Barclays Aggregate Bond Index (AGG)
债券:巴克莱综合债券指数(AGG)
Lastly, we’ll load in the hedge fund specific indices courtesy of Credit Suis (CS). Obtaining the index requires a few extra steps as the data needs to manually downloaded to Excel from the Credit Suis website and then loaded into R. Each index corresponds to a specific hedge fund strategy.
最后,我们将根据瑞⼠信贷(CS)的数据加载对冲基⾦的特定指数。 获取索引需要⼀些额外的步骤,因为需要将数据从瑞⼠信贷⽹站⼿动下载到Excel,然后加载到R中。每个索引对应于特定的对冲基⾦策略。
Credit Suis Variables:
瑞⼠信贷变量:
Convertible Bond Arbitrage Index (CV_ARB)
可转换债券套利指数(CV_ARB)
Emerging and Frontier Markets Index (EM_MRKT)
新兴和前沿市场指数(EM_MRKT)
Equity Market Neutral Index (EQ_Neutral)
股市中性指数(EQ_Neutral)
Event Driven Index (EVT_DRV)
事件驱动索引(EVT_DRV)
Distresd Opportunities Index (DISTRESS)
苦恼机会指数(DISTRESS)
Multi-Strategy Event Driven Index (MS_EVT)
多策略事件驱动索引(MS_EVT)
临时装片Event Driven Risk Arbitrage Index (RISK_ARB)
事件驱动风险套利指数(RISK_ARB)
Fixed Income Arbitrage Index (FI_ARB)
固定收益套利指数(FI_ARB)
Global Macro Index (GL_MACRO)
全球宏观指数(GL_MACRO)
Equity Long-Short Index (EQ_LS)
股票多空指数(EQ_LS)
Managed Futures Index (MNGD_FT)
管理期货指数(MNGD_FT)
Multi-Strategy Hedge Fund Index (MS_HF)
多策略对冲基⾦指数(MS_HF)
B部分:模型估算 (Part B: Model Estimation)
Recall that for the purpo of this ca study we are “pretending” as though we only have data for AHF from January 2017 through March 2020 (i.e. the sample period). In reality we have data going back to January 2010. We will u the data in the sample period to calibrate the factor model and th
en compare the results from the simulation to the long-run risk and performance over the full period of January 2010 to March 2020.