-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
495 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.14.7 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# Hurst Exponent | ||
|
||
The [Hurst exponent](https://en.wikipedia.org/wiki/Hurst_exponent) is used as a measure of long-term memory of time series. It relates to the autocorrelations of the time series, and the rate at which these decrease as the lag between pairs of values increases. | ||
|
||
It is a statistics which can be used to test if a time-series is mean reverting or it is trending. | ||
|
||
```{code-cell} ipython3 | ||
from quantflow.sp.cir import CIR | ||
p = CIR(kappa=1, sigma=1) | ||
``` | ||
|
||
# Links | ||
|
||
* [Wikipedia](https://en.wikipedia.org/wiki/Hurst_exponent) | ||
* [Hurst Exponent for Algorithmic Trading | ||
](https://robotwealth.com/demystifying-the-hurst-exponent-part-1/) | ||
|
||
```{code-cell} ipython3 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.14.7 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# Volatility Surface | ||
|
||
In this notebook we illustrate the use of the Volatility Surface tool in the library. We use [deribit](https://docs.deribit.com/) options on BTCUSD as example. | ||
|
||
First thing, fetch the data | ||
|
||
```{code-cell} ipython3 | ||
from quantflow.data.client import HttpClient | ||
deribit_url = "https://test.deribit.com/api/v2/public/get_book_summary_by_currency" | ||
async with HttpClient() as cli: | ||
futures = await cli.get(deribit_url, params=dict(currency="BTC", kind="future")) | ||
options = await cli.get(deribit_url, params=dict(currency="BTC", kind="option")) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
from decimal import Decimal | ||
from quantflow.options.surface import VolSurfaceLoader | ||
from datetime import timezone | ||
from dateutil.parser import parse | ||
def parse_maturity(v: str): | ||
return parse(v).replace(tzinfo=timezone.utc, hour=8) | ||
loader = VolSurfaceLoader() | ||
for future in futures["result"]: | ||
if (bid := future["bid_price"]) and (ask := future["ask_price"]): | ||
maturity = future["instrument_name"].split("-")[-1] | ||
if maturity == "PERPETUAL": | ||
loader.add_spot(future, bid=Decimal(bid), ask=Decimal(ask)) | ||
else: | ||
loader.add_forward(parse_maturity(maturity), future, bid=Decimal(bid), ask=Decimal(ask)) | ||
for option in options["result"]: | ||
if (bid := option["bid_price"]) and (ask := option["ask_price"]): | ||
_, maturity, strike, ot = option["instrument_name"].split("-") | ||
call = ot == "C" | ||
bid = Decimal(bid) | ||
ask = Decimal(ask) | ||
loader.add_option(Decimal(strike), parse_maturity(maturity), call, option, bid=Decimal(bid), ask=Decimal(ask)) | ||
``` | ||
|
||
Once we have loaded the data, lets create the surface and display the term-structure of forwards | ||
|
||
```{code-cell} ipython3 | ||
vs = loader.surface() | ||
vs.term_structure() | ||
``` | ||
|
||
This method allows to inspect bid/ask for call options at a given cross section | ||
|
||
```{code-cell} ipython3 | ||
vs.options_df(index=2) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
vs.bs(index=2).options_df(index=2) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
len(r) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.