A financial simulation application implementing arithmetic Brownian motion (ABM) for stock price evolution, option pricing, and risk analysis.
Modeling the price evolution of a financial instrument in the presence of fluctuating market conditions is a critical task for many financial institutions. This application implements a numerical solution of the stochastic differential equation (SDE) for an arithmetic Brownian motion process, based on the implementation from the Oosterlee-Grzelak Book1.
Traditional Monte Carlo simulations of ABM typically use thousands to hundreds of thousands of paths across multiple time steps (e.g., 252 trading days per year). When running on the Signaloid Cloud Compute Engine, the application can replace individual samples from distributions for each path with direct computation on probability distribution representations. This allows the Signaloid platform to compute the same distribution in a single pass through the time steps, achieving results equivalent to thousands of Monte Carlo iterations.
This application can calculate:
- Stock price at maturity: Distribution of asset prices after simulation period (e.g., 252 trading days)
- European call option payoff: Distribution of call option values
- European put option payoff: Distribution of put option values
- Value at Risk (VaR): Risk metric at specified quantile (default: 5%)
- Simulated returns: Portfolio return distributions
The correct way to clone this repository to get the submodules is:
git clone --recursive git@github.com:signaloid/Signaloid-Demo-Finance-OosterleeGrzelakBookArithmeticBrownianMotionExample.gitIf you forgot to clone with --recursive and end up with empty submodule directories, you can remedy this with:
git submodule update --initTo run this application on the Signaloid Cloud Developer Platform, you need a Signaloid account. You can sign up using this link.
Once you have an account, click the "add to signaloid.io" button at the top of this README to connect this repository to the platform and run the application.
You can compile and run this application locally as a native Monte Carlo implementation using the GNU Scientific Library2 to generate samples for different input distributions.
Install dependencies (on Linux):
sudo apt-get install libgsl-dev libgslcblas0From the repository root:
cd src/
gcc -O3 -I. -I../submodules/common -I../submodules/compat main.c utilities.c ../submodules/compat/uxhw.c arithmetic-brownian-motion.c ../submodules/common/common.c -lgsl -lgslcblas -lm -o abmRun with Monte Carlo mode (required for local execution):
./abm -S 0 -M 10000This runs 10,000 Monte Carlo iterations to calculate the stock price at maturity. The results are stored in data.out where the first line contains execution time in microseconds (μs), and subsequent lines contain output sample values.
View the results:
cat data.out| Short | Long | Type | Default | Description |
|---|---|---|---|---|
-o |
--output |
string | - | Path to output CSV file |
-S |
--select-output |
int | 5 | Select specific output (0-5): 0=stock price, 1=call option, 2=put option, 3=VaR, 4=simulated returns, 5=all outputs |
-M |
--multiple-executions |
int | 1 | Number of Monte Carlo iterations (only needed for local execution) |
-T |
--time |
flag | false | Enable timing mode |
-b |
--benchmarking |
flag | false | Enable benchmarking output format |
-j |
--json |
flag | false | Output results in JSON format |
-h |
--help |
flag | false | Display help message |
| Long Option | Type | Default | Description |
|---|---|---|---|
--mean-return, --periodic-mean-return |
double | 0.05 | Periodic mean return (drift coefficient) |
--initial-value, --initial-portfolio-value |
double | 5.0 | Initial portfolio/stock value |
--volatility, --periodic-volatility |
double | 0.4 | Periodic volatility |
--strike, --strike-price |
double | 4.5 | Strike price for options |
--quantile, --quantile-probability |
double | 0.05 | Quantile probability for Value at Risk |
--maturity-time, --maturity-time-years |
double | 1.0 | Simulation time horizon in years |
--frequency, --frequency-index |
int | 0 | Time step frequency: 0=daily (252 steps/year), 1=monthly (12 steps/year), 2=yearly (1 step/year) |
Note: When running on Signaloid's platform, you don't need to set -M greater than 1. The platform's uncertainty tracking provides distribution results in a single execution.
Use the -S or --select-output option to choose which output to calculate:
Calculates the distribution of asset prices after the simulation period (default: 252 trading days for 1 year).
Example output using Signaloid's C0Pro-S core:
Calculates the European call option payoff distribution: max(S - K, 0) where S is the stock price at maturity and K is the strike price.
Example output using Signaloid's C0Pro-S core:
Calculates the European put option payoff distribution: max(K - S, 0) where K is the strike price and S is the stock price at maturity.
Example output using Signaloid's C0Pro-S core:
Calculates the Value at Risk at the specified quantile (default: 5%). VaR represents the maximum expected loss over the time horizon at a given confidence level.
Calculates the portfolio returns: final portfolio value minus initial value.
Calculates all available outputs: stock price at maturity, call option payoff, put option payoff, Value at Risk, and simulated returns.
Footnotes
-
Oosterlee, C.W. and Grzelak, L.A. 2019. Mathematical Modeling And Computation In Finance: With Exercises And Python And Matlab Computer Codes. World Scientific Publishing Company. https://books.google.com/books?id=TsPKDwAAQBAJ - Python Implementation ↩


