knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
A package for backtesting and data
snoop
ing.
You can install the development version of snoop from GitHub with:
# install.packages("devtools") devtools::install_github("Reckziegel/snoop")
snoop
aims to automate routines for portfolio construction purposes inside the tiyverse
.
The current workflow is the following:
tibble
with construct_rolling_infrastructure()
construct_rebalance_infrastructure()
rebalance_portfolio()
extract_statistics()
library(snoop) # Step 0: Get the data stocks <- tibble::tibble( time = as.Date('2009-01-01') + 0:99, X = stats::rnorm(100, 0, 1), Y = stats::rnorm(100, 0, 2), Z = stats::rnorm(100, 0, 4) ) # Step 1: Rolling Infraestructure roll <- construct_rolling_infrastructure(stocks, .initial = 50) roll # Step 2: Rebalance Infraestructure rebal <- construct_rebalance_infrastructure(roll, .by = "week") rebal # information is under the hood # Step 3: Rebalance Portfolio mu_sigma <- function(.data) { # Mean Variance Strategy list(mu = colMeans(.data), sigma = stats::cov(.data)) } # Step 4: Compute the main statistics optimal <- rebalance_portfolio(rebal, mu_sigma, .strategy = "mean_variance") optimal # Step 4: Compute Statistics metrics <- extract_statistics(optimal) metrics
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.