-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ca5bb8
commit e253854
Showing
7 changed files
with
528 additions
and
12 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
docs/source/torchquantlib.core.asset_pricing.option.american_option.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
American Option | ||
=============== | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.option.american_option | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Overview | ||
-------- | ||
|
||
The American Option module provides functionality for pricing and analyzing American-style options using various numerical methods. American options can be exercised at any time up to the expiration date, making them more complex to value than European options. | ||
|
||
Key Features | ||
------------ | ||
|
||
- Pricing of American call and put options | ||
- Support for various underlying assets (e.g., stocks, indices) | ||
- Implementation of multiple pricing methods (e.g., binomial tree, finite difference) | ||
- Greeks calculation for risk management | ||
|
||
Classes | ||
------- | ||
|
||
AmericanOption | ||
~~~~~~~~~~~~~~ | ||
|
||
.. autoclass:: torchquantlib.core.asset_pricing.option.american_option.AmericanOption | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
The AmericanOption class represents an American-style option contract and provides methods for pricing and analyzing the option. | ||
|
||
:param underlying: The price of the underlying asset | ||
:type underlying: float | ||
:param strike: The strike price of the option | ||
:type strike: float | ||
:param expiry: Time to expiration in years | ||
:type expiry: float | ||
:param rf_rate: Risk-free interest rate (annualized) | ||
:type rf_rate: float | ||
:param volatility: Volatility of the underlying asset (annualized) | ||
:type volatility: float | ||
:param option_type: Type of the option ('call' or 'put') | ||
:type option_type: str | ||
|
||
.. method:: price(method='binomial', steps=100) | ||
|
||
Calculate the price of the American option using the specified method. | ||
|
||
:param method: Pricing method to use ('binomial' or 'finite_difference') | ||
:type method: str | ||
:param steps: Number of steps in the pricing model | ||
:type steps: int | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
.. method:: delta() | ||
|
||
Calculate the delta of the American option. | ||
|
||
:return: The option's delta | ||
:rtype: float | ||
|
||
.. method:: gamma() | ||
|
||
Calculate the gamma of the American option. | ||
|
||
:return: The option's gamma | ||
:rtype: float | ||
|
||
.. method:: theta() | ||
|
||
Calculate the theta of the American option. | ||
|
||
:return: The option's theta | ||
:rtype: float | ||
|
||
.. method:: vega() | ||
|
||
Calculate the vega of the American option. | ||
|
||
:return: The option's vega | ||
:rtype: float | ||
|
||
.. method:: rho() | ||
|
||
Calculate the rho of the American option. | ||
|
||
:return: The option's rho | ||
:rtype: float | ||
|
||
Functions | ||
--------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.option.american_option.binomial_tree_price | ||
|
||
Implement the binomial tree method for pricing American options. | ||
|
||
:param option: An instance of the AmericanOption class | ||
:type option: AmericanOption | ||
:param steps: Number of steps in the binomial tree | ||
:type steps: int | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.option.american_option.finite_difference_price | ||
|
||
Implement the finite difference method for pricing American options. | ||
|
||
:param option: An instance of the AmericanOption class | ||
:type option: AmericanOption | ||
:param steps: Number of steps in the finite difference grid | ||
:type steps: int | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
Examples | ||
-------- | ||
|
||
Here's a basic example of how to use the AmericanOption class: | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.option.american_option import AmericanOption | ||
# Create an American call option | ||
option = AmericanOption( | ||
underlying=100, | ||
strike=95, | ||
expiry=1.0, | ||
rf_rate=0.05, | ||
volatility=0.2, | ||
option_type='call' | ||
) | ||
# Price the option using the binomial tree method | ||
price = option.price(method='binomial', steps=1000) | ||
print(f"American call option price: {price:.4f}") | ||
# Calculate option Greeks | ||
delta = option.delta() | ||
gamma = option.gamma() | ||
theta = option.theta() | ||
vega = option.vega() | ||
rho = option.rho() | ||
print(f"Delta: {delta:.4f}") | ||
print(f"Gamma: {gamma:.4f}") | ||
print(f"Theta: {theta:.4f}") | ||
print(f"Vega: {vega:.4f}") | ||
print(f"Rho: {rho:.4f}") |
157 changes: 157 additions & 0 deletions
157
docs/source/torchquantlib.core.asset_pricing.option.asian_option.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
Asian Option | ||
============ | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.option.asian_option | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Overview | ||
-------- | ||
|
||
The Asian Option module provides functionality for pricing and analyzing Asian-style options using various numerical methods. Asian options are path-dependent options where the payoff depends on the average price of the underlying asset over a specific period. | ||
|
||
Key Features | ||
------------ | ||
|
||
- Pricing of Asian call and put options | ||
- Support for arithmetic and geometric average price calculations | ||
- Implementation of multiple pricing methods (e.g., Monte Carlo simulation, analytical approximations) | ||
- Greeks calculation for risk management | ||
|
||
Classes | ||
------- | ||
|
||
AsianOption | ||
~~~~~~~~~~~ | ||
|
||
.. autoclass:: torchquantlib.core.asset_pricing.option.asian_option.AsianOption | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
The AsianOption class represents an Asian-style option contract and provides methods for pricing and analyzing the option. | ||
|
||
:param underlying: The initial price of the underlying asset | ||
:type underlying: float | ||
:param strike: The strike price of the option | ||
:type strike: float | ||
:param expiry: Time to expiration in years | ||
:type expiry: float | ||
:param rf_rate: Risk-free interest rate (annualized) | ||
:type rf_rate: float | ||
:param volatility: Volatility of the underlying asset (annualized) | ||
:type volatility: float | ||
:param option_type: Type of the option ('call' or 'put') | ||
:type option_type: str | ||
:param averaging_type: Type of averaging ('arithmetic' or 'geometric') | ||
:type averaging_type: str | ||
:param averaging_period: Period over which the average is calculated (in years) | ||
:type averaging_period: float | ||
|
||
.. method:: price(method='monte_carlo', num_simulations=10000) | ||
|
||
Calculate the price of the Asian option using the specified method. | ||
|
||
:param method: Pricing method to use ('monte_carlo' or 'analytical_approximation') | ||
:type method: str | ||
:param num_simulations: Number of simulations for Monte Carlo method | ||
:type num_simulations: int | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
.. method:: delta() | ||
|
||
Calculate the delta of the Asian option. | ||
|
||
:return: The option's delta | ||
:rtype: float | ||
|
||
.. method:: gamma() | ||
|
||
Calculate the gamma of the Asian option. | ||
|
||
:return: The option's gamma | ||
:rtype: float | ||
|
||
.. method:: theta() | ||
|
||
Calculate the theta of the Asian option. | ||
|
||
:return: The option's theta | ||
:rtype: float | ||
|
||
.. method:: vega() | ||
|
||
Calculate the vega of the Asian option. | ||
|
||
:return: The option's vega | ||
:rtype: float | ||
|
||
.. method:: rho() | ||
|
||
Calculate the rho of the Asian option. | ||
|
||
:return: The option's rho | ||
:rtype: float | ||
|
||
Functions | ||
--------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.option.asian_option.monte_carlo_price | ||
|
||
Implement the Monte Carlo simulation method for pricing Asian options. | ||
|
||
:param option: An instance of the AsianOption class | ||
:type option: AsianOption | ||
:param num_simulations: Number of Monte Carlo simulations | ||
:type num_simulations: int | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.option.asian_option.analytical_approximation_price | ||
|
||
Implement an analytical approximation method for pricing Asian options. | ||
|
||
:param option: An instance of the AsianOption class | ||
:type option: AsianOption | ||
:return: The calculated option price | ||
:rtype: float | ||
|
||
Examples | ||
-------- | ||
|
||
Here's a basic example of how to use the AsianOption class: | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.option.asian_option import AsianOption | ||
# Create an Asian call option | ||
option = AsianOption( | ||
underlying=100, | ||
strike=95, | ||
expiry=1.0, | ||
rf_rate=0.05, | ||
volatility=0.2, | ||
option_type='call', | ||
averaging_type='arithmetic', | ||
averaging_period=0.5 | ||
) | ||
# Price the option using the Monte Carlo method | ||
price = option.price(method='monte_carlo', num_simulations=100000) | ||
print(f"Asian call option price: {price:.4f}") | ||
# Calculate option Greeks | ||
delta = option.delta() | ||
gamma = option.gamma() | ||
theta = option.theta() | ||
vega = option.vega() | ||
rho = option.rho() | ||
print(f"Delta: {delta:.4f}") | ||
print(f"Gamma: {gamma:.4f}") | ||
print(f"Theta: {theta:.4f}") | ||
print(f"Vega: {vega:.4f}") | ||
print(f"Rho: {rho:.4f}") |
69 changes: 69 additions & 0 deletions
69
docs/source/torchquantlib.core.asset_pricing.option.bermudan_option.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Bermudan Option | ||
=============== | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.option.bermudan_option | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Overview | ||
-------- | ||
|
||
The Bermudan Option module provides functionality for pricing Bermudan-style options using a binomial tree model. Bermudan options are a type of exotic option that can be exercised on specific dates before expiration, combining features of both American and European options. | ||
|
||
Key Features | ||
------------ | ||
|
||
- Pricing of Bermudan call and put options | ||
- Implementation using a binomial tree model | ||
- Support for multiple exercise dates | ||
|
||
Functions | ||
--------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.option.bermudan_option.bermudan_option | ||
|
||
Price a Bermudan option using a binomial tree model. | ||
|
||
:param option_type: Type of option - either 'call' or 'put' | ||
:type option_type: str | ||
:param spot: Current price of the underlying asset | ||
:type spot: Tensor | ||
:param strike: Strike price of the option | ||
:type strike: Tensor | ||
:param expiry: Time to expiration in years | ||
:type expiry: Tensor | ||
:param volatility: Volatility of the underlying asset | ||
:type volatility: Tensor | ||
:param rate: Risk-free interest rate (annualized) | ||
:type rate: Tensor | ||
:param steps: Number of time steps in the binomial tree | ||
:type steps: int | ||
:param exercise_dates: Tensor of indices representing the steps at which the option can be exercised | ||
:type exercise_dates: Tensor | ||
:return: The price of the Bermudan option | ||
:rtype: Tensor | ||
|
||
Examples | ||
-------- | ||
|
||
Here's a basic example of how to use the bermudan_option function: | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchquantlib.core.asset_pricing.option.bermudan_option import bermudan_option | ||
# Set option parameters | ||
option_type = 'call' | ||
spot = torch.tensor(100.0) | ||
strike = torch.tensor(95.0) | ||
expiry = torch.tensor(1.0) | ||
volatility = torch.tensor(0.2) | ||
rate = torch.tensor(0.05) | ||
steps = 100 | ||
exercise_dates = torch.tensor([25, 50, 75]) # Exercise allowed at 1/4, 1/2, and 3/4 of the option's life | ||
# Price the Bermudan option | ||
price = bermudan_option(option_type, spot, strike, expiry, volatility, rate, steps, exercise_dates) | ||
print(f"Bermudan {option_type} option price: {price:.4f}") |
Oops, something went wrong.