Skip to content

Commit 5ba12ae

Browse files
authored
Add maturity to options dataframe (#31)
1 parent 4c07e85 commit 5ba12ae

File tree

6 files changed

+1221
-1042
lines changed

6 files changed

+1221
-1042
lines changed

.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_jump_diffusion.py",
17+
"quantflow_tests/test_vault.py",
1818
]
1919
},
2020
]

poetry.lock

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

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "quantflow"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "quantitative analysis"
55
authors = [{ name = "Luca Sbardella", email = "[email protected]" }]
66
license = "BSD-3-Clause"
@@ -49,7 +49,7 @@ optional = true
4949
[tool.poetry.group.book.dependencies]
5050
jupyter-book = "^1.0.0"
5151
jupytext = "^1.13.8"
52-
plotly = "^5.20.0"
52+
plotly = "^6.2.0"
5353
jupyterlab = "^4.0.2"
5454
sympy = "^1.12"
5555
ipywidgets = "^8.0.7"

quantflow/options/calibration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def plot(
196196
max_moneyness_ttm=max_moneyness_ttm, support=support
197197
)
198198
return plot.plot_vol_surface(
199-
pd.DataFrame([d._asdict() for d in options]),
199+
pd.DataFrame([d.info_dict() for d in options]),
200200
model=model.df,
201201
**kwargs,
202202
)

quantflow/options/surface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ def calculate_price(self) -> OptionPrice:
260260
)
261261
return self
262262

263-
def _asdict(self) -> dict[str, Any]:
263+
def info_dict(self) -> dict[str, Any]:
264264
return dict(
265265
strike=float(self.strike),
266266
forward=float(self.forward),
267+
maturity=self.maturity,
267268
moneyness=self.moneyness,
268269
moneyness_ttm=self.moneyness / np.sqrt(self.ttm),
269270
ttm=self.ttm,
@@ -595,7 +596,7 @@ def options_df(
595596
initial_vol=initial_vol,
596597
converged=converged,
597598
)
598-
return pd.DataFrame([d._asdict() for d in data])
599+
return pd.DataFrame([d.info_dict() for d in data])
599600

600601
def as_array(
601602
self,

quantflow_tests/test_vault.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import tempfile
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
from quantflow.data.vault import Vault
7+
8+
9+
@pytest.fixture
10+
def vault():
11+
with tempfile.TemporaryDirectory() as temp_dir:
12+
yield Vault(Path(temp_dir) / "test_vault")
13+
14+
15+
def test_vault(vault: Vault) -> None:
16+
assert vault.path
17+
assert not vault.data
18+
vault.add("hello", "world")
19+
assert vault.data
20+
assert vault.get("hello") == "world"
21+
22+
v2 = Vault(vault.path)
23+
assert v2.path == vault.path
24+
assert v2.data == vault.data
25+
assert v2.get("hello") == "world"
26+
27+
assert vault.keys() == ["hello"]
28+
29+
vault.add("foo", "bar")
30+
assert vault.keys() == ["foo", "hello"]
31+
assert vault.delete("foo")
32+
assert vault.keys() == ["hello"]
33+
assert not vault.delete("foo")
34+
assert vault.keys() == ["hello"]

0 commit comments

Comments
 (0)