Skip to content

Commit a76798f

Browse files
committed
More docs
1 parent 27b3544 commit a76798f

File tree

17 files changed

+189
-15
lines changed

17 files changed

+189
-15
lines changed

notebooks/api/data/deribit.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
================
2+
Deribit
3+
================
4+
5+
.. currentmodule:: quantflow.data.deribit
6+
7+
.. autoclass:: Deribit
8+
:members:
9+
:member-order: groupwise
10+
:autosummary:
11+
:autosummary-nosignatures:

notebooks/api/data/fmp.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
================
2+
FMP
3+
================
4+
5+
.. currentmodule:: quantflow.data.fmp
6+
7+
.. autoclass:: FMP
8+
:members:
9+
:member-order: groupwise
10+
:autosummary:
11+
:autosummary-nosignatures:

notebooks/api/data/fred.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
================
2+
Fred
3+
================
4+
5+
.. currentmodule:: quantflow.data.fred
6+
7+
.. autoclass:: Fred
8+
:members:
9+
:member-order: groupwise
10+
:autosummary:
11+
:autosummary-nosignatures:

notebooks/api/data/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ Data fetching
44

55
.. currentmodule:: quantflow.data
66

7+
The :mod:`quantflow.data` module provides classes and functions for fetching data from various sources.
8+
To use the module the package must be installed with the optional `data` extra.
9+
```
10+
pip install quantflow[data]
11+
```
12+
13+
.. toctree::
14+
:maxdepth: 1
15+
16+
fmp
17+
fred
18+
deribit

notebooks/api/sp/heston.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ Heston process
1010
:autosummary:
1111
:autosummary-nosignatures:
1212

13+
14+
.. autoclass:: HestonJ
15+
:members:
16+
:member-order: groupwise
17+
:autosummary:
18+
:autosummary-nosignatures:

notebooks/reference/glossary.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,20 @@ Moneyness is used in the context of option pricing and it is defined as
4545

4646
where $K$ is the strike and $F$ is the Forward price. A positive value implies strikes above the forward, which means put options are in the money and call options are out of the money.
4747

48-
```{code-cell}
4948

50-
```
49+
## Moneyness Time Adjusted
50+
51+
The time-adjusted moneyness is used in the context of option pricing in order to compare options with different maturities. It is defined as
52+
53+
\begin{equation}
54+
\frac{1}{\sqrt{T}}\ln\frac{K}{F}
55+
\end{equation}
56+
57+
where $K$ is the strike and $F$ is the Forward price and $T$ is the time to maturity.
58+
59+
The key reason for dividing by the square root of time-to-maturity is related to how volatility and price movement behave over time.
60+
The price of the underlying asset is subject to random fluctuations, if these fluctuations follow a Brownian motion than the
61+
standard deviation of the price movement will increase with the square root of time.
5162

5263
## Probability Density Function (PDF)
5364

poetry.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ aio-fluid = {version = "^1.2.1", extras=["http"], optional = true}
2424
rich = {version = "^13.9.4", optional = true}
2525
click = {version = "^8.1.7", optional = true}
2626
holidays = {version = "^0.63", optional = true}
27+
async-cache = {version = "^1.1.1", optional = true}
2728

2829
[tool.poetry.group.dev.dependencies]
2930
black = "^24.1.1"
@@ -37,7 +38,14 @@ isort = "^5.13.2"
3738

3839
[tool.poetry.extras]
3940
data = ["aio-fluid"]
40-
cli = ["asciichartpy", "prompt-toolkit", "rich", "click", "holidays"]
41+
cli = [
42+
"asciichartpy",
43+
"async-cache",
44+
"prompt-toolkit",
45+
"rich",
46+
"click",
47+
"holidays"
48+
]
4149

4250
[tool.poetry.group.book]
4351
optional = true
@@ -89,6 +97,7 @@ warn_no_return = true
8997
[[tool.mypy.overrides]]
9098
module = [
9199
"asciichartpy.*",
100+
"cache.*",
92101
"quantflow_tests.*",
93102
"IPython.*",
94103
"pandas.*",

quantflow/cli/commands/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,10 @@ class options:
115115
show_default=True,
116116
help="Historical period",
117117
)
118+
index = click.option(
119+
"-i",
120+
"--index",
121+
type=int,
122+
default=-1,
123+
help="maturity index",
124+
)

quantflow/cli/commands/crypto.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import click
66
import pandas as pd
77
from asciichartpy import plot
8+
from cache import AsyncTTL
89
from ccy.cli.console import df_to_rich
910

1011
from quantflow.data.deribit import Deribit
12+
from quantflow.options.surface import VolSurface
1113

1214
from .base import QuantContext, options, quant_group
1315

@@ -36,6 +38,48 @@ def volatility(currency: str, length: int, height: int, chart: bool) -> None:
3638
ctx.qf.print(df_to_rich(df))
3739

3840

41+
@crypto.command()
42+
@click.argument("currency")
43+
def term_structure(currency: str) -> None:
44+
"""Provides information about the term structure for given cryptocurrency"""
45+
ctx = QuantContext.current()
46+
vs = asyncio.run(get_vol_surface(currency))
47+
ts = vs.term_structure().round({"ttm": 4})
48+
ts["open_interest"] = ts["open_interest"].map("{:,d}".format)
49+
ts["volume"] = ts["volume"].map("{:,d}".format)
50+
ctx.qf.print(df_to_rich(ts))
51+
52+
53+
@crypto.command()
54+
@click.argument("currency")
55+
@options.index
56+
@options.height
57+
@options.chart
58+
def implied_vol(currency: str, index: int, height: int, chart: bool) -> None:
59+
"""Display the Volatility Surface for given cryptocurrency
60+
at a given maturity index
61+
"""
62+
ctx = QuantContext.current()
63+
vs = asyncio.run(get_vol_surface(currency))
64+
index_or_none = None if index < 0 else index
65+
vs.bs(index=index_or_none)
66+
df = vs.options_df(index=index_or_none)
67+
df["implied_vol"] = df["implied_vol"] * 100
68+
df = df.round({"ttm": 4, "moneyness": 4, "moneyness_ttm": 4, "implied_vol": 5})
69+
if chart:
70+
data = df["implied_vol"].tolist()
71+
ctx.qf.print(plot(data, {"height": height}))
72+
else:
73+
ctx.qf.print(df_to_rich(df))
74+
75+
3976
async def get_volatility(ctx: QuantContext, currency: str) -> pd.DataFrame:
4077
async with Deribit() as client:
4178
return await client.get_volatility(params=dict(currency=currency))
79+
80+
81+
@AsyncTTL(time_to_live=10)
82+
async def get_vol_surface(currency: str) -> VolSurface:
83+
async with Deribit() as client:
84+
loader = await client.volatility_surface_loader(currency)
85+
return loader.surface()

0 commit comments

Comments
 (0)