awt_quant.forecast.stochastic package

Subpackages

Submodules

awt_quant.forecast.stochastic.pde_forecast module

class awt_quant.forecast.stochastic.pde_forecast.SPDEMCSimulator(ticker, equation, start_date='2022-01-01', end_date='2022-03-01', dt=1, num_paths=1000, plot_vol=True)[source]

Bases: object

Stochastic Process & GARCH-based Forecasting Simulator.

ticker[source]

Stock ticker symbol.

Type:

str

equation[source]

Stochastic model (CIR, GBM, Heston, OU).

Type:

str

start_date[source]

Start date for fetching historical data.

Type:

str

end_date[source]

End date for fetching historical data.

Type:

str

dt[source]

Time increment (default: 1 for daily, 1/252 for annual).

Type:

float

num_paths[source]

Number of Monte Carlo simulation paths.

Type:

int

__init__(ticker, equation, start_date='2022-01-01', end_date='2022-03-01', dt=1, num_paths=1000, plot_vol=True)[source]
download_data(train_test_split)[source]

Downloads historical stock data and splits into train-test sets.

simulate()[source]

Runs stochastic simulation based on the selected model.

backwards(strike_price, option)[source]

Calculates backward pricing probability for options.

plot_simulation()[source]

Plots the quantile paths for simulated stock price.

error_estimation(num_sim=100)[source]

Estimates the error of stock price forecasts.

backtest()[source]

Performs backtesting on the simulated data.

awt_quant.forecast.stochastic.run_simulations module

Run Stock Forecast Simulations using SPDEMCSimulator.

This script allows running single and multiple stock simulations with different configurations.

Usage:

python run_simulations.py –symbol AAPL –mode single python run_simulations.py –mode multi

awt_quant.forecast.stochastic.run_simulations.run_single_simulation(symbol)[source]

Runs a single simulation for a given stock symbol.

awt_quant.forecast.stochastic.run_simulations.run_multiple_simulations(symbols)[source]

Runs multiple simulations across different stock symbols.

awt_quant.forecast.stochastic.stochastic_likelihoods module

Negative Log-Likelihood Functions for Stochastic Models

This module provides:
  • neg_log_likelihood_ou: Log-likelihood for Ornstein-Uhlenbeck (OU) process.

  • neg_log_likelihood_cir: Log-likelihood for Cox-Ingersoll-Ross (CIR) process.

awt_quant.forecast.stochastic.stochastic_likelihoods.neg_log_likelihood_ou(params, data, dt)[source]

Computes the negative log-likelihood for the Ornstein-Uhlenbeck (OU) process.

Parameters:
  • params (tuple) – (mu, kappa, sigma) parameters.

  • data (np.ndarray) – Log-returns data.

  • dt (float) – Time step.

Returns:

Negative log-likelihood value.

Return type:

float

awt_quant.forecast.stochastic.stochastic_likelihoods.neg_log_likelihood_cir(params, data, dt)[source]

Computes the negative log-likelihood for the Cox-Ingersoll-Ross (CIR) process.

Parameters:
  • params (tuple) – (kappa, theta, sigma) parameters.

  • data (np.ndarray) – Volatility data.

  • dt (float) – Time step.

Returns:

Negative log-likelihood value.

Return type:

float

awt_quant.forecast.stochastic.stochastic_models module

class awt_quant.forecast.stochastic.stochastic_models.StochasticSimulator(num_paths, N, dt, device)[source]

Bases: object

__init__(num_paths, N, dt, device)[source]
simulate_gbm(mu, sigma, S0)[source]

Simulates Geometric Brownian Motion (GBM).

estimate_ou_parameters(data)[source]

Estimates Ornstein-Uhlenbeck (OU) process parameters via MLE.

simulate_ou(S0, data)[source]

Simulates Ornstein-Uhlenbeck (OU) process with estimated parameters.

estimate_cir_parameters(data)[source]

Estimates Cox-Ingersoll-Ross (CIR) process parameters via MLE.

simulate_cir(S0, data)[source]

Simulates Cox-Ingersoll-Ross (CIR) process with estimated parameters.

estimate_heston_parameters(cond_vol, returns)[source]

Estimates parameters for Heston model.

simulate_heston(S0, cond_vol, returns)[source]

Simulates the Heston model.

Module contents

Stochastic Models

Contains implementations of Geometric Brownian Motion (GBM), Ornstein-Uhlenbeck (OU), Cox-Ingersoll-Ross (CIR), and Heston models for financial forecasting.

class awt_quant.forecast.stochastic.StochasticSimulator(num_paths, N, dt, device)[source]

Bases: object

__init__(num_paths, N, dt, device)[source]
estimate_cir_parameters(data)[source]

Estimates Cox-Ingersoll-Ross (CIR) process parameters via MLE.

estimate_heston_parameters(cond_vol, returns)[source]

Estimates parameters for Heston model.

estimate_ou_parameters(data)[source]

Estimates Ornstein-Uhlenbeck (OU) process parameters via MLE.

simulate_cir(S0, data)[source]

Simulates Cox-Ingersoll-Ross (CIR) process with estimated parameters.

simulate_gbm(mu, sigma, S0)[source]

Simulates Geometric Brownian Motion (GBM).

simulate_heston(S0, cond_vol, returns)[source]

Simulates the Heston model.

simulate_ou(S0, data)[source]

Simulates Ornstein-Uhlenbeck (OU) process with estimated parameters.

awt_quant.forecast.stochastic.neg_log_likelihood_ou(params, data, dt)[source]

Computes the negative log-likelihood for the Ornstein-Uhlenbeck (OU) process.

Parameters:
  • params (tuple) – (mu, kappa, sigma) parameters.

  • data (np.ndarray) – Log-returns data.

  • dt (float) – Time step.

Returns:

Negative log-likelihood value.

Return type:

float

awt_quant.forecast.stochastic.neg_log_likelihood_cir(params, data, dt)[source]

Computes the negative log-likelihood for the Cox-Ingersoll-Ross (CIR) process.

Parameters:
  • params (tuple) – (kappa, theta, sigma) parameters.

  • data (np.ndarray) – Volatility data.

  • dt (float) – Time step.

Returns:

Negative log-likelihood value.

Return type:

float

awt_quant.forecast.stochastic.run_portfolio_simulation(portfolio, equation, start_date, end_date, train_test_split, num_paths=1000, plot_vol=False, plot_sim=False, num_sim=100)[source]

Runs a single portfolio simulation using the chosen stochastic differential equation.

Parameters:
  • portfolio (dict) – Dictionary containing symbols, positions, and quantities.

  • equation (str) – Chosen stochastic model (CIR, GBM, Heston, OU).

  • start_date (str) – Start date for simulation.

  • end_date (str) – End date for simulation.

  • train_test_split (float) – Ratio of training data.

  • num_paths (int) – Number of simulation paths (default: 1000).

  • plot_vol (bool) – Whether to plot volatility models (default: False).

  • plot_sim (bool) – Whether to plot individual stock simulations (default: False).

  • num_sim (int) – Number of simulations for error estimation (default: 100).

awt_quant.forecast.stochastic.compare_multiple_portfolio_simulations(portfolios, equation_classes, end_dates, forecast_periods, train_test_splits, num_paths=1000, num_sim=100, plot_vol=False, plot_sim=False)[source]

Compares multiple portfolio simulations across different stochastic models and settings.

Parameters:
  • portfolios (list[dict]) – List of portfolios with stock symbols and positions.

  • equation_classes (list[str]) – List of stochastic models to test.

  • end_dates (list[str]) – End dates for different simulations.

  • forecast_periods (list[int]) – Forecasting periods in days.

  • train_test_splits (list[float]) – Different train-test split ratios.

  • num_paths (int) – Number of Monte Carlo paths (default: 1000).

  • num_sim (int) – Number of simulations for error estimation (default: 100).

  • plot_vol (bool) – Whether to plot volatility models (default: False).

  • plot_sim (bool) – Whether to plot individual stock simulations (default: False).

Returns:

Dataframe containing forecast errors and summaries.

Return type:

pd.DataFrame

class awt_quant.forecast.stochastic.SPDEMCSimulator(ticker, equation, start_date='2022-01-01', end_date='2022-03-01', dt=1, num_paths=1000, plot_vol=True)[source]

Bases: object

Stochastic Process & GARCH-based Forecasting Simulator.

ticker

Stock ticker symbol.

Type:

str

equation

Stochastic model (CIR, GBM, Heston, OU).

Type:

str

start_date

Start date for fetching historical data.

Type:

str

end_date

End date for fetching historical data.

Type:

str

dt

Time increment (default: 1 for daily, 1/252 for annual).

Type:

float

num_paths

Number of Monte Carlo simulation paths.

Type:

int

__init__(ticker, equation, start_date='2022-01-01', end_date='2022-03-01', dt=1, num_paths=1000, plot_vol=True)[source]
backtest()[source]

Performs backtesting on the simulated data.

backwards(strike_price, option)[source]

Calculates backward pricing probability for options.

download_data(train_test_split)[source]

Downloads historical stock data and splits into train-test sets.

error_estimation(num_sim=100)[source]

Estimates the error of stock price forecasts.

plot_simulation()[source]

Plots the quantile paths for simulated stock price.

simulate()[source]

Runs stochastic simulation based on the selected model.