Skip to content
Open

docs #33

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ htmlcov
.eggs
*.egg-info
__pycache__
__marimo__
build
dist
.venv
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"python.defaultInterpreterPath": ".venv/bin/python"
"python.defaultInterpreterPath": ".venv/bin/python",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ lint-check: ## Lint check only
install-dev: ## Install development dependencies
@./dev/install

.PHONY: marimo
marimo: ## Run marimo for editing notebooks
@./dev/marimo edit

.PHONY: marimo-export
marimo-export: ## Run marimo for editing notebooks
@./dev/marimo export html-wasm -f --show-code notebooks/supersmoother.py -o docs/applications/supersmoother

.PHONY: notebook
notebook: ## Run Jupyter notebook server
Expand All @@ -44,9 +51,17 @@ nbsync: ## Sync python myst notebooks to .ipynb files - needed for vs noteboo
sphinx-config: ## Build sphinx config
poetry run jupyter-book config sphinx notebooks

.PHONY: docs
docs: ## build documentation
@cp docs/index.md readme.md
@poetry run mkdocs build

.PHONY: docs-serve
docs-serve: ## serve documentation
@poetry run mkdocs serve --livereload --watch quantflow --watch docs

.PHONY: sphinx
sphinx:
sphinx: ## Build sphinx docs
poetry run sphinx-build notebooks path/to/book/_build/html -b html


Expand Down
21 changes: 21 additions & 0 deletions app/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Annotated, Callable, Coroutine
from fastapi.responses import HTMLResponse, RedirectResponse
import marimo
from fastapi import FastAPI, Form, Request, Response


def crate_app() -> FastAPI:
# Create a marimo asgi app
server = (
marimo.create_asgi_app()
.with_app(path="/supersmoother", root="./app/supersmoother.py")
)
# Create a FastAPI app
app = FastAPI()
app.mount("/", server.build())
return app

# Run the server
if __name__ == "__main__":
import uvicorn
uvicorn.run(crate_app(), host="localhost", port=8001)
110 changes: 110 additions & 0 deletions app/supersmoother.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import marimo

__generated_with = "0.19.7"
app = marimo.App(width="medium")


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
# Supermsoother & EWMA
""")
return


@app.cell
def _():
import marimo as mo

app = mo.App(
requirements=["quantflow"]
)
return (mo,)


@app.cell
def _():
from quantflow.data.fmp import FMP
fmp = FMP()
return (fmp,)


@app.cell
async def _(fmp):
from datetime import date
data = await fmp.prices("BTCUSD", from_date=date(2024,1,1))
data
return (data,)


@app.cell
def _():
import altair as alt
import pandas as pd
return (alt,)


@app.cell
def _(mo):
period = mo.ui.slider(start=2, stop=100, step=1, value=10, label="Period:")
period
return (period,)


@app.cell
def _(data, period):
from quantflow.ta.supersmoother import SuperSmoother
from quantflow.ta.ewma import EWMA
smoother = SuperSmoother(period=period.value)
ewma = EWMA(period=period.value)
sm = data[["date", "close"]].copy()
sm["supersmoother"] = data["close"].apply(smoother.update)
sm["ewma"] = data["close"].apply(ewma.update)
return (sm,)


@app.cell(hide_code=True)
def _(alt, sm):
# Melt the dataframe to a long format suitable for Altair
sm_long = sm.melt(
id_vars=['date'],
value_vars=['close', 'supersmoother', "ewma"],
var_name='Signal',
value_name='Price'
)

# Create the chart with both SuperSmoothers
line_chart_combined = alt.Chart(sm_long).mark_line().encode(
x=alt.X('date:T', title='Date'),
y=alt.Y('Price:Q', title='Price (USD)', scale=alt.Scale(zero=False)),
color=alt.Color('Signal:N', title='Signal',
scale=alt.Scale(
domain=['close', 'supersmoother', 'ewma'],
range=['#4c78a8', '#f58518', '#e45756']) # Vega-Lite default palette
),
tooltip=[
alt.Tooltip('date:T', title='Date'),
alt.Tooltip('Signal:N', title='Signal'),
alt.Tooltip('Price:Q', title='Price', format='$,.2f')
]
).properties(
title='BTCUSD Close Price vs. SuperSmoothers'
).interactive()

line_chart_combined
return


@app.cell
def _(sm):
sm
return


@app.cell
def _():
return


if __name__ == "__main__":
app.run()
2 changes: 1 addition & 1 deletion dev/install
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

pip install -U pip poetry
poetry install --all-extras --with book
poetry install --all-extras --with book --with docs
3 changes: 3 additions & 0 deletions dev/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ set -e
ISORT_ARGS="-c"
BLACK_ARG="--check"
RUFF_ARG=""
TAPLO_ARG="format --check"

if [ "$1" = "fix" ] ; then
ISORT_ARGS=""
BLACK_ARG=""
RUFF_ARG="--fix"
TAPLO_ARG="format"
fi

taplo ${TAPLO_ARG}
echo isort
isort quantflow quantflow_tests ${ISORT_ARGS}
echo black
Expand Down
6 changes: 6 additions & 0 deletions dev/marimo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e

export PYTHONPATH=${PWD}:${PYTHONPATH}

poetry run marimo "$@"
11 changes: 11 additions & 0 deletions docs/api/data/deribit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Deribit

Fetch market and static data from [Deribit API](https://docs.deribit.com/).

You can import the module via

```python
from quantflow.data.deribit import Deribit
```

::: quantflow.data.deribit.Deribit
9 changes: 9 additions & 0 deletions docs/api/data/fed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Federal Reserve

You can import the module via

```python
from quantflow.data.fed import FederalReserve
```

::: quantflow.data.fed.FederalReserve
13 changes: 13 additions & 0 deletions docs/api/data/fmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# FMP


Reference information for the Financial Modeling Prep (FMP) data fetching module.
You can find more information about FMP at [FMP developer docs](https://site.financialmodelingprep.com/developer/docs/stable).

You can import the module via

```python
from quantflow.data.fmp import FMP
```

::: quantflow.data.fmp.FMP
9 changes: 9 additions & 0 deletions docs/api/data/fred.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fred

You can import the module via

```python
from quantflow.data.fred import Fred
```

::: quantflow.data.fred.Fred
13 changes: 1 addition & 12 deletions notebooks/api/data/index.rst → docs/api/data/index.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
==============
Data fetching
==============
# Data fetching

.. currentmodule:: quantflow.data

The :mod:`quantflow.data` module provides classes and functions for fetching data from various sources.
To use the module the package must be installed with the optional `data` extra.
```
pip install quantflow[data]
```

.. toctree::
:maxdepth: 1

fmp
fed
fred
deribit
3 changes: 3 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# API

Here's the reference or code API, the classes, functions, parameters, attributes, and all the quantflow parts you can use in your applications.
19 changes: 19 additions & 0 deletions docs/api/options/black.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Black Pricing

Here we define the log strike `k` as
$$
k = \log{\frac{K}{F}}
$$

where \(K\) is the strike price and \(F\) is the forward price of the underlying asset.


::: quantflow.options.bs.black_price

::: quantflow.options.bs.black_call

::: quantflow.options.bs.black_delta

::: quantflow.options.bs.black_vega

::: quantflow.options.bs.implied_black_volatility
5 changes: 5 additions & 0 deletions docs/api/options/calibration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Vol Model Calibration

::: quantflow.options.calibration.VolModelCalibration

::: quantflow.options.calibration.HestonCalibration
5 changes: 5 additions & 0 deletions docs/api/options/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Option Pricing

The `options` module provides classes and functions for pricing and analyzing options.
The main class is the [VolSurface][quantflow.options.surface.VolSurface] class which is used to represent a volatility surface for a given asset.
A volatility surface is usually created via a [VolSurfaceLoader][quantflow.options.surface.VolSurfaceLoader] object.
9 changes: 9 additions & 0 deletions docs/api/options/pricer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Option Pricer

The option pricer module provides classes for pricing options using
different stochastic volatility models.


::: quantflow.options.pricer.OptionPricer

::: quantflow.options.pricer.MaturityPricer
12 changes: 12 additions & 0 deletions docs/api/options/vol_surface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Vol Surface


::: quantflow.options.surface.VolSurface

::: quantflow.options.surface.VolCrossSection

::: quantflow.options.surface.GenericVolSurfaceLoader

::: quantflow.options.surface.VolSurfaceLoader

::: quantflow.options.surface.OptionSelection
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions notebooks/api/sp/index.rst → docs/api/sp/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
===================
Stochastic Process
===================
# Stochastic Process

This page gives an overview of all Stochastic Processes available in the library.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions docs/api/ta/ewma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# EWMA


::: quantflow.ta.EWMA
1 change: 1 addition & 0 deletions docs/api/ta/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Timeseries Analysis
3 changes: 3 additions & 0 deletions docs/api/ta/kalman.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kalman Filter

::: quantflow.ta.KalmanFilter
3 changes: 3 additions & 0 deletions docs/api/ta/ohlc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OHLC

::: quantflow.ta.ohlc.OHLC
3 changes: 3 additions & 0 deletions docs/api/ta/paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Paths

::: quantflow.ta.paths.Paths
14 changes: 14 additions & 0 deletions docs/api/ta/supersmoother.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Super Smoother

SuperSmoother algorithm for time series smoothing.

Implementation based on John Ehlers' SuperSmoother filter,
which is a [two-pole Butterworth filter](https://en.wikipedia.org/wiki/Butterworth_filter) that provides excellent smoothing
while minimizing lag. The filter uses an adaptive approach with cross-validation
to determine the optimal smoothing parameters.

Reference:
Ehlers, J. (2013). "Cycle Analytics for Traders"


::: quantflow.ta.SuperSmoother
5 changes: 5 additions & 0 deletions docs/api/utils/bins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bins

::: quantflow.utils.bins.pdf

::: quantflow.utils.bins.event_density
9 changes: 9 additions & 0 deletions docs/api/utils/distributions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Distributions

::: quantflow.utils.distributions.Distribution1D

::: quantflow.utils.distributions.Exponential

::: quantflow.utils.distributions.DoubleExponential

::: quantflow.utils.distributions.Normal
1 change: 1 addition & 0 deletions docs/api/utils/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Utils
Loading
Loading