# Example 1: backtesting one of the asset allocations in the package
us_60_40 <- asset_allocations$static$us_60_40
bt_us_60_40 <- backtest_allocation(us_60_40,
ETFs$Prices,
ETFs$Returns,
ETFs$risk_free)
# show table with performance metrics
bt_us_60_40$table_performance
# Example 2: creating and backtesting an asset allocation from scratch
# create a strategy that invests equally in momentum (MTUM), value (VLUE),
# low volatility (USMV) and quality (QUAL) ETFs.
factor_strat <- list(name = "EW Factors",
tickers = c("MTUM", "VLUE", "USMV", "QUAL"),
default_weights = c(0.25, 0.25, 0.25, 0.25),
rebalance_frequency = "month",
portfolio_rule_fn = "constant_weights")
# get data for tickers using getSymbols
factor_ETFs <- get_data_from_tickers(factor_strat$tickers,
starting_date = "2020-01-01")
# backtest the strategy
bt_factor_strat <- backtest_allocation(factor_strat,
factor_ETFs$P,
factor_ETFs$R)
# show table with performance metrics
bt_factor_strat$table_performance
Run the code above in your browser using DataLab