# Portfolio Backtesting

This is my note for learning Portfolio Backtesting

## A Basic Workflow

### Step 1: load package and dataset

The main function portfolioBacktest() requires the argument dataset_list to follow a certain format: it should be a list of several individual datasets, each of them being a list of several xts objects following exactly the same date index. One of those xts objects must contain the historial prices of the stocks, but we can have additional xts objects containing other information such as volume of the stocks or index prices. The package contains a small dataset sample for illustration.

Note that each dataset contains an xts object called “adjusted”. By default, portfolioBacktest() will use such adjusted prices to calculate the portfolio return. But one can change this setting with the argument price_name in function portfolioBacktest().

## Details

### Defining Portfolios

The portfolios have to be defined in the form of function that takes as input a dataset (which will be automatically windowed during the backtesting following a rolling-window basis) containing a list of xts objects (following the format of the elements of the argument dataset_list) and returns the portfolio as a numerical of stocks. We give the examples for the quintile portfolio, the global minimum variance portfolio (GMVP), and the Markwitz mean-variance portfolio as follows (under practical constraints $w >= 0$ and $1^T w = 1$):

## Shaping your results

Select several performance measures of one specific portfolio:

Tables of several performance measures of the portfolios (classified by performance criteria):

Summary of performance measures:

## Plotting your results:

Performance table:

Barplot (provides information from summaryTable()) in a visual way:

Box Plot (probably the best way to properly compare the performance of different portfolios with a single performance measure):

Cumulative return or wealth plot a single backtest:

Portfolio allocation evolution of a particular portfolio over a particular backtest:

## Advanced Usage

### Tansaction costs

By default, transaction costs are not included in the backtesting, but the user can easily specify the cost to be used for a more realistic backtesting:

### Incorporation benchmarks

Parameter tuning in portfolio functions

### Tracing where execution errors happen

For example, let’s define a portfolio function that will throw a error:

Now, let’s pass the above portfolio function to portfolioBacktest() and see how to check the error trace:

# R

### Comments

###### Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×