{"id":19044263,"url":"https://github.com/arturogonzalezm/equity_options","last_synced_at":"2026-04-17T06:34:27.569Z","repository":{"id":243189384,"uuid":"811726031","full_name":"arturogonzalezm/equity_options","owner":"arturogonzalezm","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-11T01:31:25.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T11:51:08.975Z","etag":null,"topics":["python3","python311","streamlit","streamlit-webapp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arturogonzalezm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-06-07T07:15:48.000Z","updated_at":"2024-06-11T01:32:59.000Z","dependencies_parsed_at":"2025-01-02T16:17:46.396Z","dependency_job_id":null,"html_url":"https://github.com/arturogonzalezm/equity_options","commit_stats":null,"previous_names":["arturogonzalezm/equity_options"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arturogonzalezm/equity_options","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturogonzalezm%2Fequity_options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturogonzalezm%2Fequity_options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturogonzalezm%2Fequity_options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturogonzalezm%2Fequity_options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arturogonzalezm","download_url":"https://codeload.github.com/arturogonzalezm/equity_options/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturogonzalezm%2Fequity_options/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31918713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"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":["python3","python311","streamlit","streamlit-webapp"],"created_at":"2024-11-08T22:45:20.986Z","updated_at":"2026-04-17T06:34:27.545Z","avatar_url":"https://github.com/arturogonzalezm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/gh/arturogonzalezm/equity_options/graph/badge.svg?token=YEtCcH8NcL)](https://codecov.io/gh/arturogonzalezm/equity_options)\n[![PyLint](https://github.com/arturogonzalezm/equity_options/actions/workflows/workflow.yml/badge.svg)](https://github.com/arturogonzalezm/equity_options/actions/workflows/workflow.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT)\n\n# Binomial Option Pricing Model\n\nThis repository contains the implementation of the Binomial Option Pricing Model for calculating the price of European call and put options. It also includes functionality to calculate the Greeks (Delta, Gamma, Vega, Theta, Rho) of the options.\n\n## BinomialOptionPricing Class\n\nThe `BinomialOptionPricing` class is used to calculate the price of a European call or put option using the binomial tree model. It also provides methods to calculate the Greeks of the option.\n\n### Initialization\n\nThe class is initialized with the following parameters:\n- `stock_price`: The current price of the underlying stock.\n- `strike_price`: The strike price of the option.\n- `time_to_expiry`: The time to expiry of the option in years.\n- `risk_free_rate`: The risk-free interest rate.\n- `volatility`: The volatility of the underlying stock.\n- `steps`: The number of steps in the binomial tree.\n- `option_type`: The type of the option (\"call\" or \"put\").\n\n```bash\npython -m pip install --upgrade pip\n```\n\n```bash\npython -m pip install -r requirements.txt\n```\n\n```bash\nstreamlit run app.py\n```\n  \n\n### Methods\n\n#### `binomial_tree`\n\nCalculates the price of the option using the binomial tree model.\n\n```python\ndef binomial_tree(self, stock_price=None, strike_price=None, time_to_expiry=None, risk_free_rate=None, volatility=None, steps=None):\n    # Parameters are optional, if not provided the class attributes will be used.\n    # Calculate the necessary parameters for the binomial model.\n    dt = time_to_expiry / steps\n    u = np.exp(volatility * np.sqrt(dt))\n    d = 1 / u\n    q = (np.exp(risk_free_rate * dt) - d) / (u - d)\n\n    # Initialize asset prices at maturity\n    asset_prices = np.zeros(steps + 1)\n    for i in range(steps + 1):\n        asset_prices[i] = stock_price * (u ** (steps - i)) * (d ** i)\n\n    # Initialize option values at maturity\n    option_values = np.zeros(steps + 1)\n    for i in range(steps + 1):\n        if self.option_type == \"call\":\n            option_values[i] = max(0, asset_prices[i] - strike_price)\n        else:\n            option_values[i] = max(0, strike_price - asset_prices[i])\n\n    # Backward induction\n    for step in range(steps - 1, -1, -1):\n        for i in range(step + 1):\n            option_values[i] = np.exp(-risk_free_rate * dt) * (q * option_values[i] + (1 - q) * option_values[i + 1])\n            asset_prices[i] = asset_prices[i] / u\n            if self.option_type == \"call\":\n                option_values[i] = max(option_values[i], asset_prices[i] - strike_price)\n            else:\n                option_values[i] = max(option_values[i], strike_price - asset_prices[i])\n\n    return option_values[0]\n```\n\n## Project Structure\n\n```sh\nequity_options/\n│\n├── backend/\n│   ├── __init__.py\n│   ├── options_facade.py\n│   └── singleton_logger.py\n│\n├── tests/\n│   ├── __init__.py\n│   ├── test_options_facade.py\n│\n├── app.py\n├── requirements.txt\n└── README.md\n```\n\n## Testing\n\nRun the unit tests using `pytest`:\n\n```sh\npytest\n```\n\n## Class Diagram\n\n```mermaid\nclassDiagram\n    class BinomialOptionPricing {\n        +float stock_price\n        +float strike_price\n        +float time_to_expiry\n        +float risk_free_rate\n        +float volatility\n        +int steps\n        +str option_type\n\n        +BinomialOptionPricing(float stock_price, float strike_price, float time_to_expiry, float risk_free_rate, float volatility, int steps, str option_type)\n        +float binomial_tree(float stock_price=None, float strike_price=None, float time_to_expiry=None, float risk_free_rate=None, float volatility=None, int steps=None)\n        +tuple~float, float, float, float, float~ calculate_greeks()\n    }\n\n    class pytest_fixture {\n        +call_option() : BinomialOptionPricing\n        +put_option() : BinomialOptionPricing\n    }\n\n    class test_binomial_tree {\n        +test_binomial_tree_call(call_option)\n        +test_binomial_tree_put(put_option)\n    }\n\n    class test_calculate_greeks {\n        +test_calculate_greeks_call(call_option)\n        +test_calculate_greeks_put(put_option)\n    }\n\n    pytest_fixture --\u003e BinomialOptionPricing : creates\n    test_binomial_tree --\u003e BinomialOptionPricing : uses\n    test_calculate_greeks --\u003e BinomialOptionPricing : uses\n\n```\n\n### Explanation\n\n- **BinomialOptionPricing**: The main class responsible for calculating the price and Greeks of an option using the binomial tree model.\n  - Attributes: `stock_price`, `strike_price`, `time_to_expiry`, `risk_free_rate`, `volatility`, `steps`, `option_type`.\n  - Methods: `__init__`, `binomial_tree`, `calculate_greeks`.\n\n- **TestBinomialOptionPricing**: The test class that contains the unit tests for the `BinomialOptionPricing` class.\n  - Methods: `test_binomial_tree_call`, `test_binomial_tree_put`, `test_calculate_greeks_call`, `test_calculate_greeks_put`.\n\n- **TestFixtures**: A helper class that provides fixtures for the unit tests.\n  - Methods: `call_option`, `put_option`.\n\n- The `TestBinomialOptionPricing` class uses the `TestFixtures` class to get instances of `BinomialOptionPricing` for testing.\n- The `TestFixtures` class creates instances of `BinomialOptionPricing`.\n\n![1](resources/images/1.png)\n![2](resources/images/2.png)\n![3](resources/images/3.png)\n\n\n\n### Summary\n\n- The `BinomialOptionPricing` class provides methods to calculate the price and Greeks of European options using the binomial tree model.\n- Unit tests are written using `pytest` to ensure the correctness of the implementation.\n- The README file explains the class, its methods, and how to run the tests.\n\n\n---\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturogonzalezm%2Fequity_options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farturogonzalezm%2Fequity_options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturogonzalezm%2Fequity_options/lists"}