monte_carlo

Summary: Performs a Monte Carlo simulation to model possible future equity values based on a given return distribution. This function generates multiple possible futures by iteratively sampling returns and compounding the equity value.

double[][]
monte_carlo
(,,,
ulong offset = 0
)

Parameters

return_distribution double[]

An array containing historical or simulated return percentages (e.g., daily returns).

dice_rolls int

The number of time steps (iterations) in each simulated future.

possible_futures int

The number of Monte Carlo simulations to run, representing different possible future scenarios.

offset ulong

(Optional) The number of initial time steps filled with zeros before actual simulation starts. Default is 0.

Return Value

Type: double[][]

result: A 2D double array (equity_matrix), where each row represents a simulated equity trajectory over dice_rolls steps.

Notes: - The process begins with an initial equity value of 1.0. - Returns are randomly sampled from return_distribution, scaled as percentages (return_distribution[i] / 100.0). - The function generates possible_futures different trajectories, each representing an independent equity evolution. - Uses Random(unpredictableSeed) for randomness, ensuring different sequences in each execution. - The function dynamically appends values to equity_matrix, which may cause memory reallocation. If performance is critical, preallocating arrays may be more efficient. - Monte Carlo simulations are widely used in financial risk assessment, portfolio analysis, and option pricing. - If offset > 0, the first offset steps are filled with zeros before equity growth begins, allowing for delayed start simulations.