Stochastic models to price financial options
Project description
Vanilla Option Pricing
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
Built Distribution
File details
Details for the file vanilla_option_pricing-0.0.7.tar.gz
.
File metadata
- Download URL: vanilla_option_pricing-0.0.7.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aba295923db633ae4179339a99af99e22fee423bb5f31f3a857afe877bcebe1 |
|
MD5 | 809d4f202b7b88a7b93799b4b3a7ea90 |
|
BLAKE2b-256 | e82f3ac1d37f30b936ef6511c7501a497bee651ce0fb4b9998fc5d96e52607be |
File details
Details for the file vanilla_option_pricing-0.0.7-py3.6.egg
.
File metadata
- Download URL: vanilla_option_pricing-0.0.7-py3.6.egg
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c8a9c30eb2473a0240390d21e4a8f49163aaf6ccf1a981df528410aa9833f8 |
|
MD5 | 0acc3d3ec2a0a4c3a1ac8eec44df46fa |
|
BLAKE2b-256 | 44cb96646625630ef949635717c09791d4594a0a76d28996905f1c430e61207a |