Skip to main content

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 Exercises29,460 Learners4400 XPFinance Fundamentals TrackQuantitative Analyst Track

Create Your Free Account



By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA. You confirm you are at least 16 years old (13 if you are an authorized Classrooms user).

Loved by learners at thousands of companies

Course Description

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.

  1. 1

    The Building Blocks


    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.

    Play Chapter Now
    Welcome to the course
    50 xp
    Getting a grasp of the basics
    50 xp
    Get a feel for the data
    100 xp
    The portfolio weights
    50 xp
    Calculating portfolio weights when component values are given
    100 xp
    The weights of an equally weighted portfolio
    50 xp
    The weights of a market capitalization-weighted portfolio
    100 xp
    The portfolio return
    50 xp
    Calculation of portfolio returns
    100 xp
    From simple to gross and multi-period returns
    50 xp
    The asymmetric impact of gains and losses
    50 xp
    50 xp
    Buy-and-hold versus (daily) rebalancing
    50 xp
    The time series of asset returns
    100 xp
    The time series of portfolio returns
    100 xp
    The time series of weights
    100 xp
  2. 2

    Analyzing Performance

    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.

    Play Chapter Now

In the following tracks

Finance FundamentalsQuantitative Analyst


loreLore Dirick
Kris Boudt Headshot

Kris Boudt

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.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA