MyNixOS website logo
Description

Automated Backtesting of Portfolios over Multiple Datasets.

Automated backtesting of multiple portfolios over multiple datasets of stock prices in a rolling-window fashion. Intended for researchers and practitioners to backtest a set of different portfolios, as well as by a course instructor to assess the students in their portfolio design in a fully automated and convenient manner, with results conveniently formatted in tables and plots. Each portfolio design is easily defined as a function that takes as input a window of the stock prices and outputs the portfolio weights. Multiple portfolios can be easily specified as a list of functions or as files in a folder. Multiple datasets can be conveniently extracted randomly from different markets, different time periods, and different subsets of the stock universe. The results can be later assessed and ranked with tables based on a number of performance criteria (e.g., expected return, volatility, Sharpe ratio, drawdown, turnover rate, return on investment, computational time, etc.), as well as plotted in a number of ways with nice barplots and boxplots.

portfolioBacktest

CRAN_Status_Badge CRAN Downloads CRAN Downloads Total

Automated backtesting of multiple portfolios over multiple datasets of stock prices in a rolling-window fashion. Intended for researchers and practitioners to backtest a set of different portfolios, as well as by a course instructor to assess the students in their portfolio design in a fully automated and convenient manner, with results conveniently formatted in tables and plots. Each portfolio design is easily defined as a function that takes as input a window of the stock prices and outputs the portfolio weights. Multiple portfolios can be easily specified as a list of functions or as files in a folder. Multiple datasets can be conveniently extracted randomly from different markets, different time periods, and different subsets of the stock universe. The results can be later assessed and ranked with tables based on a number of performance criteria (e.g., expected return, volatility, Sharpe ratio, drawdown, turnover rate, return on investment, computational time, etc.), as well as plotted in a number of ways with nice barplots and boxplots.

Installation

The package can be installed from CRAN or GitHub:

# install stable version from CRAN
install.packages("portfolioBacktest")

# install development version from GitHub
devtools::install_github("dppalomar/portfolioBacktest")

To get help:

library(portfolioBacktest)
help(package = "portfolioBacktest")
?portfolioBacktest

To cite portfolioBacktest in publications:

citation("portfolioBacktest")

Quick Start

Do the backtest on your own portfolio following few steps:

  • Step 1 - load package & 10 datasets
library(portfolioBacktest)
data("dataset10")
  • Step 2 - define your own portfolio
my_portfolio <- function(dataset, w_current) {
  prices <- dataset$adjusted
  N <- ncol(prices)
  return(rep(1/N, N))
}
  • Step 3 - do backtest
bt <- portfolioBacktest(my_portfolio, dataset10)
  • Step 4 - check your portfolio performance (e.g., median of the 10 individual backtests)
backtestSummary(bt)$performance
#>                            fun1
#> Sharpe ratio       1.476203e+00
#> max drawdown       8.937890e-02
#> annual return      1.594528e-01
#> annual volatility  1.218623e-01
#> Sortino ratio      2.057677e+00
#> downside deviation 8.351402e-02
#> Sterling ratio     2.122653e+00
#> Omega ratio        1.295090e+00
#> VaR (0.95)         1.101934e-02
#> CVaR (0.95)        1.789425e-02
#> rebalancing period 1.000000e+00
#> turnover           8.641594e-03
#> ROT (bps)          7.334458e+02
#> cpu time           1.230769e-03
#> failure rate       0.000000e+00

For a more detailed explanation on how to use the package with all the features, check the vignette.

Package Snapshot

This package backtests a list of portfolios over multiple datasets on a rolling-window basis, producing final results as in the following.

  • Performance table:
  • Barplot:
  • Boxplot:

Documentation

For more detailed information, please check the vignette.

Links

Package: CRAN and GitHub.

README file: GitHub-readme.

Vignette: CRAN-vignette and GitHub-vignette.

Metadata

Version

0.4.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows