https://github.com/arthurbernard/fynance
Python and Cython scripts of machine learning, econometrics and statistical tools designed for finance.
https://github.com/arthurbernard/fynance
backtest deep-learning finance machine-learning neural-network python
Last synced: 3 days ago
JSON representation
Python and Cython scripts of machine learning, econometrics and statistical tools designed for finance.
- Host: GitHub
- URL: https://github.com/arthurbernard/fynance
- Owner: ArthurBernard
- License: mit
- Created: 2018-11-09T20:05:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2026-06-13T18:23:56.000Z (6 days ago)
- Last Synced: 2026-06-13T20:16:39.742Z (6 days ago)
- Topics: backtest, deep-learning, finance, machine-learning, neural-network, python
- Language: Python
- Homepage:
- Size: 5.23 MB
- Stars: 24
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README

# **Fynance**
[](https://pypi.org/project/fynance/)
[](https://pypi.org/project/fynance/)
[](https://pypi.org/project/fynance/)
[](https://github.com/ArthurBernard/Fynance/actions/workflows/ci.yml)
[](https://github.com/ArthurBernard/Fynance/blob/master/LICENSE.txt)
[](https://fynance.readthedocs.io/en/latest/)
[](https://codecov.io/gh/ArthurBernard/Fynance)
[](https://github.com/ArthurBernard/Fynance)
[](https://pepy.tech/project/fynance)
___
Pure-Python package (Numba-accelerated kernels) providing **machine learning**,
**econometric** and **statistical** tools for **financial analysis** and
**backtesting of trading strategies**.
## Installation
```bash
pip install fynance
```
From source:
```bash
git clone https://github.com/ArthurBernard/Fynance.git
cd Fynance
pip install -e ".[dev]"
```
The build is pure-Python — there is no compile step (numerical kernels are
Numba `@njit`, JIT-compiled on first call).
## Architecture
A complete, layered ML/DL backtesting tool — **data → features → signal →
portfolio → backtest → metrics** — composed through `typing.Protocol` seams.
numpy is the lingua franca; PyTorch is confined to `fynance.models`. Each piece
is usable standalone; `fynance.strategy.Strategy` is an *optional* orchestrator.
> **2.0 is a breaking release.** See [`doc/MIGRATION-2.0.md`](doc/MIGRATION-2.0.md)
> for the import-path map (e.g. `fynance.algorithms` → `fynance.portfolio`,
> performance metrics → `fynance.metrics`).
## Subpackages
**Core** `fynance.core` — `PriceSeries` value object (thin, numpy-backed) and the
pipeline protocols (`DataSource`, `FeatureTransform`, `SignalModel`, `Allocator`,
`CostModel`, `Metric`).
**Data** `fynance.data` — file adapters (`load` for CSV/Parquet → `PriceSeries`),
alignment/resampling, and no-lookahead temporal splits (`train_test_split`,
`walk_forward`).
**Features** `fynance.features` — technical indicators (Bollinger, RSI, MACD, ROC,
realized volatility, rolling skew/kurtosis/autocorr, …), momentums (SMA, EMA, WMA),
scaling (incl. rolling rank), statistics, feature engineering (multi-resolution,
Granger causality) and market-regime detection.
**Metrics** `fynance.metrics` — performance/evaluation metrics (Sharpe, Sortino,
Calmar, drawdown, …) and a one-call `summary`.
**Signal** `fynance.signal` — prediction → position mappers (`sign`, `threshold`,
`rank`, vol-targeting) and a model+mapper pipeline.
**Portfolio** `fynance.portfolio` — allocation (ERC, HRP, IVP, MDP, MVP) and
sizing (fractional Kelly, volatility targeting, transaction costs).
**Backtest** `fynance.backtest` — vectorized engine (`backtest`: positions +
returns/prices + cost → `BacktestResult`) and cost models.
**Plot** `fynance.plot` — composable matplotlib figures and a one-call
`tearsheet` report.
**Models** `fynance.models` — econometric models (MA, ARMA, ARMA-GARCH) and
PyTorch nets (MLP, RNN, GRU, LSTM, MultiHeadAttention, TCN, Transformer), a
direction+magnitude stacking ensemble, differentiable losses (Sharpe, Sortino,
Calmar, Omega, directional, hybrid), and robust-training utilities.
**Strategy** `fynance.strategy` — optional orchestrator composing the maillons
end-to-end, with single-run and walk-forward evaluation.
**Research** `fynance.research` — data-agnostic experiment harness: `Experiment`
(serializable run record), `run_experiment` (seeded, cost-aware, walk-forward),
`write_report` (portable markdown + tearsheet PNG + notebook) and synthetic data
generators (`gbm`, `regime_switching`). Results are written only to a
caller-provided `output_dir` — fynance never stores them itself.
## Quick start
```python
import numpy as np
import fynance as fy
# 1. Data — load a CSV/Parquet file, or build a PriceSeries directly
prices = fy.PriceSeries(100 * np.cumprod(1 + np.random.randn(750) * 0.01))
# 2. Compose a strategy: momentum feature -> position -> backtest with costs
strat = fy.Strategy(
features=lambda p: np.sign(np.diff(p, prepend=p[0])),
signal=lambda x: x,
cost=fy.ProportionalCost(fee=0.0005),
)
result = strat.run(prices)
# 3. Evaluate and report
print(result.summary()) # Sharpe, Sortino, Calmar, max drawdown, ...
fig = fy.tearsheet(result) # one-call performance report
```
See [`Notebooks/quickstart_v2.ipynb`](Notebooks/quickstart_v2.ipynb) for the full
runnable tour (data, features, walk-forward, reporting). An optional Streamlit
playground ships under [`apps/playground/`](apps/playground/)
(`pip install -e ".[ui]" && streamlit run apps/playground/app.py`).
## Links
- PyPI: https://pypi.org/project/fynance/
- Documentation: https://fynance.readthedocs.io/en/latest/
- Source: https://github.com/ArthurBernard/Fynance
- Changelog: https://github.com/ArthurBernard/Fynance/blob/master/CHANGELOG.md