Skip to content

Commit f74b14f

Browse files
committed
Fixing forwards rates
1 parent 2181d94 commit f74b14f

10 files changed

Lines changed: 429 additions & 70 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ applyTo: '/**'
2828
* The documentation for quantflow is available at `https://quantflow.quantmid.com`
2929
* Documentation is built using [mkdocs](https://www.mkdocs.org/) and stored in the `docs/` directory. The documentation source files are written in markdown format.
3030
* Do not use em dashes (—) in documentation files or docstrings. Use colons, parentheses, or restructure the sentence instead.
31-
* Math in documentation and docstrings uses `$...$` for inline and `$$...$$` or `\begin{equation}...\end{equation}` for block equations. Do not use `.. math::` or `:math:` (RST syntax).
31+
* Math in documentation and docstrings: always use `\begin{equation}...\end{equation}` for any formula or equation. Use `$...$` only for brief inline references to variables (e.g. $F$, $K$). Do not use `$$...$$`, `` `...` ``, or RST syntax (`.. math::`, `:math:`).
3232
* Glossary entries in `docs/glossary.md` must be kept in alphabetical order.
3333
* To rebuild doc examples run `uv run ./dev/build-examples` — runs all scripts in `docs/examples/` and writes their output to `docs/examples_output/`
3434

app/volatility_surface.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ def _(mo):
4242
return
4343

4444

45-
@app.cell
46-
def _():
47-
kwargs = dict()
48-
return
49-
50-
5145
@app.cell
5246
def _(mo):
5347
asset = mo.ui.dropdown(["btc", "eth", "sol"], value="btc", label="asset")
@@ -57,7 +51,7 @@ def _(mo):
5751

5852

5953
@app.cell
60-
async def _(asset, inverse):
54+
async def _(asset, inverse, mo):
6155
import pandas as pd
6256
from quantflow.data.deribit import Deribit
6357

@@ -74,18 +68,43 @@ async def _(asset, inverse):
7468
surface.bs()
7569
# disable outliers
7670
surface.disable_outliers()
77-
surface.plot3d()
78-
return pd, surface
71+
#
72+
def int_or_none(v):
73+
try:
74+
return int(v)
75+
except TypeError:
76+
return None
77+
78+
maturites = [c.maturity for c in surface.maturities]
79+
maturity_dropdown = mo.ui.dropdown(
80+
options={m.strftime("%Y-%m-%d"): i for i, m in enumerate(maturites)},
81+
label="Maturity"
82+
)
83+
maturity_dropdown
84+
return int_or_none, maturity_dropdown, pd, surface
7985

8086

8187
@app.cell
82-
def _(pd, surface):
88+
def _(int_or_none, maturity_dropdown, surface):
89+
index = int_or_none(maturity_dropdown.value)
90+
surface.plot3d(index=index)
91+
return (index,)
92+
93+
94+
@app.cell
95+
def _(index, pd, surface):
8396
# display inputs - only options with converged implied volatility
84-
surface_inputs = surface.inputs(converged=True)
97+
surface_inputs = surface.inputs(converged=True, index=index)
8598
pd.DataFrame([i.model_dump() for i in surface_inputs.inputs])
8699
return
87100

88101

102+
@app.cell
103+
def _(surface):
104+
surface.term_structure()
105+
return
106+
107+
89108
@app.cell
90109
def _():
91110
return

docs/api/utils/rates.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Numbers
2+
3+
4+
::: quantflow.utils.interest_rates.Rate

docs/glossary.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ The [probability density function](https://en.wikipedia.org/wiki/Probability_den
9797
F_x(x) = \int_{-\infty}^x f_x(s) ds
9898
\end{equation}
9999

100+
## Put-Call Parity
101+
102+
Put-call parity is a no-arbitrage relationship between the prices of European call
103+
and put options with the same strike $K$ and maturity. Denoting forward-space prices
104+
$c = C/F$ and $p = P/F$ (see [Black Pricing](api/options/black.md)), the relationship
105+
reads:
106+
107+
\begin{equation}
108+
c - p = 1 - \frac{K}{F} = 1 - e^k
109+
\end{equation}
110+
111+
where $k$ is the [log-strike](#log-strike).
112+
In quoting currency terms, multiplying through by $F$:
113+
114+
\begin{equation}
115+
C - P = F - K
116+
\end{equation}
117+
100118
## Time To Maturity (TTM)
101119

102120
Time to maturity is the time remaining until an option or forward contract expires,

quantflow/options/inputs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class VolSurfaceSecurity(BaseModel):
4747
def vol_surface_type(self) -> VolSecurityType:
4848
raise NotImplementedError("vol_surface_type must be implemented by subclasses")
4949

50+
@classmethod
51+
def forward(cls) -> Self:
52+
raise NotImplementedError("forward_input must be implemented by subclasses")
53+
5054

5155
class DefaultVolSecurity(VolSurfaceSecurity):
5256
security_type: VolSecurityType = Field(

0 commit comments

Comments
 (0)