Skip to main content

Stochastic models to price financial options

Project description

Vanilla Option Pricing

Build Status Coverage Status Documentation Status

A simple Python package implementing stochastic models to price financial options.
Theoretical background and comprehensive explanation of models and their paramenters 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, available on arXiv

Installing

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

To install the package using pip:

pip install vanilla_option_pricing

Quickstart

Let's create a sample call option

from datetime import datetime, timedelta
from vanilla_option_princing.option import VanillaOption
from vanilla_option_princing.models import BlackScholes
from vanilla_option_pricing.calibration import ModelCalibration

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 Black-Sholes model with it. Of course, if now we ask the model to price the option, we'll get the real option price.

volatility = option.implied_volatility_of_undiscounted_price
model = BlackScholes(volatility).as_option_pricing_model()
model_price = model.price_option_black(option)
print(f'Actual price: {option.price}, model price: {model_price}')

We can also try and calibrate the parameters of a model against listed options.

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))
]

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

model = BlackScholes(0.2).as_option_pricing_model()
calibration = ModelCalibration(data_set)

result, trained_model = calibration.calibrate_model(model)
print(result)
print(f'Calibrated implied volatility: {trained_model.parameters[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

vanilla_option_pricing-0.0.7.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

vanilla_option_pricing-0.0.7-py3.6.egg (16.3 kB view hashes)

Uploaded Source

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