Skip to contents

An R6 class for performing Monte Carlo simulations on financial time series data. This class provides methods for data preparation, simulation execution, and result visualization.

Details

The MonteCarlo class uses historical price data to calculate volatility and perform Monte Carlo simulations for future price movements. It leverages the C++ implementation of the Monte Carlo algorithm for efficiency.

Public fields

data

A data.table containing the historical price data.

simulation_results

A data.table containing the results of the Monte Carlo simulation.

end_prices

A data.table containing the final prices from each simulation path.

log_historical

Logical. Whether to use log returns for historical volatility calculation.

number_sims

Integer. The number of simulation paths to generate.

project_days

Integer. The number of days to project into the future.

start_date

POSIXct. The start date for the simulation (last date of historical data).

verbose

Logical. Whether to print progress messages.

Active bindings

results

A list containing simulation results and end prices.

Methods


Method new()

Create a new MonteCarlo object.

Usage

MonteCarlo$new(
  dt,
  log_historical = FALSE,
  number_sims = 1000,
  project_days = 30,
  verbose = FALSE
)

Arguments

dt

A data.table containing historical price data.

log_historical

Logical. Whether to use log returns for historical volatility calculation.

number_sims

Integer. The number of simulation paths to generate.

project_days

Integer. The number of days to project into the future.

verbose

Logical. Whether to print progress messages.


Method carlo()

Run the Monte Carlo simulation.

Usage

MonteCarlo$carlo()


Method plot_prices()

Plot the simulated price paths.

Usage

MonteCarlo$plot_prices()

Returns

A ggplot object showing the simulated price paths.


Method plot_distribution()

Plot the distribution of final prices.

Usage

MonteCarlo$plot_distribution()

Returns

A ggplot object showing the distribution of final prices.


Method plot_prices_and_predictions()

Plot historical prices and simulated future prices.

Usage

MonteCarlo$plot_prices_and_predictions()

Returns

A ggplot object showing historical and simulated prices.


Method clone()

The objects of this class are cloneable with this method.

Usage

MonteCarlo$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.