optionvisualizer-wrapper


Nameoptionvisualizer-wrapper JSON
Version 0.1.11 PyPI version JSON
download
home_pageNone
SummaryWrapper for https://github.com/GBERESEARCH/optionvisualizer - now methods output plotly fig objects instead of None
upload_time2025-03-14 21:50:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords 3d-modeling greeks option-modeling options optionvisualizer plotly
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OptionVisualizer Wrapper

Wrapper for https://github.com/GBERESEARCH/optionvisualizer - now methods output **plotly** fig objects instead of `None`, giving you the flexibility of further processing the plots and converting them to different formats that can be displayed and interacted with outside of jupyter notebooks.

<!-- Wrapper for https://github.com/GBERESEARCH/optionvisualizer . -->

<!-- If you only want to see the visualizations in jupyter notebooks, just use the original `optionvisualizer` package is fine. -->

<!-- Demo: https://gist.github.com/tddschn/984962bd09eceb5c736cae945eabeea8 -->

This library provides a wrapper around the excellent `optionvisualizer` package, ensuring that all plotting functions consistently return Plotly `Figure` objects. This makes it easier to integrate with other Plotly-based tools, save figures in various formats, and customize plots further.

- [OptionVisualizer Wrapper](#optionvisualizer-wrapper)
  - [Key Features](#key-features)
  - [Installation](#installation)
  - [Usage Examples](#usage-examples)
  - [API Comparison with `optionvisualizer`](#api-comparison-with-optionvisualizer)


## Key Features

*   **Consistent Plotly Output:** All plotting functions (`visualize`, `greeks`, `payoffs`) return `plotly.graph_objects.Figure` instances.
*   **Mirrored API:** The API closely mirrors the original `optionvisualizer`, making it easy to transition. You can use the same function names and parameters.
*   **Simplified Usage:** No need to juggle `interactive`, `notebook`, and `web_graph` flags.  The wrapper handles this internally.
*   **Full Functionality:**  Provides access to all the core features of `optionvisualizer`, including:
    *   Option pricing (Black-Scholes)
    *   Greek calculations (analytical and numerical)
    *   Barrier option pricing
    *   2D and 3D Greek visualizations
    *   Payoff diagrams for various option strategies

## Installation

<!-- ### pipx

This is the recommended installation method.

```
$ pipx install optionvisualizer-wrapper
``` -->

[PyPI](https://pypi.org/project/optionvisualizer-wrapper/)

```
$ pip install optionvisualizer-wrapper
```


## Usage Examples

Output of the code below: https://gist.github.com/tddschn/984962bd09eceb5c736cae945eabeea8

```python
from optionvisualizer_wrapper import OptionVisualizerWrapper

# Create an instance of the wrapper
wrapper = OptionVisualizerWrapper()

# --- Option Pricing and Greeks ---

# Calculate the price of a call option
price = wrapper.option_data(
    option_value="price", S=100, K=105, T=0.5, r=0.01, sigma=0.2, option="call"
)
print(f"Call Option Price: {price}")

# Calculate Delta (using analytical method by default)
delta = wrapper.sensitivities(greek="delta", S=100, K=100, T=0.5, r=0.01, sigma=0.2)
print(f"Delta: {delta}")

# Calculate Delta numerically
delta_num = wrapper.sensitivities(
    greek="delta", S=100, K=100, T=0.5, r=0.01, sigma=0.2, num_sens=True
)
print(f"Numerical Delta: {delta_num}")

# Calculate Barrier Option Price
barrier_price = wrapper.barrier(
    S=100, K=95, H=110, R=0, T=1, r=0.05, q=0, sigma=0.3, option='call', barrier_direction='up', knock='in'
)
print(f"Barrier Option Price: {barrier_price}")


# --- 3D Greek Visualization ---

# Visualize Vega in 3D
fig_3d = wrapper.visualize(
    risk=True,
    graphtype="3D",
    greek="vega",
    S=100,
    T=0.75,
    r=0.02,
    sigma=0.25,
    direction="long",
    colorscheme="Viridis",
)
fig_3d.show()
# Save the figure to an HTML file
fig_3d.write_html("vega_3d.html")


# --- 2D Greek Visualization ---
fig_2d = wrapper.visualize(
    risk=True,
    graphtype="2D",
    x_plot="price",
    y_plot="delta",
    S=100,
    G1=90,
    G2=100,
    G3=110,
    T=0.5,
    r=0.02,
    sigma=0.25,
)
fig_2d.show()

# --- Payoff Diagram ---

# Visualize a straddle payoff
fig_payoff = wrapper.visualize(
    risk=False, combo_payoff="straddle", S=100, K=100, T=0.25, r=0.01, sigma=0.3
)
fig_payoff.show()

# Visualize a call option payoff
fig_call_payoff = wrapper.visualize(
    risk=False, payoff_type="call", S=100, K=100, T=0.25, r=0.01, sigma=0.3, direction='long', value=True
)
fig_call_payoff.show()

# --- Using greeks() method for 3D Greek Graph ---

fig_3d_greek = wrapper.greeks(
    graphtype="3D", greek="gamma", S=100, T=0.75, r=0.02, sigma=0.25, direction="short"
)
fig_3d_greek.show()

# --- Using greeks() method for 2D Greek Graph ---

fig_2d_greek = wrapper.greeks(
    graphtype="2D", x_plot="vol", y_plot="theta", S=100, T=0.75, r=0.02, sigma=0.25, direction="long"
    , G1=90, G2=100, G3=110
)

fig_2d_greek.show()
# --- Using payoffs() method ---

fig_payoff = wrapper.payoffs(
    payoff_type="butterfly", S=100, K1=90, K2=100, K3=110, T=0.75, r=0.02, sigma=0.25, direction="long"
)

fig_payoff.show()
```

## API Comparison with `optionvisualizer`

The `OptionVisualizerWrapper` aims to provide a very similar API to the original `optionvisualizer.visualizer.Visualizer` class.  Here's a breakdown of the similarities and key differences:

**Similarities:**

*   **Method Names:**  The core methods have the same names:
    *   `option_data()`
    *   `sensitivities()`
    *   `barrier()`
    *   `visualize()`
    *   `greeks()`
    *  `payoffs()`
*   **Parameters:**  The methods accept (almost) all the same parameters as the original methods.  You can use the same keyword arguments (e.g., `S`, `K`, `T`, `r`, `sigma`, `option`, `greek`, `direction`, `combo_payoff`, etc.).
*   **Functionality:** The underlying calculations and plotting logic are identical, as the wrapper simply calls the original library's functions.

**Key Differences:**

1.  **Return Values (Plotting):**
    *   **`optionvisualizer`:** The `visualize()`, `greeks()` and `payoffs()` methods in the original library *display* graphs (either using Matplotlib or by opening a browser window for Plotly) and return `None`.  To get the Plotly figure object, you had to use specific combinations of `interactive`, `notebook`, and `web_graph` flags, which could be confusing.  Or, you could use `data_output=True` to get the *data* used to create the plot, but not the figure object itself.
    *   **`OptionVisualizerWrapper`:** The `visualize()`, `greeks()` and `payoffs()` methods in the wrapper *always* return the Plotly `go.Figure` object.  You no longer need to worry about the display flags. The wrapper handles the internal details to ensure you get the figure object.

2.  **Simplified Usage (Plotting):**  The wrapper eliminates the need to manage the `interactive`, `notebook`, and `web_graph` flags for getting Plotly figures. The wrapper handles the internal details.

3.  **No `animated_gif`:** The wrapper does *not* include the `animated_gif` method from the original library.  Creating animated GIFs is a separate concern and can be handled using other libraries if needed (or potentially added as a separate feature to the wrapper).

4. **`graphtype` is restricted to 2D and 3D for `greeks` and `visualize` methods:** `graphtype` argument is now type hinted with `Literal["2D", "3D"]` and raises a `ValueError` if any other value supplied.

In essence, the wrapper provides a *cleaner, more consistent interface* for generating Plotly visualizations from `optionvisualizer`'s powerful calculations, while retaining the familiar API. It's a thin layer that makes the library more convenient to use in a Plotly-centric workflow.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "optionvisualizer-wrapper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "3d-modeling, greeks, option-modeling, options, optionvisualizer, plotly",
    "author": null,
    "author_email": "Teddy Xinyuan Chen <45612704+tddschn@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/8e/76/c905ed32cbfc087760643186f41b219dff8f880ed934a398b521909f849c/optionvisualizer_wrapper-0.1.11.tar.gz",
    "platform": null,
    "description": "# OptionVisualizer Wrapper\n\nWrapper for https://github.com/GBERESEARCH/optionvisualizer - now methods output **plotly** fig objects instead of `None`, giving you the flexibility of further processing the plots and converting them to different formats that can be displayed and interacted with outside of jupyter notebooks.\n\n<!-- Wrapper for https://github.com/GBERESEARCH/optionvisualizer . -->\n\n<!-- If you only want to see the visualizations in jupyter notebooks, just use the original `optionvisualizer` package is fine. -->\n\n<!-- Demo: https://gist.github.com/tddschn/984962bd09eceb5c736cae945eabeea8 -->\n\nThis library provides a wrapper around the excellent `optionvisualizer` package, ensuring that all plotting functions consistently return Plotly `Figure` objects. This makes it easier to integrate with other Plotly-based tools, save figures in various formats, and customize plots further.\n\n- [OptionVisualizer Wrapper](#optionvisualizer-wrapper)\n  - [Key Features](#key-features)\n  - [Installation](#installation)\n  - [Usage Examples](#usage-examples)\n  - [API Comparison with `optionvisualizer`](#api-comparison-with-optionvisualizer)\n\n\n## Key Features\n\n*   **Consistent Plotly Output:** All plotting functions (`visualize`, `greeks`, `payoffs`) return `plotly.graph_objects.Figure` instances.\n*   **Mirrored API:** The API closely mirrors the original `optionvisualizer`, making it easy to transition. You can use the same function names and parameters.\n*   **Simplified Usage:** No need to juggle `interactive`, `notebook`, and `web_graph` flags.  The wrapper handles this internally.\n*   **Full Functionality:**  Provides access to all the core features of `optionvisualizer`, including:\n    *   Option pricing (Black-Scholes)\n    *   Greek calculations (analytical and numerical)\n    *   Barrier option pricing\n    *   2D and 3D Greek visualizations\n    *   Payoff diagrams for various option strategies\n\n## Installation\n\n<!-- ### pipx\n\nThis is the recommended installation method.\n\n```\n$ pipx install optionvisualizer-wrapper\n``` -->\n\n[PyPI](https://pypi.org/project/optionvisualizer-wrapper/)\n\n```\n$ pip install optionvisualizer-wrapper\n```\n\n\n## Usage Examples\n\nOutput of the code below: https://gist.github.com/tddschn/984962bd09eceb5c736cae945eabeea8\n\n```python\nfrom optionvisualizer_wrapper import OptionVisualizerWrapper\n\n# Create an instance of the wrapper\nwrapper = OptionVisualizerWrapper()\n\n# --- Option Pricing and Greeks ---\n\n# Calculate the price of a call option\nprice = wrapper.option_data(\n    option_value=\"price\", S=100, K=105, T=0.5, r=0.01, sigma=0.2, option=\"call\"\n)\nprint(f\"Call Option Price: {price}\")\n\n# Calculate Delta (using analytical method by default)\ndelta = wrapper.sensitivities(greek=\"delta\", S=100, K=100, T=0.5, r=0.01, sigma=0.2)\nprint(f\"Delta: {delta}\")\n\n# Calculate Delta numerically\ndelta_num = wrapper.sensitivities(\n    greek=\"delta\", S=100, K=100, T=0.5, r=0.01, sigma=0.2, num_sens=True\n)\nprint(f\"Numerical Delta: {delta_num}\")\n\n# Calculate Barrier Option Price\nbarrier_price = wrapper.barrier(\n    S=100, K=95, H=110, R=0, T=1, r=0.05, q=0, sigma=0.3, option='call', barrier_direction='up', knock='in'\n)\nprint(f\"Barrier Option Price: {barrier_price}\")\n\n\n# --- 3D Greek Visualization ---\n\n# Visualize Vega in 3D\nfig_3d = wrapper.visualize(\n    risk=True,\n    graphtype=\"3D\",\n    greek=\"vega\",\n    S=100,\n    T=0.75,\n    r=0.02,\n    sigma=0.25,\n    direction=\"long\",\n    colorscheme=\"Viridis\",\n)\nfig_3d.show()\n# Save the figure to an HTML file\nfig_3d.write_html(\"vega_3d.html\")\n\n\n# --- 2D Greek Visualization ---\nfig_2d = wrapper.visualize(\n    risk=True,\n    graphtype=\"2D\",\n    x_plot=\"price\",\n    y_plot=\"delta\",\n    S=100,\n    G1=90,\n    G2=100,\n    G3=110,\n    T=0.5,\n    r=0.02,\n    sigma=0.25,\n)\nfig_2d.show()\n\n# --- Payoff Diagram ---\n\n# Visualize a straddle payoff\nfig_payoff = wrapper.visualize(\n    risk=False, combo_payoff=\"straddle\", S=100, K=100, T=0.25, r=0.01, sigma=0.3\n)\nfig_payoff.show()\n\n# Visualize a call option payoff\nfig_call_payoff = wrapper.visualize(\n    risk=False, payoff_type=\"call\", S=100, K=100, T=0.25, r=0.01, sigma=0.3, direction='long', value=True\n)\nfig_call_payoff.show()\n\n# --- Using greeks() method for 3D Greek Graph ---\n\nfig_3d_greek = wrapper.greeks(\n    graphtype=\"3D\", greek=\"gamma\", S=100, T=0.75, r=0.02, sigma=0.25, direction=\"short\"\n)\nfig_3d_greek.show()\n\n# --- Using greeks() method for 2D Greek Graph ---\n\nfig_2d_greek = wrapper.greeks(\n    graphtype=\"2D\", x_plot=\"vol\", y_plot=\"theta\", S=100, T=0.75, r=0.02, sigma=0.25, direction=\"long\"\n    , G1=90, G2=100, G3=110\n)\n\nfig_2d_greek.show()\n# --- Using payoffs() method ---\n\nfig_payoff = wrapper.payoffs(\n    payoff_type=\"butterfly\", S=100, K1=90, K2=100, K3=110, T=0.75, r=0.02, sigma=0.25, direction=\"long\"\n)\n\nfig_payoff.show()\n```\n\n## API Comparison with `optionvisualizer`\n\nThe `OptionVisualizerWrapper` aims to provide a very similar API to the original `optionvisualizer.visualizer.Visualizer` class.  Here's a breakdown of the similarities and key differences:\n\n**Similarities:**\n\n*   **Method Names:**  The core methods have the same names:\n    *   `option_data()`\n    *   `sensitivities()`\n    *   `barrier()`\n    *   `visualize()`\n    *   `greeks()`\n    *  `payoffs()`\n*   **Parameters:**  The methods accept (almost) all the same parameters as the original methods.  You can use the same keyword arguments (e.g., `S`, `K`, `T`, `r`, `sigma`, `option`, `greek`, `direction`, `combo_payoff`, etc.).\n*   **Functionality:** The underlying calculations and plotting logic are identical, as the wrapper simply calls the original library's functions.\n\n**Key Differences:**\n\n1.  **Return Values (Plotting):**\n    *   **`optionvisualizer`:** The `visualize()`, `greeks()` and `payoffs()` methods in the original library *display* graphs (either using Matplotlib or by opening a browser window for Plotly) and return `None`.  To get the Plotly figure object, you had to use specific combinations of `interactive`, `notebook`, and `web_graph` flags, which could be confusing.  Or, you could use `data_output=True` to get the *data* used to create the plot, but not the figure object itself.\n    *   **`OptionVisualizerWrapper`:** The `visualize()`, `greeks()` and `payoffs()` methods in the wrapper *always* return the Plotly `go.Figure` object.  You no longer need to worry about the display flags. The wrapper handles the internal details to ensure you get the figure object.\n\n2.  **Simplified Usage (Plotting):**  The wrapper eliminates the need to manage the `interactive`, `notebook`, and `web_graph` flags for getting Plotly figures. The wrapper handles the internal details.\n\n3.  **No `animated_gif`:** The wrapper does *not* include the `animated_gif` method from the original library.  Creating animated GIFs is a separate concern and can be handled using other libraries if needed (or potentially added as a separate feature to the wrapper).\n\n4. **`graphtype` is restricted to 2D and 3D for `greeks` and `visualize` methods:** `graphtype` argument is now type hinted with `Literal[\"2D\", \"3D\"]` and raises a `ValueError` if any other value supplied.\n\nIn essence, the wrapper provides a *cleaner, more consistent interface* for generating Plotly visualizations from `optionvisualizer`'s powerful calculations, while retaining the familiar API. It's a thin layer that makes the library more convenient to use in a Plotly-centric workflow.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Wrapper for https://github.com/GBERESEARCH/optionvisualizer - now methods output plotly fig objects instead of None",
    "version": "0.1.11",
    "project_urls": {
        "Bug Tracker": "https://github.com/tddschn/optionvisualizer-wrapper/issues",
        "Repository": "https://github.com/tddschn/optionvisualizer-wrapper"
    },
    "split_keywords": [
        "3d-modeling",
        " greeks",
        " option-modeling",
        " options",
        " optionvisualizer",
        " plotly"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2183fac94e1df08e7a73b30d98ea9d19a01079abac74b51f0613bf5bae9c1cf5",
                "md5": "30973c31d2fcbb368a8210a37fc3dbd4",
                "sha256": "ac31356f722ae07d95feb2eed4777ebb58d0057e605634717a5865818ac6b493"
            },
            "downloads": -1,
            "filename": "optionvisualizer_wrapper-0.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30973c31d2fcbb368a8210a37fc3dbd4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 8144,
            "upload_time": "2025-03-14T21:50:50",
            "upload_time_iso_8601": "2025-03-14T21:50:50.174472Z",
            "url": "https://files.pythonhosted.org/packages/21/83/fac94e1df08e7a73b30d98ea9d19a01079abac74b51f0613bf5bae9c1cf5/optionvisualizer_wrapper-0.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8e76c905ed32cbfc087760643186f41b219dff8f880ed934a398b521909f849c",
                "md5": "7ed61660d8994350a23a706252cd79e6",
                "sha256": "aa192c8ccf3c5ec4a89fc236dd90b15d19d73750122a3b2b33322dc38b7bed1f"
            },
            "downloads": -1,
            "filename": "optionvisualizer_wrapper-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "7ed61660d8994350a23a706252cd79e6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 1853908,
            "upload_time": "2025-03-14T21:50:54",
            "upload_time_iso_8601": "2025-03-14T21:50:54.118862Z",
            "url": "https://files.pythonhosted.org/packages/8e/76/c905ed32cbfc087760643186f41b219dff8f880ed934a398b521909f849c/optionvisualizer_wrapper-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-14 21:50:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tddschn",
    "github_project": "optionvisualizer-wrapper",
    "github_not_found": true,
    "lcname": "optionvisualizer-wrapper"
}
        
Elapsed time: 0.44583s