Skip to main content

Vanilla Option Pricing

Actions Status codecov Documentation Status Downloads

A Python package implementing stochastic models to price financial options.
The theoretical background and a comprehensive explanation of models and their parameters can be found is the paper Fast calibration of two-factor models for energy option pricing by Emanuele Fabbiani, Andrea Marziali and Giuseppe De Nicolao, freely available on arXiv.

Installing

The preferred way to install the package is using pip, but you can also download the code and install from source

To install the package using pip:

pip install vanilla_option_pricing

Quickstart

Let's create a call option.

from datetime import datetime, timedelta
from vanilla_option_pricing.option import VanillaOption

option = VanillaOption(
    spot=100,
    strike=101,
    dividend=0,
    date=datetime.today(),
    maturity=datetime.today() + timedelta(days=30),
    option_type='c',
    price=1,
    instrument='TTF'
)

We can compute the implied volatility and create a Geometric Brownian Motion model with it. Of course, if now we ask price the option using the Black framework, we'll get back the initial price.

from vanilla_option_pricing.models import GeometricBrownianMotion

volatility = option.implied_volatility_of_undiscounted_price
gbm_model = GeometricBrownianMotion(volatility)
gbm_price = gbm_model.price_option_black(option)
print(f'Actual price: {option.price}, model price: {gbm_price}')

But, if we adopt a different model, say a Log-spot price mean reverting to generalised Wiener process model (MLR-GW), we will get a different price.

import numpy as np
from vanilla_option_pricing.models import LogMeanRevertingToGeneralisedWienerProcess

p_0 = np.eye(2)
model = LogMeanRevertingToGeneralisedWienerProcess(p_0, 1, 1, 1)
lmrgw_price = model.price_option_black(option)
print(f'Actual price: {option.price}, model price: {lmrgw_price}')

In the previous snippet, the parameters of the LMR-GW model were chosen at random. We can also calibrate the parameters of a model against listed options.

from datetime import date
from vanilla_option_pricing.option import VanillaOption
from vanilla_option_pricing.models import OrnsteinUhlenbeck, GeometricBrownianMotion
from vanilla_option_pricing.calibration import ModelCalibration

data_set = [
    VanillaOption('TTF', 'c', date(2018, 1, 1), 2, 101, 100, date(2018, 2, 1)),
    VanillaOption('TTF', 'p', date(2018, 1, 1), 2, 98, 100, date(2018, 2, 1)),
    VanillaOption('TTF', 'c', date(2018, 1, 1), 5, 101, 100, date(2018, 5, 31))
]

models = [
    GeometricBrownianMotion(0.2),
    OrnsteinUhlenbeck(p_0=0, l=100, s=2)
]
calibration = ModelCalibration(data_set)

print(f'Implied volatilities: {[o.implied_volatility_of_undiscounted_price for o in data_set]}\n')

for model in models:
    result, trained_model = calibration.calibrate_model(model)
    print('Optimization results:')
    print(result)
    print(f'Calibrated parameters: {trained_model.parameters}\n\n')

Metadata

Release files for vanilla-option-pricing 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vanilla-option-pricing 0.1.0
File Size Uploaded Provenance Actions
vanilla-option-pricing-0.1.0.tar.gz 8.9 kB Without provenance Details for vanilla-option-pricing-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vanilla-option-pricing 0.1.0
File Interpreter ABI Platform Actions
vanilla_option_pricing-0.1.0-py3-none-any.whl Python 3 none any Details for vanilla_option_pricing-0.1.0-py3-none-any.whl

Total release size: 17.6 kB

Release files / vanilla-option-pricing-0.1.0.tar.gz

Download URL vanilla-option-pricing-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3a05532cc99bccb3d8bdc47a77df5b63b912e8a54744648f3e335b6cdf43977c
BLAKE2b-256 checksum
How to use checksums
91245e19d3b874d00cff891d1fce35b42902df6dd69cb669e115cbc8c1fdd6e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.7 Windows/10

Release files / vanilla_option_pricing-0.1.0-py3-none-any.whl

Download URL vanilla_option_pricing-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
965266631a6cf3b525e16f92a471b01657e527c497ef97dd2a2820d4486bc4ab
BLAKE2b-256 checksum
How to use checksums
041b58e0a18e9f19d316757bf242efc27edf0284b3ed00bf25ee9088a579f4a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.7 Windows/10

Security for vanilla-option-pricing 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page