google / google/tf-quant-finance

SABR calibration

Open
#58 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
5.5k
Forks
698
PR merge metrics
No merged PRs in 30d

Description

Hello,
I'm trying to use the SABR calibration with real BTC option prices but it stops right away without any error message (is_converged is False).
If anyone could help to see what is wrong with this pretty simple code:
[Colab notebook (created a wheel with the latest code)](https://colab.research.google.com/drive/120q5yXZ7p2PvHupNPnOFiLZrknHHiU9A?usp=sharing)

```python
import pandas as pd
import requests
import tf_quant_finance as tff
import time
from datetime import datetime
import numpy

vals = pd.DataFrame(requests.get(
'https://www.deribit.com/api/v2/public/get_instruments?currency=BTC&expired=false&kind=option').json()['result'])
jul_exp = vals[(vals['expiration_timestamp'] == 1627632000000)]
jul_exp['price'] = [requests.get(f'https://www.deribit.com/api/v2/public/ticker?instrument_name={x}').json()['result']['last_price'] for x in jul_exp['instrument_name']]
jul_exp.dropna(subset=['price'], inplace = True)
underlying = requests.get('https://www.deribit.com/api/v2/public/ticker?instrument_name=BTC-30JUL21').json()['result']
jul_exp['price'] = jul_exp['price'] * underlying['index_price']
is_call = numpy.array([[t == 'call' for t in jul_exp['option_type']]], dtype=numpy.bool)
delta =(( jul_exp.iloc[0]['expiration_timestamp']/1000 - time.time()) / 60 / 60 / 24) / 365
dtype = numpy.float64
models, is_converged, it = tff.models.sabr.approximations.calibration(
prices=numpy.array([jul_exp['price'].to_numpy()], dtype=dtype),
strikes=numpy.array([jul_exp['strike'].to_numpy()], dtype=dtype),
expiries=numpy.array([delta], dtype=dtype),
forwards=numpy.array([underlying['index_price']], dtype=dtype),
is_call_options=is_call,
beta=numpy.array([0.5], dtype=dtype),
calibrate_beta=True,
nu=numpy.array([0.1], dtype=dtype),
nu_lower_bound=0.0,
nu_upper_bound=10.0,
rho=numpy.array([0.0], dtype=dtype),
rho_lower_bound=-0.75,
rho_upper_bound=0.75,
maximum_iterations=1000)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.