Skip to main content

A package for Black-Scholes option pricing and implied volatility calculation(European Options only)

Project description

Calculation Of Option Greeks and Implied Volatility in Python

The aim of this package is to calculate Option Greeks and Implied Volatility for European options. The function takes input in a similar form to the popular Hoadley add-in used in Excel.

Functions:

blackScholes(calculation_type, Option_type, K, S, T, sigma, r = 0): Calculates option price, delta, gamma, vega, theta, or rho. implied_volatility(Option_type, K, S, T, Option_price, r = 0, tol = 0.0001, max_iterations = 100): Estimates implied volatility using Newton-Ralphson method.

Calculations:

  1. Performs price, delta, gamma, vega, theta, and rho calculations for both call and put options.
  2. Implied Volatility: Estimates implied volatility using numerical methods. Input Validation: Includes checks for invalid inputs (e.g., NaN values, zero strike price). Error Handling: Handles potential errors (e.g., incorrect option type, wrong Datatype entry when number is expected, etc.).

Input Parameters:

calculation_type: Specifies the type of calculation to perform (price, delta, gamma, vega, theta, rho).
   i. Use 'p' for price.
   ii. Use 'd' for delta.
   iii. Use 'g' for gamma.
   iv. Use 'v' for vega.
   v. Use 't' for theta.
   vi. Use 'r' for rho.
Option_type: Specifies the option type (call or put).
K: Strike price.
S: Underlying asset price.
T: Time to expiration (in Days).
sigma: Volatility.
r: Risk-free interest rate.
Option_price: Market price of the option (used for implied volatility calculation).
tol: Tolerance level for implied volatility calculation.
max_iterations: Maximum number of iterations for implied volatility calculation.

Example Usage

Here is an example of how to use the blackScholes and implied_volatility functions:

from hoadleyYaPu import hoadleyYaPu

# Calculate call and put prices using the Black-Scholes model
callprice = hoadleyYaPu.blackScholes("p", "c", 100, 100, 15, 0.1855, 0)
putprice = hoadleyYaPu.blackScholes("p", "p", 1350, 1400, 15, 0.25, 0)

# Calculate the Greeks for a call option using the Black-Scholes model
callDelta = hoadleyYaPu.blackScholes("d", "c", 1350, 1400, 15, 0.25, 0)
callgamma = hoadleyYaPu.blackScholes("g", "c", 1350, 1400, 15, 0.25, 0)
callvega = hoadleyYaPu.blackScholes("v", "c", 1350, 1400, 15, 0.25, 0)
calltheta = hoadleyYaPu.blackScholes("t", "c", 1350, 1400, 15, 0.25, 0)
callrho = hoadleyYaPu.blackScholes("r", "c", 1350, 1400, 15, 0.25, 0)

# Calculate implied volatility for call and put options
callIV = hoadleyYaPu.implied_volatility("c", 42200, 41653.55, 1, 14.05, 0)
putIV = hoadleyYaPu.implied_volatility("p", 42200, 41653.55, 15, 550, 0)

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

hoadleyyapu-0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

hoadleyYaPu-0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file hoadleyyapu-0.2.tar.gz.

File metadata

  • Download URL: hoadleyyapu-0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for hoadleyyapu-0.2.tar.gz
Algorithm Hash digest
SHA256 a713ed9b4fdb5efc6de80d5d5eb89d77dfcea601cbea6f66ea9b323f64082e49
MD5 cc3d2c608f69b50c3d117dd2ff6441f9
BLAKE2b-256 1e2cecfcea59c298670e3ffb115d42972dbc465a19cf18afd997ec98242fb098

See more details on using hashes here.

File details

Details for the file hoadleyYaPu-0.2-py3-none-any.whl.

File metadata

  • Download URL: hoadleyYaPu-0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for hoadleyYaPu-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9bd036bf89d0628f321a60cd9a628c3e334939429f1cb5fd37f35515ac944c04
MD5 3db3c03261ca47f0ebf05f6833e23293
BLAKE2b-256 8c0867df674993bcff9891771f08a8f928440dd7a81e6a3d1aa22fc2eda4ddc5

See more details on using hashes here.

Supported by

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