统计代写|r语言作业代写代做| Shiny App Sharpe Ratio

R是一种用于统计计算和图形的编程语言，由R核心团队和R统计计算基金会支持。R由统计学家Ross Ihaka和Robert Gentleman创建，在数据挖掘者和统计学家中被用于数据分析和开发统计软件。用户已经创建了软件包来增强R语言的功能。

statistics-lab™ 为您的留学生涯保驾护航 在代写r语言方面已经树立了自己的口碑, 保证靠谱, 高质且原创的统计Statistics代写服务。我们的专家在代写r语言代写方面经验极为丰富，各种代写r语言相关的作业也就用不着说。

• Statistical Inference 统计推断
• Statistical Computing 统计计算
• (Generalized) Linear Models 广义线性模型
• Statistical Machine Learning 统计机器学习
• Longitudinal Data Analysis 纵向数据分析
• Foundations of Data Science 数据科学基础

统计代写|r语言作业代写代考|Shiny App Sharpe Ratio

The Sharpe Ratio Shiny app structure should feel familiar but have a quick look at the final app in Figure $7.6$ and notice a few differences from our usual:

Because the Sharpe Ratio is best understood by comparison we chart the rolling Sharpe Ratio of our portfolio alongside that of the $S \& P 500$, plus we have added two blue value boxes. That means we need to calculate the rolling and overall Sharpe for the S\&P500 based on whatever starting date the user selects.

There are several calculations for this app and I divide them into market calculations and portfolio calculations.

In the chunks below, we run our market Sharpe Ratio equations, relying on the user-selected RFR, rolling window and starting date. The code flow runs through three reactives: market_returns (), which is used to find the market_sharpe() and the market_rolling_sharpe().
First, we get the RFR, rolling window and market returns.

统计代写|r语言作业代写代考|CAPM

By way of extraordinarily brief background, the Capital Asset Pricing Model (CAPM) is a model, created by William Sharpe, that estimates the return of an asset based on the return of the market and the asset’s linear relationship to the return of the market. That linear relationship is the stock’s beta coefficient. Beta can be thought of as the stock’s sensitivity to the market, or its riskiness with respect to the market.

CAPM was introduced back in 1964, garnered a Nobel for its creator and, like many epoch-altering theories, has been widely used, updated, criticized, debunked, revived, re-debunked, etc. Fama and French have written that CAPM “is the centerpiece of MBA investment courses. Indeed, it is often the only asset pricing model taught in these courses… [u]nfortunately, the empirical record of the model is poor.”1

Nevertheless, we will forge ahead with our analysis because calculating CAPM betas can serve as a nice template for more complex models. Plus, CAPM is still an iconic model. We will focus on one particular aspect of CAPM: beta. Beta, as we noted above, is the beta coefficient of an asset that results from regressing the returns of that asset on market returns. It captures the linear relationship between the asset and the market. For our purposes, it’s a good vehicle for exploring a reproducible flow for modeling or regressing our portfolio returns on the market returns. Even if your team prefers more nuanced models, this workflow can serve as a good base.

统计代写|r语言作业代写代考|CAPM and Market Returns

Our first step is to make a choice about which asset to use as a proxy for the market return and we will go with the SPY ETF, effectively treating the S\&P500 as the market. That makes our calculations substantively uninteresting because (1) SPY is $25 \%$ of our portfolio and (2) we have chosen assets and

a time period $(2013-2017)$ in which correlations with SPY have been high. With those caveats in mind, feel free to choose a different asset for the market return and try to reproduce this work, or construct a different portfolio that does not include SPY.

We first import prices for SPY, calculate monthly returns and save the object as market_returns_xts.We also want a tibble object of market returns for when we use the tidyverse.Since we will be regressing portfolio returns on market returns, let’s ensure that the number of portfolio returns observations is equal to the number of market returns observations.

Portfolio beta is equal to the covariance of the portfolio returns and market returns, divided by the variance of market returns. Here is the equation:
$$\beta_{\text {portfolio }}=\operatorname{cov}\left(R_{p}, R_{m}\right) / \sigma_{m}$$
We calculate covariance of portfolio and market returns with cov(), and the variance of market returns with var().
Our portfolio beta is equal to:

We can also calculate portfolio beta by finding the beta of each of our assets and then multiplying by asset weights. That is, another equation for portfolio beta is the weighted sum of the asset betas:
$$\beta_{\text {portfolio }}=\sum_{i=1}^{n} W_{i} \beta_{i}$$
We first find the beta for each of our assets and this affords an opportunity to introduce a code flow for regression analysis.

We need to regress each of our individual asset returns on the market return and use the $\operatorname{lm}$ () function for that purpose. We could do that for asset 1 with

Im(asset_return_1 market_returns_tidy\$returns), and then again for asset 2 with$1 \mathrm{~m}$(asset_return_2 market_returns_tidy$\ returns) etc. for all 5 of our assets. But if we had a 50 -asset portfolio, that would be impractical. Instead we write a code flow and use map () to regress each of our asset returns on market returns with one call.

We will start with our asset_returns_long tidy data frame and will then run nest (-asset).

统计代写|r语言作业代写代考|Shiny App Sharpe Ratio

Sharpe Ratio Shiny 应用程序结构应该感觉很熟悉，但可以快速查看图中的最终应用程序7.6并注意与我们通常的一些不同之处：

统计代写|r语言作业代写代考|CAPM

CAPM 于 1964 年推出，因其创造者而获得诺贝尔奖，并且与许多改变时代的理论一样，已被广泛使用、更新、批评、揭穿、复兴、重新揭穿等。Fama 和 French 写道，CAPM “是MBA投资课程的核心。事实上，它通常是这些课程中教授的唯一资产定价模型……[​​u]不幸的是，该模型的经验记录很差。”1

统计代写|r语言作业代写代考|CAPM and Market Returns

b文件夹 =这⁡(Rp,R米)/σ米

b文件夹 =∑一世=1n在一世b一世

Im(asset_return_1 market_returns_tidy $returns)，然后再次使用资产 21 米(asset_return_2 market_returns_tidy$回报）等我们所有的 5 项资产。但如果我们有一个 50 项资产的投资组合，那将是不切实际的。相反，我们编写了一个代码流并使用 map () 通过一次调用将我们的每个资产回报率回归到市场回报率上。

广义线性模型代考

statistics-lab作为专业的留学生服务机构，多年来已为美国、英国、加拿大、澳洲等留学热门地的学生提供专业的学术服务，包括但不限于Essay代写，Assignment代写，Dissertation代写，Report代写，小组作业代写，Proposal代写，Paper代写，Presentation代写，计算机作业代写，论文修改和润色，网课代做，exam代考等等。写作范围涵盖高中，本科，研究生等海外留学全阶段，辐射金融，经济学，会计学，审计学，管理学等全球99%专业科目。写作团队既有专业英语母语作者，也有海外名校硕博留学生，每位写作老师都拥有过硬的语言能力，专业的学科背景和学术写作经验。我们承诺100%原创，100%专业，100%准时，100%满意。

MATLAB代写

MATLAB 是一种用于技术计算的高性能语言。它将计算、可视化和编程集成在一个易于使用的环境中，其中问题和解决方案以熟悉的数学符号表示。典型用途包括：数学和计算算法开发建模、仿真和原型制作数据分析、探索和可视化科学和工程图形应用程序开发，包括图形用户界面构建MATLAB 是一个交互式系统，其基本数据元素是一个不需要维度的数组。这使您可以解决许多技术计算问题，尤其是那些具有矩阵和向量公式的问题，而只需用 C 或 Fortran 等标量非交互式语言编写程序所需的时间的一小部分。MATLAB 名称代表矩阵实验室。MATLAB 最初的编写目的是提供对由 LINPACK 和 EISPACK 项目开发的矩阵软件的轻松访问，这两个项目共同代表了矩阵计算软件的最新技术。MATLAB 经过多年的发展，得到了许多用户的投入。在大学环境中，它是数学、工程和科学入门和高级课程的标准教学工具。在工业领域，MATLAB 是高效研究、开发和分析的首选工具。MATLAB 具有一系列称为工具箱的特定于应用程序的解决方案。对于大多数 MATLAB 用户来说非常重要，工具箱允许您学习应用专业技术。工具箱是 MATLAB 函数（M 文件）的综合集合，可扩展 MATLAB 环境以解决特定类别的问题。可用工具箱的领域包括信号处理、控制系统、神经网络、模糊逻辑、小波、仿真等。