Introduction to Portfolio Analysis in R
Apply your finance and R skills to backtest, analyze, and optimize financial portfolios.Start Course for Free
5 Hours14 Videos57 Exercises31,311 Learners
Create Your Free Account
Loved by learners at thousands of companies
A golden rule in investing is to always test the portfolio strategy on historical data, and, once you are trading the strategy, to constantly monitor its performance. In this course, you will learn this by critically analyzing portfolio returns using the package PerformanceAnalytics. The course also shows how to estimate the portfolio weights that optimally balance risk and return. This is a data-driven course that combines portfolio theory with the practice in R, illustrated on real-life examples of equity portfolios and asset allocation problems. If you'd like to continue exploring the data after you've finished this course, the data used in the first three chapters can be obtained using the tseries-package. The code to get them can be found here. The data used in chapter 4 can be downloaded here.
The Building BlocksFree
Asset returns and portfolio weights; those are the building blocks of a portfolio return. This chapter is about computing those portfolio weights and returns in R.Welcome to the course50 xpGetting a grasp of the basics50 xpGet a feel for the data100 xpThe portfolio weights50 xpCalculating portfolio weights when component values are given100 xpThe weights of an equally weighted portfolio50 xpThe weights of a market capitalization-weighted portfolio100 xpThe portfolio return50 xpCalculation of portfolio returns100 xpFrom simple to gross and multi-period returns50 xpThe asymmetric impact of gains and losses50 xpPerformanceAnalytics50 xpBuy-and-hold versus (daily) rebalancing50 xpThe time series of asset returns100 xpThe time series of portfolio returns100 xpThe time series of weights100 xp
The history of portfolio returns reveals valuable information about how much the investor can expect to gain or lose. This chapter introduces the R functionality to analyze the investment performance based on a statistical analysis of the portfolio returns. It includes graphical analysis and the calculation of performance statistics expressing average return, risk, and risk-adjusted return over rolling estimation samples.Dimensions of portfolio performance50 xpExploring the monthly S&P 500 returns100 xpThe monthly mean and volatility100 xpThe (annualized) Sharpe ratio50 xpExcess returns and the portfolio's Sharpe ratio100 xpAnnualized mean and volatility100 xpTime-variation in portfolio performance50 xpEffect of window length choice50 xpRolling annualized mean and volatility100 xpSubperiod performance analysis and the function window100 xpNon-normality of the return distribution50 xpBalancing risk and reward50 xpDetecting non-normality using skewness and kurtosis100 xpDownside risk measures100 xpDrawdowns due to buying high, selling low100 xp
In addition to studying portfolio performance based on the observed portfolio return series, it is relevant to determine how individual (expected) returns, volatilities, and correlations interact to determine the total portfolio performance.Drivers in the case of two assets50 xpDriver 1: The assets' individual performance50 xpDriver 2: The choice of portfolio weights100 xpDriver 3: The correlation between the asset returns50 xpInterpreting correlation100 xpUsing matrix notation50 xpMaking a risk-reward scatter diagram100 xpThe covariance matrix100 xpMatrix-based calculation of portfolio mean and variance100 xpPortfolio risk budget50 xpWho did it?100 xp
Optimizing the Portfolio
We have up to now considered the portfolio weights as given. In this chapter, you learn how to determine in R the portfolio weights that are optimal in terms of achieving a target return with minimum variance, while satisfying constraints on the portfolio weights.Modern portfolio theory of Harry Markowitz50 xpMean-variance based investing in DJIA stocks50 xpExploring monthly returns of the 30 DJIA stocks100 xpFinding the mean-variance efficient portfolio100 xpEffect of the return target100 xpImposing weight constraints100 xpThe efficient frontier50 xpComputing the efficient frontier using a grid of target returns100 xpInterpreting the efficient frontier50 xpProperties of the efficient frontier50 xpThe minimum variance and maximum Sharpe ratio portfolio100 xpIn-sample vs. out-of-sample evaluation50 xpSplit-sample evaluation100 xpOut of sample performance evaluation100 xpIt ain't over100 xp
In the following tracksFinance Fundamentals in RQuantitative Analyst with R
DatasetsStock prices for Apple and MicrosoftBonds pricesCommodities pricesEquities pricesStock prices for DIJAReal estate pricesDaily prices in S&P 500
PrerequisitesIntermediate R for Finance
Kris BoudtSee More
Professor of Finance and Econometrics at VUB and VUA
Kris Boudt is professor of finance and econometrics at Ghent University, Vrije Universiteit Brussel and Amsterdam. He teaches the courses "GARCH models in R" and "Introduction to portfolio analysis in R" at DataCamp. He is a member of the Sentometrics organization. He is also affiliated with the KU Leuven and an invited lecturer at the University of Illinois in Chicago, Renmin University, Sichuan University, SWUFE and the University of Aix-Marseille. Kris Boudt obtained his PhD in 2008 for his developments in the modelling and estimation of financial risk under non-normal distribution. He has published his research in the Journal of Banking and Finance, Journal of Econometrics, Journal of Portfolio Management, Journal of Financial Econometrics, and the Review of Finance, among others. Kris Boudt received several awards for outstanding research and refereeing and is an active contributor to the open source community.
What do other learners have to say?
Join over 11 million learners and start Introduction to Portfolio Analysis in R today!
Create Your Free Account