Development of Optimal Investment Portfolio using Sharpe Ratio
Crawling, Pre-Processing, Statistical Computation and Application of Sharpe Ratio using R
Background
Financial market can go up and down; therefore, applying appropriate risk and achieving consistent return in a long term is most effective.
Instead of using 'instincts', the project aimed to utilize financial data and R to develop optimal investment portfolio.
Financial Concepts
The following financial concepts were implemented throughout the project:
1. Capital Asset Pricing Model (CAPM)
ER of i = rf + Beta of i *(Em - rf)
Expected return on asset i determined by risk-free asset return plus risk premium.
2. Beta
Beta = Cov(Ri, Rm) / Var(Rm)
A measure of a security's systematic risk in comparison to the market as a whole.
3. One Factor Model
SD of i^2 = (Beta of i^2) (SD of M^2) + Residual Error^2
A security's variance is determined by multiplication between a squared security's beta and market or benchmark's variance plus squared residual error.
4. Sharpe Ratio
(Ri - Rf) / SD of i
Return of a security i minus return of risk-free asset divided by standard deviation or risk of security i.The ratio underscores how well the return of an asset compensates the investor for the risk taken. The higher ratio, the better investment.
Data Acquisition
1. Data related to 10 stocks
10 stocks from New York Stock Exchange were chosen. Each represents best performing stock within its own sector in terms of return rate between 2010-01-01 to 2015-12-31. The following table highlights the chosen stocks. Each stock's daily raw prices between 2010-01-01 and 2015-12-31 were acquired.
2. Data related to S&P 500
S&P500, the benchmark, daily raw prices between 2010-01-01 and 2015-12-31 were acquired.
3. Data related to risk-free asset (U.S. T-Bill)
U.S. Treasury Bill monthly return between 2010-01-01 and 2015-12-31 were acquired.
Crawling
Using R and its packages, historical raw daily prices of each stock and S&P500 were crawled. The image below highlights the crawling process.
Crawled data of U.S. Treasury Bill monthly return between 2010-01-01 and 2015-12-31 from the following site: https://fred.stlouisfed.org/series/TB4WK/downloaddata?cid=116
PRE-PROCESSING
A function for extracting each month's last day closing price for each stock and the benchmark was developed during the project. As a result, the benchmark and 10 stock's monthly closing price between 2010-01-01 and 2015-12-31 was achieved. After securing the monthly closing price, monthly return rate was computed and processed for each stock and benchmark.
The following image shows the pre-processing using R.
Each stock and benchmark's excess return was computed by subtracting each stock and benchmark's monthly return with monthly risk free U.S. T-Bill return.
The pre-processing of excess return for each stock and benchmark is highlighted below.
Computing Market Return and Standard Deviation for Benchmark and each Stock
Using the pre-processed excess return data, the Benchmark, S&P500, average market return, standard deviations for benchmark and each stock between 2010-01-01 and 2015-12-31 were computed. These values were later utilized for return on investment model and one factor model.
The computations were conducted through R and its functions as shown below:
Computing Each Stock's Beta and Firm Specific Risk
Each stock's beta and its residual standard error, the firm specific risk, were computed after running regression of each stock's excess return against benchmark's excess return. The already pre-processed data for excess return was used. The values acquired from this regression analysis were later used for return on investment model and one factor model.
The regression analysis was conducted through R and each stock's beta as well as firm specific risk for each stock were computed as shown below:
Computing Each Stock's Expected Excess Return through the use of CAPM
The CAPM (Capital Asset Pricing Model) can be written as the following:
E(Ri) = Rf + βi * (E(Rm) – Rf).
The formula then can be re-written as the follwing:
E(Ri) – Rf =βi * (E(Rm) – Rf).
*"E(Ri) – Rf" in the formula denotes Expected Excess Return of Stock i and (E(Rm) – Rf) in the formula denotes benchmark's average excess return.
Using the above concepts, each stock's expected excess return was computed. The beta and average excess return of the market that were computed in the early steps were used in the CAPM.
The following underscores the points above:
Computing Stock Variance through the use of One Factor Model
One Factor Model underlines the following formula: σi^2= βi^2 * σM^2+ σ^2(e).
Using this model and the standard deviation of the benchmark as well as each stock's residual error or firm specific error computed in the early steps, each stock's variance was computed.
The stock variances were later used for co-variance computation.
The following highlights the points mentioned above:
After acquiring each stock's variance, beta and excess return through the use of One Factor Model, Regression Analysis and CAPM, the values were pre-processed and organized into a data table using R.
The data table highlights the organized data table after the pre-processing:
Optimal Asset Allocation based on Maximum Sharpe Ratio
Guy Yollin’s “effFrontier” and “maxSharpe” functions were used to to compute optimal allocation ratios for each asset (stock). The allocation ratios are computed so that the allocation ratios lead to maximum Sharpe Ratio. The core function that Guy Yollin uses is "portfolio.optim" in the "tseries" R package. Thus, "tseries" was loaded in memory before computing the allocation ratios.
*The R codes for Guy Yollin's "effFrontier" and "maxSharpe" functions can be found from the following source: http://www.rinfinance.com/RinFinance2009/presentations/yollin_slides.pdf
In order to utilize Guy Yollin's functions, the following steps were taken:
1. Build a Matrix of Excess Return
For instance, the matrix was built by doing the following in R:
averet <- matrix(c(0.01316866, 0.008274696, 0.004394322, 0.01610246, 0.01374298, 0.02365631, 0.02025826, 0.02780626, 0.00423415, 0.01014234), nrow=1)
*Each decimal represents each stock's excess return.
2. Build a Matrix of Stocks' Co-Variance
σij= βiβj(σM)^2
The formula above denotes Co-Variance formula and this formula was used to generate the Co-Variance Matrix.
3. Input the matrix values and compute the optimal allocation ratios using 'maxSharpe" funciton
After generating the matrix values for excess return and co-variance, the values were inserted into Guy Yollin's 'maxSharpe' function to generate the optimal allocation ratios.
The following highlights the inputs for the function and output of the function. The output of the functions underscores optimal asset allocation ratios for each stock in the investment portfolio.
Summary
The following highlights the summary of steps that were taken throughout the project.
Result
For each stock chosen from each industrial sector, optimal investment ratios using Sharpe Ratio were achieved from the project. The project result is shown below.
Testing
Using the investment ratio produced from the project, testing of the Optimal Investment Portfolio was conducted using the actual financial data. Risk-free asset (US T-Bill) rate of return between end of 2016 February and end of 2016 March was calculated and the benchmark, SP500, rate of return between the same period was computed. CAPM was used for computing the rate of returns.
Applying the investment ratios of the Optimal Investment Portfolio, the portfolio earns 9.76% return.
The following highlights the Optimal Portfolio Testing:
Conclusion
Optimal Investment Portfolio based on equity assets was generated from the project. In conjunction with financial concepts such as CAPM and Sharpe Ratio, R was utilized to conduct crawling, pre-processing and statistical analysis to produce the optimal portfolio.
Testing of the optimal portfolio was carried out and the testing revealed the optimal portfolio produced from the project will have expected return of 9.76% when anyone invests in the portfolio between February of 2016 and March of 2016.
Using the same steps used in the project, another new Optimal Investment Portfolio can be produced.
The outcome of the project and results of the testing were, however, followed assumptions such as CAPM assumptions. For example, the project assumed that markets are friction-less and there are no taxes or transaction costs when CAPM was used for computing expected return.
The following underscores and summarizes conclusion drawn from the project.
0コメント