Learn R Programming

PortfolioTesteR (version 0.1.4)

plot.wf_optimization_result: Plot Walk-Forward Results

Description

Visual diagnostics for a wf_optimization_result returned by run_walk_forward(). Supported types:

  • "parameters": best parameter values chosen per window.

  • "is_oos": in-sample vs out-of-sample scores by window.

  • "equity": stitched out-of-sample equity curve.

  • "drawdown": drawdown of the stitched OOS curve.

  • "windows": per-window bar/line chart of an OOS metric (see metric).

  • "stability": summary of parameter stability.

  • "distributions": distributions of IS/OOS scores across windows.

Usage

# S3 method for wf_optimization_result
plot(
  x,
  y = NULL,
  type = c("parameters", "is_oos", "equity", "drawdown", "windows", "stability",
    "distributions"),
  param = NULL,
  metric = NULL,
  main = NULL,
  sub = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

Value

Invisibly, a small list describing the plot.

Arguments

x

A wf_optimization_result from run_walk_forward().

y

Ignored.

type

One of "parameters","is_oos","equity","drawdown", "windows","stability","distributions".

param

Character vector of parameter names to include for "parameters"/"stability"/"distributions". If NULL, uses all.

metric

Character; column to plot for "is_oos" or "windows" (e.g., "OOS_Return" or "OOS_Score"). Ignored for other types.

main, sub, xlab, ylab

Base plotting annotations.

...

Additional plot options (type-specific).

See Also

run_walk_forward(), wf_report(), print.wf_optimization_result()

Examples

Run this code
# \donttest{
  data(sample_prices_weekly)
  b <- function(prices, params, ...) {
    weight_equally(filter_top_n(calc_momentum(prices, params$lookback),
                                params$top_n))
  }
  wf <- run_walk_forward(
    prices = sample_prices_weekly,
    grid   = list(lookback = c(8, 12, 26), top_n = c(5, 10)),
    builder = b,
    is_periods = 52, oos_periods = 26, step = 26
  )
  plot(wf, type = "parameters")
  plot(wf, type = "is_oos", metric = "OOS_Score")
# }

Run the code above in your browser using DataLab