Skip to content

Commit 7939fec

Browse files
committed
Add tasks and citation
1 parent 30535bb commit 7939fec

File tree

5 files changed

+109
-67
lines changed

5 files changed

+109
-67
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#
22
# IDEs
33
.idea
4-
.vscode
54
*.sublime-workspace
65

76
#

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
5+
{
6+
"name": "PyTest",
7+
"type": "debugpy",
8+
"request": "launch",
9+
"cwd": "${workspaceFolder}",
10+
"console": "integratedTerminal",
11+
"module": "pytest",
12+
"env": {},
13+
"justMyCode": false,
14+
"args": [
15+
"-x",
16+
"-vvv",
17+
"quantflow_tests/test_utils.py",
18+
]
19+
},
20+
]
21+
}

.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"tasks": [
3+
{
4+
"label": "JupyText Sync",
5+
"type": "shell",
6+
"command": "${command:python.interpreterPath} -m jupytext ${file} -s",
7+
"group": {
8+
"kind": "build",
9+
"isDefault": true
10+
},
11+
"presentation": {
12+
"reveal": "never",
13+
}
14+
}
15+
]
16+
}

CITATION.cff

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This CITATION.cff file was generated with cffinit.
2+
# Visit https://bit.ly/cffinit to generate yours today!
3+
4+
cff-version: 1.2.0
5+
title: quantflow
6+
message: >-
7+
If you use this software, please cite it using the
8+
metadata from this file.
9+
type: software
10+
authors:
11+
- given-names: Luca
12+
family-names: Sbardella
13+
email: luca@quantmind.com
14+
- name: quantmind
15+
repository-code: 'https://github.com/quantmind/quantflow'
16+
url: 'https://quantmind.github.io/quantflow/'
17+
abstract: Quantitative finance and derivative pricing
18+
keywords:
19+
- finance
20+
- option-pricing
21+
- quantitative-finance
22+
- timeseries
23+
license: BSD-3-Clause

notebooks/applications/hurst.md

Lines changed: 49 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,65 @@ jupytext:
55
format_name: myst
66
format_version: 0.13
77
jupytext_version: 1.16.6
8+
kernelspec:
9+
display_name: Python 3 (ipykernel)
10+
language: python
11+
name: python3
812
---
913

10-
# %% [markdown]
11-
# # Hurst Exponent
12-
#
13-
# The [Hurst exponent](https://en.wikipedia.org/wiki/Hurst_exponent) is used as a measure of long-term memory of time series. It relates to the autocorrelations of the time series, and the rate at which these decrease as the lag between pairs of values increases.
14-
#
15-
# It is a statistics which can be used to test if a time-series is mean reverting or it is trending.
16-
17-
# %% [markdown]
18-
# ## Study with the Weiner Process
19-
#
20-
# We want to construct a mechanism to estimate the Hurst exponent via OHLC data because it is widely available from data provider and easily constructed as an online signal during trading.
21-
#
22-
# In order to evaluate results against known solutions, we consider the Weiner process as generator of timeseries.
23-
#
24-
# The Weiner process is a continuous-time stochastic process named in honor of Norbert Wiener. It is often also called Brownian motion due to its historical connection with the physical model of Brownian motion of particles in water, named after the botanist Robert Brown.
25-
26-
# %%
14+
# Hurst Exponent
15+
16+
The [Hurst exponent](https://en.wikipedia.org/wiki/Hurst_exponent) is used as a measure of long-term memory of time series. It relates to the autocorrelations of the time series, and the rate at which these decrease as the lag between pairs of values increases.
17+
18+
It is a statistics which can be used to test if a time-series is mean reverting or it is trending.
19+
Trending time-series have a Hurst exponent H > 0.5, while mean reverting time-series have H < 0.5. Understanding in which regime a time-series is can be useful for trading strategies.
20+
21+
* [Hurst Exponent for Algorithmic Trading](https://robotwealth.com/demystifying-the-hurst-exponent-part-1/)
22+
23+
## Study with the Weiner Process
24+
25+
We want to construct a mechanism to estimate the Hurst exponent via OHLC data because it is widely available from data provider and easily constructed as an online signal during trading.
26+
27+
In order to evaluate results against known solutions, we consider the Weiner process as generator of timeseries.
28+
29+
The Weiner process is a continuous-time stochastic process named in honor of Norbert Wiener. It is often also called Brownian motion due to its historical connection with the physical model of Brownian motion of particles in water, named after the botanist Robert Brown.
30+
31+
```{code-cell} ipython3
2732
from quantflow.sp.weiner import WeinerProcess
2833
from quantflow.utils.dates import start_of_day
2934
p = WeinerProcess(sigma=0.5)
3035
paths = p.sample(1, 1, 24*60*60)
3136
paths.plot()
37+
```
3238

33-
# %%
39+
```{code-cell} ipython3
3440
df = paths.as_datetime_df(start=start_of_day()).reset_index()
3541
df
42+
```
43+
44+
### Realized Variance
45+
46+
At this point we estimate the standard deviation using the **realized variance** along the path (we use the **scaled** flag so that the standard deviation is scaled by the square-root of time step, in this way it removes the dependency on the time step size).
47+
The value should be close to the **sigma** of the WeinerProcess defined above.
48+
49+
```{code-cell} ipython3
50+
float(paths.paths_std(scaled=True)[0])
51+
```
52+
53+
### Range-base Variance estimators
3654

37-
# %% [markdown]
38-
# ### Realized Variance
39-
#
40-
# At this point we estimate the standard deviation using the **realized variance** along the path (we use the **scaled** flag so that the standard deviation is scaled by the square-root of time step, in this way it removes the dependency on the time step size).
41-
# The value should be close to the **sigma** of the WeinerProcess defined above.
42-
43-
# %%
44-
float(paths.path_std(scaled=True)[0])
45-
46-
# %% [markdown]
47-
# ### Range-base Variance estimators
48-
#
49-
# We now turn our attention to range-based volatility estimators. These estimators depends on OHLC timeseries, which are widely available from data providers such as [FMP](https://site.financialmodelingprep.com/).
50-
# To analyze range-based variance estimators, we use he **quantflow.ta.OHLC** tool which allows to down-sample a timeserie to OHLC series and estimate variance with three different estimators
51-
#
52-
# * **Parkinson** (1980)
53-
# * **Garman & Klass** (1980)
54-
# * **Rogers & Satchell** (1991)
55-
#
56-
# See {cite:p}`molnar` for a detailed overview of the properties of range-based estimators.
57-
#
58-
# For this we build an OHLC estimator as template and use it to create OHLC estimators for different periods.
59-
60-
# %%
55+
We now turn our attention to range-based volatility estimators. These estimators depends on OHLC timeseries, which are widely available from data providers such as [FMP](https://site.financialmodelingprep.com/).
56+
To analyze range-based variance estimators, we use he **quantflow.ta.OHLC** tool which allows to down-sample a timeserie to OHLC series and estimate variance with three different estimators
57+
58+
* **Parkinson** (1980)
59+
* **Garman & Klass** (1980)
60+
* **Rogers & Satchell** (1991)
61+
62+
See {cite:p}`molnar` for a detailed overview of the properties of range-based estimators.
63+
64+
For this we build an OHLC estimator as template and use it to create OHLC estimators for different periods.
65+
66+
```{code-cell} ipython3
6167
import pandas as pd
6268
from quantflow.ta.ohlc import OHLC
6369
ohlc = OHLC(serie="0", period="10m", rogers_satchell_variance=True, parkinson_variance=True, garman_klass_variance=True)
@@ -69,27 +75,4 @@ for period in ("2m", "5m", "10m", "30m", "1h", "4h"):
6975
results.append(dict(period=period, pk=result["0_pk"].item(), gk=result["0_gk"].item(), rs=result["0_rs"].item()))
7076
vdf = pd.DataFrame(results)
7177
vdf
72-
73-
# %% [markdown]
74-
# # Links
75-
#
76-
# * [Wikipedia](https://en.wikipedia.org/wiki/Hurst_exponent)
77-
# * [Hurst Exponent for Algorithmic Trading
78-
# ](https://robotwealth.com/demystifying-the-hurst-exponent-part-1/)
79-
80-
# %%
81-
import pandas as pd
82-
v = pd.to_timedelta(0.02, unit="d")
83-
v
84-
85-
# %%
86-
v.to_pytimedelta()
87-
88-
# %%
89-
from quantflow.utils.dates import utcnow
90-
pd.date_range(start=utcnow(), periods=10, freq="0.5S")
91-
92-
# %%
93-
7*7+3*3
94-
95-
# %%
78+
```

0 commit comments

Comments
 (0)