Skip to content

Commit eede96a

Browse files
committed
Added pricer price
1 parent e342c4e commit eede96a

21 files changed

Lines changed: 1305 additions & 787 deletions

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ applyTo: '/**'
2727
* The documentation for quantflow is available at `https://quantflow.quantmid.com`
2828
* Documentation is built using [mkdocs](https://www.mkdocs.org/) and stored in the `docs/` directory. The documentation source files are written in markdown format.
2929
* Do not use em dashes (—) in documentation files or docstrings. Use colons, parentheses, or restructure the sentence instead.
30+
* 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).

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ _build
3737

3838
# builds
3939
app/docs
40+
docs/examples_output

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"args": [
1515
"-x",
1616
"-vvv",
17-
"quantflow_tests/test_options.py",
17+
"quantflow_tests/test_options_pricer.py",
1818
]
1919
},
2020
]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ marimo: ## Run marimo for editing notebooks
2727
.PHONY: docs
2828
docs: ## build documentation
2929
@cp docs/index.md readme.md
30+
@uv run ./dev/build-examples
3031
@uv run mkdocs build
3132

3233
.PHONY: docs-serve

app/volatility_surface.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ def _(mo):
4343

4444

4545
@app.cell
46-
async def _():
46+
def _(mo):
47+
inverse = mo.ui.checkbox(value=True, label="Inverse options")
48+
inverse
49+
return (inverse,)
50+
51+
52+
@app.cell
53+
async def _(inverse):
4754
import pandas as pd
4855
from quantflow.data.deribit import Deribit
4956

5057
async with Deribit() as cli:
51-
loader = await cli.volatility_surface_loader("eth", exclude_open_interest=0)
58+
loader = await cli.volatility_surface_loader("eth", exclude_open_interest=0, inverse=inverse.value)
5259

5360
# build the volatility surface
5461
surface = loader.surface()

dev/build-examples

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
"""Run all example scripts in docs/examples/ and capture their stdout to .out files."""
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
7+
out_dir = Path("docs/examples_output")
8+
out_dir.mkdir(exist_ok=True)
9+
10+
examples = sorted(Path("docs/examples").glob("*.py"))
11+
failed = []
12+
13+
for script in examples:
14+
out_file = out_dir / script.with_suffix(".out").name
15+
print(f"running {script} -> {out_file}")
16+
result = subprocess.run(
17+
[sys.executable, str(script)],
18+
capture_output=True,
19+
text=True,
20+
)
21+
if result.returncode != 0:
22+
print(f"FAILED: {script}\n{result.stderr}", file=sys.stderr)
23+
failed.append(script)
24+
else:
25+
out_file.write_text(result.stdout)
26+
27+
if failed:
28+
sys.exit(1)

docs/api/options/black.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ $$
55
k = \log{\frac{K}{F}}
66
$$
77

8-
where \(K\) is the strike price and \(F\) is the forward price of the underlying asset.
8+
where $K$ is the strike price and $F$ is the forward price of the underlying asset.
9+
We also refers to this log-strike as `moneyness`, since it is zero for at-the-money (ATM) options,
10+
negative for in-the-money (ITM) call options, and positive for out-of-the-money (OTM) call options.
911

1012

1113
::: quantflow.options.bs.black_price
@@ -16,6 +18,8 @@ where \(K\) is the strike price and \(F\) is the forward price of the underlying
1618

1719
::: quantflow.options.bs.black_vega
1820

21+
::: quantflow.options.bs.BlackSensitivities
22+
1923
::: quantflow.options.bs.implied_black_volatility
2024

2125
::: quantflow.options.bs.ImpliedVols

docs/api/options/pricer.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ different stochastic volatility models.
77
::: quantflow.options.pricer.OptionPricer
88

99
::: quantflow.options.pricer.MaturityPricer
10+
11+
::: quantflow.options.pricer.ModelOptionPrice
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"option_type": "call",
3+
"moneyness": 0.0,
4+
"ttm": 1.0,
5+
"price": 0.19225250948685713,
6+
"delta": 0.4081907106007492,
7+
"gamma": 0.4063832911177639
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from quantflow.options.inputs import OptionType
2+
from quantflow.options.pricer import OptionPricer
3+
from quantflow.sp.heston import HestonJ
4+
from quantflow.utils.distributions import DoubleExponential
5+
6+
pricer = OptionPricer(
7+
model=HestonJ.create(
8+
DoubleExponential,
9+
vol=0.5,
10+
kappa=2,
11+
rho=-0.2,
12+
sigma=0.8,
13+
jump_fraction=0.5,
14+
jump_asymmetry=0.2,
15+
)
16+
)
17+
18+
# Price an ATM call option at time to maturity 1.0
19+
price = pricer.price(
20+
option_type=OptionType.call,
21+
strike=100.0,
22+
forward=100.0,
23+
ttm=1.0,
24+
)
25+
print(price.model_dump_json(indent=2))

0 commit comments

Comments
 (0)