Skip to content

Commit 30535bb

Browse files
committed
Add nbconvert command
1 parent c9c9714 commit 30535bb

32 files changed

+222
-202
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ book: ## Build static jupyter {book}
3535
nbconvert: ## Convert notebooks to myst markdown
3636
poetry run ./dev/nbconvert
3737

38+
.PHONY: nbsync
39+
nbsync: ## Sync python myst notebooks to .ipynb files - needed for vs notebook development
40+
poetry run ./dev/nbsync
41+
3842
.PHONY: sphinx-config
3943
sphinx-config: ## Build sphinx config
4044
poetry run jupyter-book config sphinx notebooks

dev/nbsync

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
for file in notebooks/**/*.md
5+
do
6+
jupytext "$file" -s
7+
done

notebooks/applications/calibration.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.14.7
8+
jupytext_version: 1.16.6
99
kernelspec:
1010
display_name: Python 3 (ipykernel)
1111
language: python
@@ -26,7 +26,7 @@ Early pointers
2626
For calibration we use {cite:p}`ukf`.
2727
Lets consider the Heston model as a test case
2828

29-
```{code-cell} ipython3
29+
```{code-cell}
3030
from quantflow.sp.heston import Heston
3131
3232
pr = Heston.create(vol=0.6, kappa=1.3, sigma=0.8, rho=-0.6)
@@ -82,11 +82,11 @@ the state equation is given by
8282
X_{t+1} &= \left[\begin{matrix}\kappa\left(\theta\right) dt \\ 0\end{matrix}\right] +
8383
\end{align}
8484

85-
```{code-cell} ipython3
85+
```{code-cell}
8686
[p for p in pr.variance_process.parameters]
8787
```
8888

89-
```{code-cell} ipython3
89+
```{code-cell}
9090
9191
```
9292

@@ -106,7 +106,7 @@ x_t &= \left[\begin{matrix}\nu_t && w_t && z_t\end{matrix}\right]^T \\
106106
\bar{x}_t = {\mathbb E}\left[x_t\right] &= \left[\begin{matrix}\nu_t && 0 && 0\end{matrix}\right]^T
107107
\end{align}
108108

109-
```{code-cell} ipython3
109+
```{code-cell}
110110
from quantflow.data.fmp import FMP
111111
frequency = "1min"
112112
async with FMP() as cli:
@@ -115,13 +115,13 @@ df = df.sort_values("date").reset_index(drop=True)
115115
df
116116
```
117117

118-
```{code-cell} ipython3
118+
```{code-cell}
119119
import plotly.express as px
120120
fig = px.line(df, x="date", y="close", markers=True)
121121
fig.show()
122122
```
123123

124-
```{code-cell} ipython3
124+
```{code-cell}
125125
import numpy as np
126126
from quantflow.utils.volatility import parkinson_estimator, GarchEstimator
127127
df["returns"] = np.log(df["close"]) - np.log(df["open"])
@@ -132,43 +132,43 @@ fig = px.line(ds["returns"], markers=True)
132132
fig.show()
133133
```
134134

135-
```{code-cell} ipython3
135+
```{code-cell}
136136
import plotly.express as px
137137
from quantflow.utils.bins import pdf
138138
df = pdf(ds["returns"], num=20)
139139
fig = px.bar(df, x="x", y="f")
140140
fig.show()
141141
```
142142

143-
```{code-cell} ipython3
143+
```{code-cell}
144144
g1 = GarchEstimator.returns(ds["returns"], dt)
145145
g2 = GarchEstimator.pk(ds["returns"], ds["pk"], dt)
146146
```
147147

148-
```{code-cell} ipython3
148+
```{code-cell}
149149
import pandas as pd
150150
yf = pd.DataFrame(dict(returns=g2.y2, pk=g2.p))
151151
fig = px.line(yf, markers=True)
152152
fig.show()
153153
```
154154

155-
```{code-cell} ipython3
155+
```{code-cell}
156156
r1 = g1.fit()
157157
r1
158158
```
159159

160-
```{code-cell} ipython3
160+
```{code-cell}
161161
r2 = g2.fit()
162162
r2
163163
```
164164

165-
```{code-cell} ipython3
165+
```{code-cell}
166166
sig2 = pd.DataFrame(dict(returns=np.sqrt(g2.filter(r1["params"])), pk=np.sqrt(g2.filter(r2["params"]))))
167167
fig = px.line(sig2, markers=False, title="Stochastic volatility")
168168
fig.show()
169169
```
170170

171-
```{code-cell} ipython3
171+
```{code-cell}
172172
class HestonCalibration:
173173
174174
def __init__(self, dt: float, initial_std = 0.5):
@@ -186,19 +186,19 @@ class HestonCalibration:
186186
return np.array(((1-self.kappa*self.dt, 0),(-0.5*self.dt, 0)))
187187
```
188188

189-
```{code-cell} ipython3
189+
```{code-cell}
190190
191191
```
192192

193-
```{code-cell} ipython3
193+
```{code-cell}
194194
c = HestonCalibration(dt)
195195
c.x0
196196
```
197197

198-
```{code-cell} ipython3
198+
```{code-cell}
199199
c.prediction(c.x0)
200200
```
201201

202-
```{code-cell} ipython3
202+
```{code-cell}
203203
c.state_jacobian()
204204
```

notebooks/applications/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.7
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -18,6 +18,6 @@ Real-world applications of the library
1818
```{tableofcontents}
1919
```
2020

21-
```{code-cell} ipython3
21+
```{code-cell}
2222
2323
```

notebooks/applications/sampling.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.7
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -15,21 +15,21 @@ kernelspec:
1515

1616
The library use the `Paths` class for managing monte carlo paths.
1717

18-
```{code-cell} ipython3
18+
```{code-cell}
1919
from quantflow.utils.paths import Paths
2020
2121
nv = Paths.normal_draws(paths=1000, time_horizon=1, time_steps=1000)
2222
```
2323

24-
```{code-cell} ipython3
24+
```{code-cell}
2525
nv.var().mean()
2626
```
2727

28-
```{code-cell} ipython3
28+
```{code-cell}
2929
nv = Paths.normal_draws(paths=1000, time_horizon=1, time_steps=1000, antithetic_variates=False)
3030
nv.var().mean()
3131
```
3232

33-
```{code-cell} ipython3
33+
```{code-cell}
3434
3535
```

notebooks/data/fmp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.16.1
8+
jupytext_version: 1.16.6
99
kernelspec:
1010
display_name: Python 3 (ipykernel)
1111
language: python
@@ -16,45 +16,45 @@ kernelspec:
1616

1717
The library provides a python client for the [Financial Modelling Prep API](https://site.financialmodelingprep.com/developer/docs). To use the client one needs to provide the API key aither directly to the client or via the `FMP_API_KEY` environment variable. The API offers 1 minute, 5 minutes, 15 minutes, 30 minutes, 1 hour and daily historical prices.
1818

19-
```{code-cell} ipython3
19+
```{code-cell}
2020
from quantflow.data.fmp import FMP
2121
cli = FMP()
2222
cli.url
2323
```
2424

25-
```{code-cell} ipython3
25+
```{code-cell}
2626
stock = "KNOS.L"
2727
```
2828

2929
## Company Profile
3030

31-
```{code-cell} ipython3
31+
```{code-cell}
3232
d = await cli.profile(stock)
3333
d
3434
```
3535

36-
```{code-cell} ipython3
36+
```{code-cell}
3737
c = await cli.peers(stock)
3838
c
3939
```
4040

4141
## Executive trading
4242

43-
```{code-cell} ipython3
43+
```{code-cell}
4444
stock = "KNOS.L"
4545
```
4646

47-
```{code-cell} ipython3
47+
```{code-cell}
4848
await cli.executives(stock)
4949
```
5050

51-
```{code-cell} ipython3
51+
```{code-cell}
5252
await cli.insider_trading(stock)
5353
```
5454

5555
## News
5656

57-
```{code-cell} ipython3
57+
```{code-cell}
5858
c = await cli.news(stock)
5959
c
6060
```

notebooks/data/timeseries.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.16.1
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -13,27 +13,27 @@ kernelspec:
1313

1414
## Timeseries
1515

16-
```{code-cell} ipython3
16+
```{code-cell}
1717
from quantflow.data.fmp import FMP
1818
from quantflow.utils.plot import candlestick_plot
1919
cli = FMP()
2020
```
2121

22-
```{code-cell} ipython3
22+
```{code-cell}
2323
prices = await cli.prices("ethusd", frequency="")
2424
```
2525

26-
```{code-cell} ipython3
26+
```{code-cell}
2727
candlestick_plot(prices).update_layout(height=500)
2828
```
2929

30-
```{code-cell} ipython3
30+
```{code-cell}
3131
from quantflow.utils.df import DFutils
3232
3333
df = DFutils(prices).with_rogers_satchel().with_parkinson()
3434
df
3535
```
3636

37-
```{code-cell} ipython3
37+
```{code-cell}
3838
3939
```

notebooks/examples/gaussian_sampling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.7
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -15,7 +15,7 @@ kernelspec:
1515

1616
Here we sample the gaussian OU process for different mean reversion speed and number of paths.
1717

18-
```{code-cell} ipython3
18+
```{code-cell}
1919
from quantflow.sp.ou import Vasicek
2020
from quantflow.utils import plot
2121
import ipywidgets as widgets
@@ -51,6 +51,6 @@ fig = go.FigureWidget(data=[simulation, analytical])
5151
widgets.VBox([kappa, samples, fig])
5252
```
5353

54-
```{code-cell} ipython3
54+
```{code-cell}
5555
5656
```

notebooks/examples/heston_vol_surface.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.7
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -13,7 +13,7 @@ kernelspec:
1313

1414
# Heston Volatility Surface
1515

16-
```{code-cell} ipython3
16+
```{code-cell}
1717
from quantflow.sp.heston import HestonJ
1818
from quantflow.options.pricer import OptionPricer
1919
@@ -29,13 +29,13 @@ pricer = OptionPricer(model=HestonJ.create(
2929
pricer
3030
```
3131

32-
```{code-cell} ipython3
32+
```{code-cell}
3333
pricer.plot3d(max_moneyness_ttm=1.5, support=31).update_layout(
3434
height=800,
3535
title="Heston volatility surface",
3636
)
3737
```
3838

39-
```{code-cell} ipython3
39+
```{code-cell}
4040
4141
```

notebooks/examples/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.7
7+
jupytext_version: 1.16.6
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python

0 commit comments

Comments
 (0)