{"id":18390151,"url":"https://github.com/orlovt/optionspricingcpp","last_synced_at":"2025-08-08T05:34:06.026Z","repository":{"id":230628504,"uuid":"779838999","full_name":"orlovt/OptionsPricingCPP","owner":"orlovt","description":"High-performance C++ implementation of critical option pricing models: Black-Scholes, Binomial, Finite Difference, and Monte Carlo. ","archived":false,"fork":false,"pushed_at":"2024-03-31T00:30:43.000Z","size":66,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T06:52:34.347Z","etag":null,"topics":["binomial-pricing","black-scholes","finite-difference-method","low-latency","monte-carlo","options-pricing","options-trading"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orlovt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-30T23:23:11.000Z","updated_at":"2025-04-03T20:33:25.000Z","dependencies_parsed_at":"2024-03-31T00:33:49.233Z","dependency_job_id":null,"html_url":"https://github.com/orlovt/OptionsPricingCPP","commit_stats":null,"previous_names":["orlovt/optionspricingcpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/orlovt/OptionsPricingCPP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovt%2FOptionsPricingCPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovt%2FOptionsPricingCPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovt%2FOptionsPricingCPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovt%2FOptionsPricingCPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orlovt","download_url":"https://codeload.github.com/orlovt/OptionsPricingCPP/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovt%2FOptionsPricingCPP/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269371382,"owners_count":24406264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binomial-pricing","black-scholes","finite-difference-method","low-latency","monte-carlo","options-pricing","options-trading"],"created_at":"2024-11-06T01:46:29.358Z","updated_at":"2025-08-08T05:34:06.002Z","avatar_url":"https://github.com/orlovt.png","language":"C++","readme":"# Options Pricing in C++\n\n## Overview\nThis project implements several fundamental options pricing models in C++, offering a comprehensive toolkit for financial analysis and research. The models included are the Black-Scholes model, the Binomial model, the Finite Difference Method (FDM), and the Monte Carlo simulation method. Each model has been encapsulated within its own class, following object-oriented programming principles, to provide a clear, modular, and extensible architecture that can be easily expanded with new pricing models.\n\n## Installation\n\nTo compile and run the project, ensure you have a C++ compiler and make installed on your system. The project is structured to use a Makefile for easy compilation.\n\n```bash\n# Clone the repository\ngit clone https://github.com/orlovt/OptionsPricingCPP.git\n\n# Navigate to the project directory\ncd OptionsPricingCPP\n\n# Compile the project\nmake\n\n# Execute the program\n./price_opt\n\n# Or execute with args spotPrice, strikePrice, rfRate, annualizedVolatility, timeToMaturity, optionType \n./price_opt 100.00 100.00 0.1 0.1 1.0 call\n```\n\n## Usage\n\nThe executable `price_opt` provides a command-line interface to select and run different pricing models with predefined or user-specified parameters.\n\n```bash\n# Example usage\n./price_opt 100.00 100.00 0.1 0.1 1.0 call\n```\n\nReplace the parameters with your desired values to compute the price of an option using the selected model.\n\n## Performance Comparison and Improvement\n\n\n| Pricing Model  | Initial Time (ms) | Optimized Time (ms) | Improvement |\n|----------------|-------------------|---------------------|-------------|\n| Binomial       | 0.013708          | 0.008734            | ~36.3%      |\n| Black-Scholes  | 0.001708          | 0.000508            | ~70.3%      |\n| Monte Carlo    | 2.72567           | 0.596726            | ~78.1%      |\n\n\n- The **Binomial model** saw a reduction in execution time by approximately 36%, highlighting the impact of optimized tree traversal and usage of dynamic programing techniques, which has let to cut the number of expencive computations.\n- The **Black-Scholes model** achieved a execution time reduction of around 70%, benefiting from optimized mathematical computations, more efficient library calls and compiler changes.\n- The **Monte Carlo model** exhibited the most significant improvement with a reduction in execution time by over 78%, which can be attributed to optimized random number generation, parallelization of simulations, and variance reduction techniques.\n\n\n## Project Structure\n\n- `Makefile`: Contains rules for compiling the project.\n- `include/`: Header files for the project.\n  - `Factory/`: Contains the `PricingModelFactory` for creating model instances.\n  - `domain/`: Domain-specific classes, like `Option`.\n  - `models/`: Pricing models implementations.\n  - `util/`: Utility functions and helpers, such as mathematical functions.\n- `src/`: Source files mirroring the structure in `include/`.\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003ePricing Models\u003c/h2\u003e (click to expand)\u003c/summary\u003e\n\n\n### [Black-Scholes Model](https://www.google.com/url?sa=t\u0026source=web\u0026rct=j\u0026opi=89978449\u0026url=https://en.wikipedia.org/wiki/Black%25E2%2580%2593Scholes_model\u0026ved=2ahUKEwjQkuyalZ2FAxXltokEHTxTCxwQFnoECCkQAQ\u0026usg=AOvVaw3Y3P-LHLGDz-OHGgwisPKx)\n\nThe Black-Scholes model provides a closed-form solution for pricing European call and put options. It assumes a constant volatility and risk-free rate.\n\n**Call Option Price $`C(S, T)`$**\n$$C(S, T) = S_0 \\cdot N(d_1) - K \\cdot e^{-rT} \\cdot N(d_2)$$\n\n**Put Option Price $`P(S, T)`$**\n$$P(S, T) = K \\cdot e^{-rT} \\cdot N(-d_2) - S_0 \\cdot N(-d_1)$$\n\nwhere:\n- $` S_0 `$ is the current stock price,\n- $` K `$ is the strike price,\n- $` T `$ is the time to expiration (in years),\n- $` r `$ is the risk-free interest rate (annual rate, expressed in terms of continuous compounding),\n- $` \\sigma `$ is the volatility of the stock price (standard deviation of the stock's returns),\n- $` N(\\cdot) `$ is the cumulative distribution function of the standard normal distribution,\n\nand $` d_1 `$ and $` d_2 `$ are calculated as follows:\n\n$$d_1 = \\frac{\\ln(\\frac{S_0}{K}) + (r + \\frac{\\sigma^2}{2})T}{\\sigma\\sqrt{T}}$$\n\n$$d_2 = d_1 - \\sigma\\sqrt{T}$$\n\n\n### [Binomial Model](https://www.google.com/url?sa=t\u0026source=web\u0026rct=j\u0026opi=89978449\u0026url=https://en.wikipedia.org/wiki/Binomial_options_pricing_model\u0026ved=2ahUKEwjw98z1np2FAxVnhIkEHT4SCjcQFnoECDMQAQ\u0026usg=AOvVaw17PuzsxohClPB-jfpTJb4j)\nThe Binomial model prices options by constructing a binomial tree to model the underlying's price movements, allowing for the pricing of American options.\n\n\n1. **Step Size**: The time to expiration $` T `$ is divided into $` N `$ equal intervals of length $` \\Delta t = \\frac{T}{N} `$.\n\n2. **Up and Down Factors**: The model calculates the up ($` u `$) and down ($` d `$) factors, which represent the possible price changes in one step.\n$$u = e^{\\sigma \\sqrt{\\Delta t}}$$\n$$d = e^{-\\sigma \\sqrt{\\Delta t}}$$\nwhere $` \\sigma `$ is the volatility of the underlying asset.\n\n4. **Risk-neutral Probability**: The model uses a risk-neutral probability ($` q `$) for the price moving up, calculated as:\n$$q = \\frac{e^{r\\Delta t} - d}{u - d}$$\nwhere $` r `$ is the risk-free interest rate.\n\n**Formulas for Option Valuation**\n\nThe value of a European call or put option at each node is calculated using the formula:\n$$C = e^{-r\\Delta t} [qC_u + (1 - q)C_d]$$\n$$P = e^{-r\\Delta t} [qP_u + (1 - q)P_d]$$\nwhere $` C_u `$ and $` C_d `$ (or $` P_u `$ and $` P_d `$) are the values of the call (or put) option in the next step if the price moves up or down, respectively.\n\n\n### [Finite Difference Method (FDM)](https://www.google.com/url?sa=t\u0026source=web\u0026rct=j\u0026opi=89978449\u0026url=https://en.wikipedia.org/wiki/Finite_difference_methods_for_option_pricing%23:~:text%3DIn%2520general%252C%2520finite%2520difference%2520methods,discrete%252Dtime%2520difference%2520equations.\u0026ved=2ahUKEwi-_s3_np2FAxUoDHkGHZX7BGQQFnoECBAQAw\u0026usg=AOvVaw1MG5Om0CMwisOsxdIRuGzJ)\nThe FDM solves the Black-Scholes PDE numerically using a discretized grid over asset prices and time, applicable to various boundary conditions.\n\n\n1. **Grid Construction**: Create a grid over the domain of interest, typically the range of possible underlying asset prices and time until expiration. The grid is defined by intervals $` \\Delta S `$ for the asset price and $` \\Delta t `$ for time.\n\n2. **Discretization of the PDE**: The continuous PDE is approximated by finite differences. The choice of discretization scheme (explicit, implicit, or Crank-Nicolson) affects the stability and accuracy of the solution.\n\n3. **Initial and Boundary Conditions**: Apply the initial condition, typically the option's payoff at expiration, and boundary conditions reflecting the option's behavior as the asset price approaches zero or infinity.\n\n4. **Backward in Time Solution**: Solve the discretized equations backward in time from the known final conditions at expiration to obtain the option's price at the desired earlier time.\n\n**Fundamental Equations**\n\nThe PDE for a vanilla European option under the Black-Scholes framework is:\n$$\\frac{\\partial V}{\\partial t} + \\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial^2 V}{\\partial S^2} + rS\\frac{\\partial V}{\\partial S} - rV = 0$$\n\nWhere:\n- $` V `$ is the option price,\n- $` S `$ is the underlying asset price,\n- $` t `$ is time,\n- $` \\sigma `$ is the volatility of the underlying asset,\n- $` r `$ is the risk-free interest rate.\n\n**Discretization Example (Explicit Scheme)**\nThe time derivative can be approximated by a forward difference and the second spatial derivative by a central difference:\n$$\\frac{V^{i+1}_j - V^i_j}{\\Delta t} + \\frac{1}{2} \\sigma^2 S_j^2 \\frac{V^i_{j+1} - 2V^i_j + V^i_{j-1}}{\\Delta S^2} + rS_j\\frac{V^i_{j+1} - V^i_{j-1}}{2\\Delta S} - rV^i_j = 0$$\n\n\n\n### [Monte Carlo Simulation](https://www.google.com/url?sa=t\u0026source=web\u0026rct=j\u0026opi=89978449\u0026url=https://en.wikipedia.org/wiki/Monte_Carlo_methods_for_option_pricing\u0026ved=2ahUKEwj-jPGGn52FAxUjmIkEHbkXCYIQFnoECCQQAQ\u0026usg=AOvVaw2uPIKtB2xjy9roK_KgQuZT)\nMonte Carlo simulation estimates the price of an option by simulating the underlying asset's price path multiple times and calculating the average outcome.\n\n\n$$dS_t = \\mu S_t dt + \\sigma S_t dW_t$$\n\nwhere:\n- $` S_t `$ is the price of the asset at time $` t `$,\n- $` \\mu `$ is the expected return (drift) of the asset,\n- $` \\sigma `$ is the volatility (standard deviation) of the asset's returns,\n- $` dW_t `$ is the increment of a Wiener process (Brownian motion), representing random fluctuations.\n\n**Simulation of Price Paths**\n\nTo simulate the future price of an asset under the GBM model, the discrete counterpart of the SDE over a small time interval $` \\Delta t `$ is used:\n\n$$S_{t+\\Delta t} = S_t \\exp\\left((\\mu - \\frac{1}{2}\\sigma^2)\\Delta t + \\sigma\\sqrt{\\Delta t}Z\\right)$$\n\nwhere $` Z `$ is a random draw from the standard normal distribution $` N(0,1) `$.\n\n**Option Payoff Calculation**\n\nFor each simulated path of the underlying asset, the payoff of the option is calculated based on the option type. For example, for a European call option, the payoff at maturity $` T `$ is:\n\n$$\\text{Payoff} = \\max(S_T - K, 0)$$\n\nand for a European put option:\n\n$$\\text{Payoff} = \\max(K - S_T, 0)$$\n\nwhere $` S_T `$ is the simulated price of the underlying asset at maturity and $` K `$ is the strike price of the option.\n\n**Discounting to Present Value**\n\nThe expected payoff of the option is computed by averaging the payoffs of all simulated paths. This average is then discounted back to the present value using the risk-free interest rate $` r `$, to get the option's price:\n\n$$\\text{Option Price} = e^{-rT} \\times \\frac{1}{N} \\sum_{i=1}^{N} \\text{Payoff}_i$$\n\nwhere $` N `$ is the number of simulated paths.\n\u003c/details\u003e\n  \n## License\n\nThis project is licensed under the MIT License - see the LICENSE.md file for details.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlovt%2Foptionspricingcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forlovt%2Foptionspricingcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlovt%2Foptionspricingcpp/lists"}