Skip to main content

An intuitive and versatile options library.

Project description

OptiCalc: An intuitive and versatile options library

Overview

OptiCalc is a Python library designed to provide the user with a high-level and intuitive API for option pricing, greeks calculation, implied volatility calculation and more.

The core idea behind OptiCalc is to allow for complex calculations with a simple interface, filling the gap between simple End-user developed applications (EUDAs) and more advanced libraries/modules such as QuantLib. OptiCalc is not necessarily intended for speed or low-level complexity. For that, QuantLib is much more suitable.

Table of Contents

Key Features

High-level Option Classes

Currently 4 option classes (EuropeanOption, AmericanOption, BermudaOption and Option) are available for use.

These option classes offer flexibility with their attributes, from simple, minimal inputs for quick calculations to more complex ones:

import opticalc as op

# Minimal inputs
new_european_option = op.EuropeanOption(s = 100,
                                        k = 110,
                                        t = 0.10,
                                        r = 0.04,
                                        q = 0.00,
                                        sigma = 0.20,
                                        option_type = op.OptionType.Call)

# All possible inputs used
new_american_option = op.Option(s = 200,
                                k = 150,
                                t = 0.25,
                                r = 0.035,
                                q = 0.05,
                                sigma = 0.15,
                                option_type = "put",
                                exercise_style = op.ExerciseStyle.American,
                                b = None,
                                rf = 0.02,
                                premium = 5.5,
                                transaction_costs = 0.233,
                                underlying_type = op.Underlying.FX,
                                direction = "long",
                                underlying_contracts = 100)

Dynamic input

Assigning values to an option's attributes is also handled internally in a dynamic way, which allows for ease of use and personal preference when changing or assigning values.

import opticalc as op

option = op.Option(...)

option.option_type = op.OptionType.Call
print(option.option_type)  # Output: op.OptionType.Call

option.option_type = "put"
print(option.option_type)  # Output: op.OptionType.Put

option.option_type = "Call"
print(option.option_type)  # Output: op.OptionType.Call

option.exercise_style = "european"
print(option.exercise_style)  # Output: op.ExerciseStyle.European

option.exercise_style = "BERMUDA"
print(option.exercise_style)  # Output: op.ExerciseStyle.Bermuda

option.underlying_type = op.Underlying.FX
print(option.underlying_type)  # Output: op.Underlying.FX

option.direction = "lOnG"
print(option.direction)  # Output: op.Direction.Long

The cost-of-carry logic

OptiCalc includes flexible handling of the option's cost of carry factor b. The cost of carry can either be defined when initializing a Option-type object or left to default to None. In that case, OptiCalc will try to infer b by looking at the option's underlying, where b will be set in the following manner:

Future:         b = 0
FX:             b = r - rf
Stock Index:    b = r - q
Bond:           b = r - q
Commodity:      b = r - q
Swap:           b = r - q
Not defined:    b = r - q
import opticalc as op

underlying_price = 80
strike = 65
time_to_expiry = 0.333
risk_free_rate = 0.04
dividends = 0.01
volatility = 0.20
option_type = op.OptionType.Put
# b not defined!

new_option = op.EuropeanOption(underlying_price, strike, time_to_expiry,
                               risk_free_rate, dividends, volatility, option_type)

Since b is not explicitly defined when initializing the object, currently b = None. Given that, OptiCalc will autocalculate b. Since the underlying type is not defined, OptiCalc defaults to b = r - q.

print(new_option.b)  # Output: 0.03

Should the user want to, one can also modify b by simply assigning a new value to b. This will assign b a custom value which will means in future calls, no autocalculation based on the underlying will take place. This new value can simply be removed by calling the property reset_b which will result in b simply falling back to appropriate value based on the underlying or r - q in the default case.

new_option.b = 0.05
print(new_option.b)  # Output after modification: 0.05

new_option.reset_b
print(new_option.b) # Output: 0.03

new_option.underlying_type = op.Underlying.Future
new_option.reset_b
print(new_option.b) # Output: 0.00

Pricers

As of now, OptiCalc offers 5 different pricing classes, with 15 pricing methods available for european-style options, 12 for american-style options and 8 for bermuda-style options.

  • Black Scholes (European options)

    • Black-Scholes
    • Black-Scholes-Merton
    • Black-76
    • Garman Kohlhagen
    • Adaptive Black-Scholes
  • Binomial Trees (European, Bermuda and American options)

    • Cox-Ross-Rubinstein
    • Cox-Ross-Rubinstein with drift
    • Rendleman-Bartter
    • Leisen-Reimer
    • Jarrow-Rudd
    • Jarrow-Rudd with risk neutrality
    • Tian
    • Universal binomial tree
  • Bjerksund-Stensland (American options)

    • Bjerksund-Stensland 1993 model
    • Bjerksund-Stensland 2002 model
    • Combined Bjerksund-Stensland 1993 and 2002 model
  • Barone-Adesi and Whaley (American options)

    • Barone-Adesi and Whaley model
  • Bachelier (European options)

    • Classic Bachelier model
    • Modified Bachelier model

License

OptiCalc is released under a MIT License

Dependencies

  • SciPy: Adds statistical and probability functions like distributions.
  • NumPy: Adds support for vectorized operations and the functions to process these.
  • Matplotlib: Allows for visualization of greeks and option payoffs.

Roadmap

As OptiCalc is still under development, many features are still work-in progress and will be implemented in a similar order following the outline below:

  • New pricing modules
    • Longstaff-Schwartz
    • Heston
    • Merton Jump Diffusion
    • Variance Gamma
    • Trinomial Trees
    • Monte Carlo
  • Greeks support for american options
  • Implied volatility
  • Testing
  • Expanded Documentation
  • Extend support for exotic options (Asian, Barrier, Basket...)
  • Global settings class for constants etc.
  • Expand Plotting (Payoff graphs, Greeks)
  • OptionStrategy class (Allows for the combination of several options)
    • Aggregate greeks
  • Fully vectorized option classes (Option chains)

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

options_calculator-0.1.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

options_calculator-0.1.1-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file options_calculator-0.1.1.tar.gz.

File metadata

  • Download URL: options_calculator-0.1.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for options_calculator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e90221cdbabc8826b422530c5d8f7ab2243cc0b9b154948cdc19d9da0e8727be
MD5 5e3024fb30d94ad3b489ed63a63b66f4
BLAKE2b-256 5f2f5faa9debcc4691774bf49e1027edb830f7f6a3190e5972e4ab01f20d3153

See more details on using hashes here.

File details

Details for the file options_calculator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for options_calculator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c1b5171bb9f33f2f89be5b7d06ac51dde411b93349dbc4068edd0d577148719
MD5 e5e9f3786ec7646cee297e022b887119
BLAKE2b-256 096c110bc3bc8ebc3e005decd92c7bebfc7fe4606ab9a73dffb10fb1b3c10234

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