Skip to main content

A library for pricing options using different models

Project description

OptionsPricerLib

OptionsPricerLib is a Python library for pricing financial options using various european and american models. The library provides options pricing, implied volatility calculation, and the Greeks for options, covering models such as Barone-Adesi Whaley, Black-Scholes, Leisen-Reimer, Jarrow-Rudd, and Cox-Ross-Rubinstein.

Installation

pip install OptionsPricerLib

Or, install directly from the GitHub repository:

pip install git+https://github.com/hedge0/OptionsPricerLib.git

Usage

After installation, you can import and use any of the models. Here’s a quick example:

from options_models.barone_adesi_whaley import BaroneAdesiWhaley
from options_models.black_scholes import BlackScholes
from options_models.leisen_reimer import LeisenReimer
from options_models.jarrow_rudd import JarrowRudd
from options_models.cox_ross_rubinstein import CoxRossRubinstein

# Define parameters
S = 100        # Current stock price
K = 100        # Strike price
T = 1          # Time to maturity (in years)
r = 0.05       # Risk-free interest rate
sigma = 0.2    # Volatility
q = 0.01       # Dividend yield
option_type = 'calls'  # Option type ('calls' or 'puts')

# Barone-Adesi Whaley
price = BaroneAdesiWhaley.price(sigma, S, K, T, r, q, option_type)
delta = BaroneAdesiWhaley.calculate_delta(sigma, S, K, T, r, q, option_type)
gamma = BaroneAdesiWhaley.calculate_gamma(sigma, S, K, T, r, q, option_type)
vega = BaroneAdesiWhaley.calculate_vega(sigma, S, K, T, r, q, option_type)
theta = BaroneAdesiWhaley.calculate_theta(sigma, S, K, T, r, q, option_type)
rho = BaroneAdesiWhaley.calculate_rho(sigma, S, K, T, r, q, option_type)
print(f"Barone-Adesi Whaley {option_type}: Price={price:.2f}, Delta={delta:.4f}, Gamma={gamma:.4f}, Vega={vega:.4f}, Theta={theta:.4f}, Rho={rho:.4f}")

# Black-Scholes
price = BlackScholes.price(sigma, S, K, T, r, q, option_type)
delta = BlackScholes.calculate_delta(sigma, S, K, T, r, q, option_type)
gamma = BlackScholes.calculate_gamma(sigma, S, K, T, r, q, option_type)
vega = BlackScholes.calculate_vega(sigma, S, K, T, r, q, option_type)
theta = BlackScholes.calculate_theta(sigma, S, K, T, r, q, option_type)
rho = BlackScholes.calculate_rho(sigma, S, K, T, r, q, option_type)
print(f"Black-Scholes {option_type}: Price={price:.2f}, Delta={delta:.4f}, Gamma={gamma:.4f}, Vega={vega:.4f}, Theta={theta:.4f}, Rho={rho:.4f}")

# Leisen-Reimer
price = LeisenReimer.price(sigma, S, K, T, r, q, option_type, steps=100)
delta = LeisenReimer.calculate_delta(sigma, S, K, T, r, q, option_type, steps=100)
gamma = LeisenReimer.calculate_gamma(sigma, S, K, T, r, q, option_type, steps=100)
vega = LeisenReimer.calculate_vega(sigma, S, K, T, r, q, option_type, steps=100)
theta = LeisenReimer.calculate_theta(sigma, S, K, T, r, q, option_type, steps=100)
rho = LeisenReimer.calculate_rho(sigma, S, K, T, r, q, option_type, steps=100)
print(f"Leisen-Reimer {option_type}: Price={price:.2f}, Delta={delta:.4f}, Gamma={gamma:.4f}, Vega={vega:.4f}, Theta={theta:.4f}, Rho={rho:.4f}")

# Jarrow-Rudd
price = JarrowRudd.price(sigma, S, K, T, r, q, option_type, steps=100)
delta = JarrowRudd.calculate_delta(sigma, S, K, T, r, q, option_type, steps=100)
gamma = JarrowRudd.calculate_gamma(sigma, S, K, T, r, q, option_type, steps=100)
vega = JarrowRudd.calculate_vega(sigma, S, K, T, r, q, option_type, steps=100)
theta = JarrowRudd.calculate_theta(sigma, S, K, T, r, q, option_type, steps=100)
rho = JarrowRudd.calculate_rho(sigma, S, K, T, r, q, option_type, steps=100)
print(f"Jarrow-Rudd {option_type}: Price={price:.2f}, Delta={delta:.4f}, Gamma={gamma:.4f}, Vega={vega:.4f}, Theta={theta:.4f}, Rho={rho:.4f}")

# Cox-Ross-Rubinstein (CRR)
price = CoxRossRubinstein.price(sigma, S, K, T, r, q, option_type, steps=100)
delta = CoxRossRubinstein.calculate_delta(sigma, S, K, T, r, q, option_type, steps=100)
gamma = CoxRossRubinstein.calculate_gamma(sigma, S, K, T, r, q, option_type, steps=100)
vega = CoxRossRubinstein.calculate_vega(sigma, S, K, T, r, q, option_type, steps=100)
theta = CoxRossRubinstein.calculate_theta(sigma, S, K, T, r, q, option_type, steps=100)
rho = CoxRossRubinstein.calculate_rho(sigma, S, K, T, r, q, option_type, steps=100)
print(f"Cox-Ross-Rubinstein {option_type}: Price={price:.2f}, Delta={delta:.4f}, Gamma={gamma:.4f}, Vega={vega:.4f}, Theta={theta:.4f}, Rho={rho:.4f}")

Available Models

  1. Barone-Adesi Whaley: American, approximation model.
  2. Black-Scholes: European.
  3. Leisen-Reimer: American, binomial model.
  4. Jarrow-Rudd: European, binomial model.
  5. Cox-Ross-Rubinstein (CRR): American, binomial model.

Running Tests

The package includes unit tests in the tests/ folder. You can run them using unittest:

python -m unittest discover -s tests -p "test_options_models.py"

This command will execute the test suite and verify the functionality of each pricing model. If all tests pass, it confirms that each model in OptionsPricerLib is performing as expected.

Contributing

Contributions to OptionsPricerLib are welcome! If you find a bug or have suggestions for improvements, please open an issue or submit a pull request. Make sure to follow these guidelines:

  1. Fork the repository and clone it locally.
  2. Create a new branch for your feature or fix.
  3. Add your changes and include tests for any new functionality.
  4. Run the test suite to ensure all tests pass.
  5. Submit a pull request describing your changes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any questions or feedback, feel free to reach out to the author via GitHub: hedge0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optionspricerlib-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

OptionsPricerLib-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file optionspricerlib-0.1.0.tar.gz.

File metadata

  • Download URL: optionspricerlib-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for optionspricerlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ca1d752de6521322411f444a9e08442cd1d63573b3f012955174078bb2929fc
MD5 8c83b0bc79ee25d8b4c3ffb221bca82d
BLAKE2b-256 9ae1dfb72a7ea3514f665ed7008cb0b7bfd5aa84479ee4e34c835bcbe478ae0f

See more details on using hashes here.

File details

Details for the file OptionsPricerLib-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for OptionsPricerLib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d53f5fca6de4344acb5b1d936b14a73f4affa6bd82fedde5ee12aa7d7dae62a
MD5 d2d6a9264e41b90d8ea68fc30db8bbf2
BLAKE2b-256 0b329e411eab70dbb4d734065864b293a04c0838a123dac2863a8c4b19222d98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page