Python and Cython scripts of machine learning, econometrics and statistical features for financial analysis
Project description
Fynance
Python and Cython package providing machine learning, econometric and statistical tools for financial analysis and backtesting of trading strategies.
Installation
pip install fynance
From source:
git clone https://github.com/ArthurBernard/Fynance.git
cd Fynance
pip install -e ".[dev]"
python setup.py build_ext --inplace
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.mdfor 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.
Quick start
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 for the full
runnable tour (data, features, walk-forward, reporting). An optional Streamlit
playground ships under apps/playground/
(pip install -e ".[ui]" && streamlit run apps/playground/app.py).
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fynance-2.1.1.tar.gz.
File metadata
- Download URL: fynance-2.1.1.tar.gz
- Upload date:
- Size: 152.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fad0f991c0ba7045a2ba92557a624aeb16edf97d86fdc478330ed0c910a73fa3
|
|
| MD5 |
f5f20716da70b96de0fdfcbe8627f026
|
|
| BLAKE2b-256 |
d9b154608e9132dcc8bb067594e43ef94cc602cacc0b6ef437c99ca28d097174
|
Provenance
The following attestation bundles were made for fynance-2.1.1.tar.gz:
Publisher:
release.yml on ArthurBernard/Fynance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fynance-2.1.1.tar.gz -
Subject digest:
fad0f991c0ba7045a2ba92557a624aeb16edf97d86fdc478330ed0c910a73fa3 - Sigstore transparency entry: 1828941263
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@75c5e7106da3ede7b7d01a1e8c3f52163a136968 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@75c5e7106da3ede7b7d01a1e8c3f52163a136968 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fynance-2.1.1-py3-none-any.whl.
File metadata
- Download URL: fynance-2.1.1-py3-none-any.whl
- Upload date:
- Size: 208.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b84b94167349ca1fbbd199402f90c2fe55e1044e016a3c378d1a7b4f3440893
|
|
| MD5 |
d047caa52010b8b09f1aa5076fc35a52
|
|
| BLAKE2b-256 |
c19b5e87b0c64c797f657dcdf01887d6a97d47bb72bc1426c06193cb1629b926
|
Provenance
The following attestation bundles were made for fynance-2.1.1-py3-none-any.whl:
Publisher:
release.yml on ArthurBernard/Fynance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fynance-2.1.1-py3-none-any.whl -
Subject digest:
3b84b94167349ca1fbbd199402f90c2fe55e1044e016a3c378d1a7b4f3440893 - Sigstore transparency entry: 1828941307
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@75c5e7106da3ede7b7d01a1e8c3f52163a136968 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@75c5e7106da3ede7b7d01a1e8c3f52163a136968 -
Trigger Event:
push
-
Statement type: