{"id":30269020,"url":"https://github.com/donpushme/sv-model","last_synced_at":"2025-08-16T01:38:42.836Z","repository":{"id":307476790,"uuid":"1026125734","full_name":"donpushme/SV-model","owner":"donpushme","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-25T10:54:41.000Z","size":10690,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T08:55:41.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/donpushme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2025-07-25T10:53:34.000Z","updated_at":"2025-07-26T08:28:38.000Z","dependencies_parsed_at":"2025-07-31T14:36:34.928Z","dependency_job_id":"1d09bc20-7b43-4b39-9192-159b0aa91b4f","html_url":"https://github.com/donpushme/SV-model","commit_stats":null,"previous_names":["donpushme/sv-model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/donpushme/SV-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donpushme%2FSV-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donpushme%2FSV-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donpushme%2FSV-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donpushme%2FSV-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donpushme","download_url":"https://codeload.github.com/donpushme/SV-model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donpushme%2FSV-model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270657455,"owners_count":24623457,"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-15T02:00:12.559Z","response_time":110,"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":[],"created_at":"2025-08-16T01:38:37.746Z","updated_at":"2025-08-16T01:38:42.828Z","avatar_url":"https://github.com/donpushme.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StochVolModels\n\nImplementation of pricing analytics and Monte Carlo simulations for modeling of options and implied volatilities.\n\nThe StochVol package provides:\n1) Analytics for Black-Scholes and Normal vols\n2) Interfaces and implementation for stochastic volatility models,\nincluding log-normal SV model and Heston SV model \nusing analytical method with Fourier transform and Monte Carlo simulations\n3) Visualization of model implied volatilities\n\nFor the analytic implementation of stochastic volatility models, the package provides interfaces for a generic volatility model with the following features.\n1) Interface for analytical pricing of vanilla options \nusing Fourier transform with closed-form solution for moment generating function\n2) Interface for Monte-Carlo simulations of model dynamics\n\n\n[Illustrations](#papers) of using package analytics for research \nwork is provided in top-level package ```my_papers``` \nwhich contains computations and visualisations for several papers\n\n\n## Installation\nInstall using\n```python \npip install stochvolmodels\n```\nUpgrade using\n```python \npip install --upgrade stochvolmodels\n```\nClose using\n```python \ngit clone https://github.com/ArturSepp/StochVolModels.git\n```\n\nCore dependencies:\n    python = \"\u003e=3.8\",\n    numba = \"\u003e=0.56.4\",\n    numpy = \"\u003e=1.22.4\",\n    scipy = \"\u003e=1.10\",\n    pandas = \"\u003e=2.2.0\",\n    matplotlib = \"\u003e=3.2.2\",\n    seaborn = \"\u003e=0.12.2\"\n\nOptional dependencies:\n    qis \"\u003e=2.1.38\" (for running code in my_papers and volatility_book)\n\n\n# Table of contents\n1. [Model Interface](#introduction)\n    1. [Log-normal stochastic volatility model](#logsv)\n    2. [Heston stochastic volatility model](#hestonsv)\n2. [Running log-normal SV pricer](#paragraph1)\n   1. [Computing model prices and vols](#subparagraph1)\n   2. [Running model calibration to sample Bitcoin options data](#subparagraph2)\n   3. [Comparison of model prices vs MC](#subparagraph3)\n   4. [Analysis and figures for the paper](#subparagraph4)\n3. [Running Heston SV pricer](#heston)\n4. [Supporting Illustrations for Public Papers](#papers)\n\n\nRunning model calibration to sample Bitcoin options data\n\n## Implemented Stochastic Volatility models \u003ca name=\"introduction\"\u003e\u003c/a\u003e\nThe package provides interfaces for a generic volatility model with the following features.\n1) Interface for analytical pricing of vanilla options using Fourier transform with closed-form solution for moment generating function\n2) Interface for Monte-Carlo simulations of model dynamics\n3) Interface for visualization of model implied volatilities\n\nThe model interface is in stochvolmodels/pricers/model_pricer.py\n\n### Log-normal stochastic volatility model \u003ca name=\"logsv\"\u003e\u003c/a\u003e\n\nThe analytics for the log-normal stochastic volatility model is based on the paper\n\n[Log-normal Stochastic Volatility Model with Quadratic Drift](https://www.worldscientific.com/doi/10.1142/S0219024924500031) by Artur Sepp and Parviz Rakhmonov\n\n\nThe dynamics of the log-normal stochastic volatility model:\n\n$$dS_{t}=r(t)S_{t}dt+\\sigma_{t}S_{t}dW^{(0)}_{t}$$\n\n$$d\\sigma_{t}=\\left(\\kappa_{1} + \\kappa_{2}\\sigma_{t} \\right)(\\theta - \\sigma_{t})dt+  \\beta  \\sigma_{t}dW^{(0)}_{t} +  \\varepsilon \\sigma_{t} dW^{(1)}_{t}$$\n\n$$dI_{t}=\\sigma^{2}_{t}dt$$\n\nwhere $r(t)$ is the deterministic risk-free rate; $W^{(0)}_{t}$ and $W^{(1)}_t$  are uncorrelated Brownian motions, $\\beta\\in\\mathbb{R}$ is the volatility beta which measures the sensitivity of the volatility to changes in the spot price, and $\\varepsilon\u003e0$ is the volatility of residual volatility. We denote by $\\vartheta^{2}$, $\\vartheta^{2}=\\beta^{2}+\\varepsilon^{2}$, the total instantaneous variance of the volatility process.\n\n\nImplementation of Lognormal SV model is contained in \n```python \nstochvolmodels/pricers/logsv_pricer.py\n```\n\n### Heston stochastic volatility model \u003ca name=\"hestonsv\"\u003e\u003c/a\u003e\n\nThe dynamics of Heston stochastic volatility model:\n\n$$dS_{t}=r(t)S_{t}dt+\\sqrt{V_{t}}S_{t}dW^{(S)}_{t}$$\n\n$$dV_{t}=\\kappa (\\theta - V_{t})dt+  \\vartheta  \\sqrt{V_{t}}dW^{(V)}_{t}$$\n\nwhere  $W^{(S)}$ and $W^{(V)}$ are correlated Brownian motions with correlation parameter $\\rho$\n\nImplementation of Heston SV model is contained in \n```python \nstochvolmodels/pricers/heston_pricer.py\n```\n\n## Running log-normal SV pricer \u003ca name=\"paragraph1\"\u003e\u003c/a\u003e\n\nBasic features are implemented in \n```python \nexamples/run_lognormal_sv_pricer.py\n```\n\nImports:\n```python \nimport stochvolmodels as sv\nfrom stochvolmodels import LogSVPricer, LogSvParams, OptionChain\n```\n\n\n### Computing model prices and vols \u003ca name=\"subparagraph1\"\u003e\u003c/a\u003e\n\n```python \n# instance of pricer\nlogsv_pricer = LogSVPricer()\n\n# define model params    \nparams = LogSvParams(sigma0=1.0, theta=1.0, kappa1=5.0, kappa2=5.0, beta=0.2, volvol=2.0)\n\n# 1. compute ne price\nmodel_price, vol = logsv_pricer.price_vanilla(params=params,\n                                             ttm=0.25,\n                                             forward=1.0,\n                                             strike=1.0,\n                                             optiontype='C')\nprint(f\"price={model_price:0.4f}, implied vol={vol: 0.2%}\")\n\n# 2. prices for slices\nmodel_prices, vols = logsv_pricer.price_slice(params=params,\n                                             ttm=0.25,\n                                             forward=1.0,\n                                             strikes=np.array([0.9, 1.0, 1.1]),\n                                             optiontypes=np.array(['P', 'C', 'C']))\nprint([f\"{p:0.4f}, implied vol={v: 0.2%}\" for p, v in zip(model_prices, vols)])\n\n# 3. prices for option chain with uniform strikes\noption_chain = OptionChain.get_uniform_chain(ttms=np.array([0.083, 0.25]),\n                                            ids=np.array(['1m', '3m']),\n                                            strikes=np.linspace(0.9, 1.1, 3))\nmodel_prices, vols = logsv_pricer.compute_chain_prices_with_vols(option_chain=option_chain, params=params)\nprint(model_prices)\nprint(vols)\n```\n\n\n### Running model calibration to sample Bitcoin options data  \u003ca name=\"subparagraph2\"\u003e\u003c/a\u003e\n```python \nbtc_option_chain = chains.get_btc_test_chain_data()\nparams0 = LogSvParams(sigma0=0.8, theta=1.0, kappa1=5.0, kappa2=None, beta=0.15, volvol=2.0)\nbtc_calibrated_params = logsv_pricer.calibrate_model_params_to_chain(option_chain=btc_option_chain,\n                                                                    params0=params0,\n                                                                    constraints_type=ConstraintsType.INVERSE_MARTINGALE)\nprint(btc_calibrated_params)\n\nlogsv_pricer.plot_model_ivols_vs_bid_ask(option_chain=btc_option_chain,\n                               params=btc_calibrated_params)\n```\n![image info](docs/figures/btc_fit.PNG)\n\n\n\n### Comparison of model prices vs MC  \u003ca name=\"subparagraph3\"\u003e\u003c/a\u003e\n```python \nbtc_option_chain = chains.get_btc_test_chain_data()\nuniform_chain_data = OptionChain.to_uniform_strikes(obj=btc_option_chain, num_strikes=31)\nbtc_calibrated_params = LogSvParams(sigma0=0.8327, theta=1.0139, kappa1=4.8609, kappa2=4.7940, beta=0.1988, volvol=2.3694)\nlogsv_pricer.plot_comp_mma_inverse_options_with_mc(option_chain=uniform_chain_data,\n                                                  params=btc_calibrated_params,\n                                                  nb_path=400000)\n                                           \n```\n![image info](docs/figures/btc_mc_comp.PNG)\n\n\n### Analysis and figures for the paper \u003ca name=\"subparagraph4\"\u003e\u003c/a\u003e\n\nAll figures shown in the paper can be reproduced using py scripts in\n```python \nexamples/plots_for_paper\n```\n\n\n## Running Heston SV pricer \u003ca name=\"heston\"\u003e\u003c/a\u003e\n\nExamples are implemented here\n```python \nexamples/run_heston_sv_pricer.py\nexamples/run_heston.py\n```\n\nContent of run_heston.py\n```python \nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom stochvolmodels import HestonPricer, HestonParams, OptionChain\n\n# define parameters for bootstrap\nparams_dict = {'rho=0.0': HestonParams(v0=0.2**2, theta=0.2**2, kappa=4.0, volvol=0.75, rho=0.0),\n               'rho=-0.4': HestonParams(v0=0.2**2, theta=0.2**2, kappa=4.0, volvol=0.75, rho=-0.4),\n               'rho=-0.8': HestonParams(v0=0.2**2, theta=0.2**2, kappa=4.0, volvol=0.75, rho=-0.8)}\n\n# get uniform slice\noption_chain = OptionChain.get_uniform_chain(ttms=np.array([0.25]), ids=np.array(['3m']), strikes=np.linspace(0.8, 1.15, 20))\noption_slice = option_chain.get_slice(id='3m')\n\n# run pricer\npricer = HestonPricer()\npricer.plot_model_slices_in_params(option_slice=option_slice, params_dict=params_dict)\n\nplt.show()\n```\n\n\n## Supporting Illustrations for Public Papers \u003ca name=\"papers\"\u003e\u003c/a\u003e\n\nAs illustrations of different analytics, this packadge includes module ```my_papers``` \nwith codes for computations and visualisations featured in several papers\nfor \n\n1) \"Log-normal Stochastic Volatility Model with Quadratic Drift\" by Artur Sepp \nand Parviz Rakhmonov: https://www.worldscientific.com/doi/10.1142/S0219024924500031\n```python \nstochvolmodels/my_papers/logsv_model_wtih_quadratic_drift\n```\n\n\n2) \"What is a robust stochastic volatility model\" by Artur Sepp and Parviz Rakhmonov, SSRN:\nhttps://papers.ssrn.com/sol3/papers.cfm?abstract_id=4647027\n```python \nstochvolmodels/my_papers/volatility_models\n```\n\n\n3) \"Valuation and Hedging of Cryptocurrency Inverse Options\" by Artur Sepp\nand Vladimir Lucic, \nSSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4606748 \n```python \nstochvolmodels/my_papers/inverse_options\n```\n\n4) \"Unified Approach for Hedging Impermanent Loss of Liquidity Provision\" by \nArtur Sepp, Alexander Lipton and Vladimir Lucic, \nSSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4887298 \n```python \nstochvolmodels/my_papers/il_hedging\n```\n\n5) \"Stochastic Volatility for Factor Heath-Jarrow-Morton Framework\" by Artur Sepp and Parviz Rakhmonov, SSRN:\nhttps://papers.ssrn.com/sol3/papers.cfm?abstract_id=4646925\n```python \nstochvolmodels/my_papers/sv_for_factor_hjm\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonpushme%2Fsv-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonpushme%2Fsv-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonpushme%2Fsv-model/lists"}