Learn R Programming

PortfolioTesteR (version 0.1.4)

run_backtest: Run Portfolio Backtest

Description

Main backtesting engine that simulates portfolio performance over time. Handles position tracking, transaction costs, and performance calculation.

Usage

run_backtest(
  prices,
  weights,
  initial_capital = 1e+05,
  name = "Strategy",
  verbose = FALSE,
  stop_loss = NULL,
  stop_monitoring_prices = NULL
)

Value

backtest_result object with performance metrics

Arguments

prices

Price data (data.frame with Date column)

weights

Weight matrix from weighting functions

initial_capital

Starting capital (default: 100000)

name

Strategy name for reporting

verbose

Print progress messages (default: FALSE)

stop_loss

Optional stop loss percentage as decimal

stop_monitoring_prices

Optional daily prices for stop monitoring

Examples

Run this code
data("sample_prices_weekly")
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
selected <- filter_top_n(momentum, n = 10)
weights <- weight_equally(selected)
result <- run_backtest(sample_prices_weekly, weights)

Run the code above in your browser using DataLab