This tutorial will teach you about how to use R for portfolio analysis. We will be using various financial packages from R that will help us perform portfolio analysis. Let’s look at these packages: Quantmod Quantmod is a very powerful package that is designed for quant traders to explore and build quantitative trading models. For […]

# Portfolio Analysis in R

## Downloading Stock Data in R Using QuantMod

We will use QuantMod R package to download stock data. This allows for downloading stock data from multiple sources, although Yahoo is the default option. To start using the Quantmod library, you can install and load it in your R environment using the following commands in R console or R Studio (Preferred). Once the package […]

## Calculating Stock Returns and Portfolio Returns in R

To calculate the returns of AAPL & GOOG over the time period, you can use the Return.calculate function. This will then calculate the daily returns of AAPL and GOOG over the time period. The first day, as there is nothing to divide it by, will be NA. It generally makes sense to use this code […]

## Modern Portfolio Theory

This is a brief recap of Modern Portfolio Theory (MPT) before delving into practical applications of it. While there are many aspects of MPT, the focus will be on its application for portfolio optimisation. The origin of MPT came from a paper written by Harry Markowitz in 1952 to create an optimal portfolio. From thereon, […]

## Portfolio Optimisation in R

For this tutorial, both minimum-variance and mean-variance will be taught. The PortfolioAnalytics package will be used extensively throughout as it allows for a simple workflow for portfolio optimisations. The first part of the code is to define that a portfolio optimisation problem exists. The only variable that needs to be defined is the names of […]