One of the main advantages of quantstrat package is that we can backtest strategies with multiple symbols as fast as with one symbol. The package provides fast computations for multiple symbols that allow analysts to get insights of strategies in an efficient approach. In this case study we will build a strategy that works with 9 ETFs […]

# Quantitative Finance

## Quantstrat Example in R – RSI Strategy

In this Quantstrat case study, we will create a strategy with the Relative Strength Index (RSI) indicator that gives signals related to overbought and oversold regimes. RSI Strategy Entry and Exit Signals In our strategy, we will work with the RSI signal to generate long positions only. We will analyze the strategy with 2 different exit conditions […]

## Quantstrat Example in R – EMA Crossover Strategy

Our first quantstrat example case study is based on the Exponential Moving Average (EMA) Crossover. Let’s briefly review what moving averages and crossovers are. Moving Averages A moving average is the average price of a security over a set amount of time. Moving averages smooth the price data to form a trend following indicator (TFI). Once […]

## Measuring Overall ETFs Performance

We will now plot a graph to show the accumulated returns of the ETFs over a period of time. We can do so by following the following steps: Build a dataframe with the 4 ETFs prices and a date column. Calculate daily returns and cumulative returns. The cumsum() function returns the cumulative sums (i.e. the sum of all […]

## Data Analysis with Quantmod in R

We will perform some data analysis with the 4 ETF symbols that we have loaded into the environment. This analysis consists of comparing the returns of the four ETFs, observing their correlations, getting some statistics, and trying to answer some questions such as which of the ETFs has the best performance in the whole period. […]

## Creating Charts with Quantmod

Apart from loading data from external and local sources, Quantmod is also suitable for making beautiful charts. There are three types of charts: lines, bars and candlestick. We will learn how to create these charts to show historical data for SPY index. In Quantmod, the function to create charts is called chartSeries. With the type parameter we can change the chart […]

## Downloading Data Using Quantmod Package in R

Once the quantmod package is installed and library is loaded, we can start using the library. We will start by showing some examples of how to download data from the web and load the data into the environment. Quantmod provides a very powerful function for downloading financial data from the web. This function is called […]

## Introduction to Quantmod in R

The quantmod package for R is designed to assist the quantitative traders in the development, testing, and deployment of statistics based trading models. Using quantmod, quant traders can quickly explore and build trading models. The important features of quantmod that we will use are divided into three categories: 1) downloading data, 2) charting, and 3) technical indicators and […]

## Plotting the VIX Index and TED Spread in R

In this lesson, will will look at how to create the two graphs in R. Before you start, it is important to setup your basic environment: Setup Environment Open RStudio and ensure that you have the basic setup in place. Create a new directory called ‘quantative-trading-strategies-r’ in your computer. We will use this director for […]

## Risk Indicators – VIX Index and TED Spread

There are some risks indicators that traders and investors need to watch to avoid days with high volatility. These indicators are referred to as leading risk indicators. A good example of a risk indicator is the VIX index. This index tracks the implied volatility of the stocks that compose the S&P 500 index. If VIX is higher than […]