OptionGreeksGPU


NameOptionGreeksGPU JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/SalilBhasinOfficial/OptionGreeksGPU.git
SummaryGPU / Machine code - accelerated computation of option Greeks
upload_time2024-04-30 20:41:57
maintainerNone
docs_urlNone
authorSalil Bhasin
requires_python>=3.7
licenseNone
keywords options greeks computation gpu acceleration finance options trading quantitative finance risk management financial engineering option pricing cuda gpu computing high performance computing derivatives trading volatility hedging strategies investment analysis trading algorithms financial markets black-scholes algorithmic trading portfolio optimization market analysis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OptionGreeksGPU (V2.0.0)

OptionGreeksGPU is a high-performance, GPU-accelerated library designed to calculate option Greeks for a large number of contracts quickly and efficiently. 

In the absense of cuda compatible GPU, the library falls back to machine code using numba which is over 100 times faster. By leveraging the power of machine code / modern GPU architectures, OptionGreeksGPU can compute Greeks for over 1648 option contracts in just 0.20 seconds (after warmup), offering a significant performance improvement over computation in python.

Benchmarking results on test data of 824 contracts (included in test directory):

    •	CPU Single core without numba    | Warmup run = 144.23 Seconds | subsequent runs = 221.29 Seconds
	•	CPU Machine Code using numba jit | Warmup run = 1.94 Seconds   | subsequent runs = 0.68 Second
	•	Cuda Capable GPU using numba jit | Warmup run = 1.65 Seconds   | susequent runs = 0.14 Second


Features

	•	Fast Computation: Utilizes GPU acceleration/ Machine code to dramatically reduce computation times for option Greeks.
	•	Easy Integration: Designed to easily integrate with existing Python financial analysis workflows.
	•	Comprehensive: Supports a wide range of Greeks calculations, including Delta, Gamma, Theta, Vega, and Rho.

# Black-Scholes Model

The Black-Scholes model is a fundamental concept in modern financial theory and is widely used for pricing European options on stocks that do not pay dividends. Developed by Fischer Black, Myron Scholes, and Robert Merton in the early 1970s, this model provides a theoretical estimate of the price of European-style options. The beauty of the Black-Scholes model lies in its ability to factor in the major variables affecting option prices, such as the stock price, the exercise price, the risk-free interest rate, the time to expiration, and the volatility of the stock.

The Black-Scholes formula helps investors and traders to determine the fair value of an option, allowing them to make informed trading decisions. Specifically, it calculates the price of an option by inputting the current stock price, the option's strike price, the time until expiration (expressed as a year fraction), the risk-free interest rate, and the volatility of the stock. The model assumes that stock prices follow a lognormal distribution because asset prices cannot be negative, and it considers the constant risk-free rate for the option's life span.

The model is particularly suited for European options, which can only be exercised at expiration, unlike American options, which can be exercised at any time before or at expiration. It's important to note that while the Black-Scholes model provides a robust framework for option valuation, it does have limitations, especially when applied to American options, options on dividend-paying stocks, or in highly volatile markets.


# Installation

Before installing OptionGreeksGPU, ensure you have a CUDA-compatible GPU and the appropriate CUDA Toolkit installed on your system.

To install OptionGreeksGPU, run the following command:

`pip install OptionGreeksGPU`

# Usage

Here’s a quick example of how to use OptionGreeksGPU (see test.py for exact operation) to compute Greeks for option contracts:

```python
from OptionGreeksGPU.Compute import calculate_option_metrics
import pandas as pd
import numpy as np

### Load your option contracts data (shared in test directory)
df = pd.read_csv('OpGreeksTestInput.csv', parse_dates=['expiry', 'DT'])

### Prepare the data
optionData = df[['strike', 'last_price_Und', 'last_price_CE', 'GreekRef_CE', 'last_price_PE', 'GreekRef_PE']].to_numpy()
interestRate = 5
daysToExpiration = 30  # Example: 30 days to expiration

### Calculate the Greeks
Data = calculate_option_metrics(option_data=optionData, days_to_expiry=daysToExpiration, interest_rate=interestRate)

### Convert the result to a DataFrame
Result_DF = pd.DataFrame(np.column_stack(Data), columns=['call_IVs', 'call_deltas', 'call_delta2s', 'call_vegas', 'call_gammas', 'call_thetas', 'call_rhos', 'put_IVs', 'put_deltas', 'put_delta2s', 'put_vegas', 'put_gammas', 'put_thetas', 'put_rhos'])

### Save or use the results
Result_DF.to_csv('OpGreeksTestOutput.csv')
```

### Input Format for OptionGreeksGPU (try using Test.py)
When using the OptionGreeksGPU library to calculate option Greeks based on the Black-Scholes model, the input data should be structured as follows:

input_data = (option_data=[[strikePrices], [underlyingPrices], [callPrices], [callRefs = 0s], [putPrices], [putRefs = 1s]],
                days_to_expiry,
                interest_rate)


strikePrices: An array of strike prices for the options.
underlyingPrices: An array of current prices of the underlying asset.
callPrices: An array of market prices for call options.
callRefs: An array filled with 0s, indicating that the corresponding prices are for call options.
putPrices: An array of market prices for put options.
putRefs: An array filled with 1s, indicating that the corresponding prices are for put options.
interestRate: The risk-free interest rate, expressed as a whole number (e.g., 5 for 5%).
daysToExpiry: The time to expiration of the options, expressed in days (with Decimals).


# Performance

    •	CPU Python Single core without numba    | Warmup run = 144.23 Seconds | subsequent runs = 221.29 Seconds
	•	CPU Machine Code using numba jit        | Warmup run = 1.94 Seconds   | subsequent runs = 0.68 Second
	•	Cuda Capable GPU using numba jit        | Warmup run = 1.65 Seconds   | susequent runs = 0.14 Second

# Contributing

Contributions are welcome! If you’d like to contribute, please fork the repository, create a feature branch, and submit a pull request.

# License

OptionGreeksGPU is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.

# Support

If you encounter any problems or have any suggestions, please open an issue on the project’s GitHub page.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SalilBhasinOfficial/OptionGreeksGPU.git",
    "name": "OptionGreeksGPU",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "options greeks computation gpu acceleration finance options trading quantitative finance risk management financial engineering option pricing CUDA GPU computing high performance computing derivatives trading volatility hedging strategies investment analysis trading algorithms financial markets black-scholes algorithmic trading portfolio optimization market analysis",
    "author": "Salil Bhasin",
    "author_email": "salilbhasinofficial@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/ac/a96759e6f64cd76725897e4ba10b7fb4e6ead133fa140ebc3d8b3b5be10d/optiongreeksgpu-2.0.0.tar.gz",
    "platform": null,
    "description": "# OptionGreeksGPU (V2.0.0)\r\n\r\nOptionGreeksGPU is a high-performance, GPU-accelerated library designed to calculate option Greeks for a large number of contracts quickly and efficiently. \r\n\r\nIn the absense of cuda compatible GPU, the library falls back to machine code using numba which is over 100 times faster. By leveraging the power of machine code / modern GPU architectures, OptionGreeksGPU can compute Greeks for over 1648 option contracts in just 0.20 seconds (after warmup), offering a significant performance improvement over computation in python.\r\n\r\nBenchmarking results on test data of 824 contracts (included in test directory):\r\n\r\n    \u00e2\u20ac\u00a2\tCPU Single core without numba    | Warmup run = 144.23 Seconds | subsequent runs = 221.29 Seconds\r\n\t\u00e2\u20ac\u00a2\tCPU Machine Code using numba jit | Warmup run = 1.94 Seconds   | subsequent runs = 0.68 Second\r\n\t\u00e2\u20ac\u00a2\tCuda Capable GPU using numba jit | Warmup run = 1.65 Seconds   | susequent runs = 0.14 Second\r\n\r\n\r\nFeatures\r\n\r\n\t\u00e2\u20ac\u00a2\tFast Computation: Utilizes GPU acceleration/ Machine code to dramatically reduce computation times for option Greeks.\r\n\t\u00e2\u20ac\u00a2\tEasy Integration: Designed to easily integrate with existing Python financial analysis workflows.\r\n\t\u00e2\u20ac\u00a2\tComprehensive: Supports a wide range of Greeks calculations, including Delta, Gamma, Theta, Vega, and Rho.\r\n\r\n# Black-Scholes Model\r\n\r\nThe Black-Scholes model is a fundamental concept in modern financial theory and is widely used for pricing European options on stocks that do not pay dividends. Developed by Fischer Black, Myron Scholes, and Robert Merton in the early 1970s, this model provides a theoretical estimate of the price of European-style options. The beauty of the Black-Scholes model lies in its ability to factor in the major variables affecting option prices, such as the stock price, the exercise price, the risk-free interest rate, the time to expiration, and the volatility of the stock.\r\n\r\nThe Black-Scholes formula helps investors and traders to determine the fair value of an option, allowing them to make informed trading decisions. Specifically, it calculates the price of an option by inputting the current stock price, the option's strike price, the time until expiration (expressed as a year fraction), the risk-free interest rate, and the volatility of the stock. The model assumes that stock prices follow a lognormal distribution because asset prices cannot be negative, and it considers the constant risk-free rate for the option's life span.\r\n\r\nThe model is particularly suited for European options, which can only be exercised at expiration, unlike American options, which can be exercised at any time before or at expiration. It's important to note that while the Black-Scholes model provides a robust framework for option valuation, it does have limitations, especially when applied to American options, options on dividend-paying stocks, or in highly volatile markets.\r\n\r\n\r\n# Installation\r\n\r\nBefore installing OptionGreeksGPU, ensure you have a CUDA-compatible GPU and the appropriate CUDA Toolkit installed on your system.\r\n\r\nTo install OptionGreeksGPU, run the following command:\r\n\r\n`pip install OptionGreeksGPU`\r\n\r\n# Usage\r\n\r\nHere\u00e2\u20ac\u2122s a quick example of how to use OptionGreeksGPU (see test.py for exact operation) to compute Greeks for option contracts:\r\n\r\n```python\r\nfrom OptionGreeksGPU.Compute import calculate_option_metrics\r\nimport pandas as pd\r\nimport numpy as np\r\n\r\n### Load your option contracts data (shared in test directory)\r\ndf = pd.read_csv('OpGreeksTestInput.csv', parse_dates=['expiry', 'DT'])\r\n\r\n### Prepare the data\r\noptionData = df[['strike', 'last_price_Und', 'last_price_CE', 'GreekRef_CE', 'last_price_PE', 'GreekRef_PE']].to_numpy()\r\ninterestRate = 5\r\ndaysToExpiration = 30  # Example: 30 days to expiration\r\n\r\n### Calculate the Greeks\r\nData = calculate_option_metrics(option_data=optionData, days_to_expiry=daysToExpiration, interest_rate=interestRate)\r\n\r\n### Convert the result to a DataFrame\r\nResult_DF = pd.DataFrame(np.column_stack(Data), columns=['call_IVs', 'call_deltas', 'call_delta2s', 'call_vegas', 'call_gammas', 'call_thetas', 'call_rhos', 'put_IVs', 'put_deltas', 'put_delta2s', 'put_vegas', 'put_gammas', 'put_thetas', 'put_rhos'])\r\n\r\n### Save or use the results\r\nResult_DF.to_csv('OpGreeksTestOutput.csv')\r\n```\r\n\r\n### Input Format for OptionGreeksGPU (try using Test.py)\r\nWhen using the OptionGreeksGPU library to calculate option Greeks based on the Black-Scholes model, the input data should be structured as follows:\r\n\r\ninput_data = (option_data=[[strikePrices], [underlyingPrices], [callPrices], [callRefs = 0s], [putPrices], [putRefs = 1s]],\r\n                days_to_expiry,\r\n                interest_rate)\r\n\r\n\r\nstrikePrices: An array of strike prices for the options.\r\nunderlyingPrices: An array of current prices of the underlying asset.\r\ncallPrices: An array of market prices for call options.\r\ncallRefs: An array filled with 0s, indicating that the corresponding prices are for call options.\r\nputPrices: An array of market prices for put options.\r\nputRefs: An array filled with 1s, indicating that the corresponding prices are for put options.\r\ninterestRate: The risk-free interest rate, expressed as a whole number (e.g., 5 for 5%).\r\ndaysToExpiry: The time to expiration of the options, expressed in days (with Decimals).\r\n\r\n\r\n# Performance\r\n\r\n    \u00e2\u20ac\u00a2\tCPU Python Single core without numba    | Warmup run = 144.23 Seconds | subsequent runs = 221.29 Seconds\r\n\t\u00e2\u20ac\u00a2\tCPU Machine Code using numba jit        | Warmup run = 1.94 Seconds   | subsequent runs = 0.68 Second\r\n\t\u00e2\u20ac\u00a2\tCuda Capable GPU using numba jit        | Warmup run = 1.65 Seconds   | susequent runs = 0.14 Second\r\n\r\n# Contributing\r\n\r\nContributions are welcome! If you\u00e2\u20ac\u2122d like to contribute, please fork the repository, create a feature branch, and submit a pull request.\r\n\r\n# License\r\n\r\nOptionGreeksGPU is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.\r\n\r\n# Support\r\n\r\nIf you encounter any problems or have any suggestions, please open an issue on the project\u00e2\u20ac\u2122s GitHub page.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "GPU / Machine code - accelerated computation of option Greeks",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/SalilBhasinOfficial/OptionGreeksGPU.git"
    },
    "split_keywords": [
        "options",
        "greeks",
        "computation",
        "gpu",
        "acceleration",
        "finance",
        "options",
        "trading",
        "quantitative",
        "finance",
        "risk",
        "management",
        "financial",
        "engineering",
        "option",
        "pricing",
        "cuda",
        "gpu",
        "computing",
        "high",
        "performance",
        "computing",
        "derivatives",
        "trading",
        "volatility",
        "hedging",
        "strategies",
        "investment",
        "analysis",
        "trading",
        "algorithms",
        "financial",
        "markets",
        "black-scholes",
        "algorithmic",
        "trading",
        "portfolio",
        "optimization",
        "market",
        "analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "222fc6d6d29920fd473273744e3d6ba9b378f5a2b213a050205a00266afe3f96",
                "md5": "9301665fa3ba49b141109f3855a5f364",
                "sha256": "982eea06f5b56dfbe4b5710f909d38e2c5fbc105ba586197195bfe62de1c7ccc"
            },
            "downloads": -1,
            "filename": "OptionGreeksGPU-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9301665fa3ba49b141109f3855a5f364",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 20626,
            "upload_time": "2024-04-30T20:41:53",
            "upload_time_iso_8601": "2024-04-30T20:41:53.956981Z",
            "url": "https://files.pythonhosted.org/packages/22/2f/c6d6d29920fd473273744e3d6ba9b378f5a2b213a050205a00266afe3f96/OptionGreeksGPU-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33aca96759e6f64cd76725897e4ba10b7fb4e6ead133fa140ebc3d8b3b5be10d",
                "md5": "f93fb3c562b547d18d1555599a52c021",
                "sha256": "e9f6faf85fa727456f20c2fc81e4ba80636eacfb76a77f07b2d39813297f62c1"
            },
            "downloads": -1,
            "filename": "optiongreeksgpu-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f93fb3c562b547d18d1555599a52c021",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20005,
            "upload_time": "2024-04-30T20:41:57",
            "upload_time_iso_8601": "2024-04-30T20:41:57.858100Z",
            "url": "https://files.pythonhosted.org/packages/33/ac/a96759e6f64cd76725897e4ba10b7fb4e6ead133fa140ebc3d8b3b5be10d/optiongreeksgpu-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 20:41:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SalilBhasinOfficial",
    "github_project": "OptionGreeksGPU",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "optiongreeksgpu"
}
        
Elapsed time: 0.30489s