Skip to main content

Pure-Python (Numba-accelerated) machine learning, econometrics and statistical tools for financial analysis and backtesting

Project description

Fynance logo

Fynance

Python versions PyPI PyPI status CI License
Documentation Coverage Docstring coverage Downloads


Pure-Python package (Numba-accelerated kernels) 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]"

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 for the import-path map (e.g. fynance.algorithmsfynance.portfolio, performance metrics → fynance.metrics).

Subpackages

Core fynance.corePriceSeries 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, …), OHLCV indicators (ATR, ADX, Williams %R, OBV, VWAP), a causal GARCH(1,1) conditional-volatility feature, momentums (SMA, EMA, WMA) and adaptive windows, 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 (ProportionalCost and the non-linear MarketImpactCost).

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, RegimeMoE (regime-conditioned mixture-of-experts), 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fynance-2.10.0.tar.gz (226.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fynance-2.10.0-py3-none-any.whl (304.0 kB view details)

Uploaded Python 3

File details

Details for the file fynance-2.10.0.tar.gz.

File metadata

  • Download URL: fynance-2.10.0.tar.gz
  • Upload date:
  • Size: 226.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fynance-2.10.0.tar.gz
Algorithm Hash digest
SHA256 b33a51f5bc3c36bb8a8656546a572acb1f0645fdf474ed1adbb0f4292b7c31e6
MD5 87bde9e264d33de38da39ccd77792f2d
BLAKE2b-256 cb0612e7b1f2de78c1d212cede625998beb136a15572626e86142a02e16fce7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.10.0.tar.gz:

Publisher: release.yml on ArthurBernard/Fynance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fynance-2.10.0-py3-none-any.whl.

File metadata

  • Download URL: fynance-2.10.0-py3-none-any.whl
  • Upload date:
  • Size: 304.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fynance-2.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3907bf187052130982a6b8b297d14ea60743f12ba36552cf44e48d3944ff0f
MD5 48aaf771176d8a7071dde0635536120a
BLAKE2b-256 d0dffc54e5545cef087daf062d14d97a3869346d7601271eba70245cb7432b3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.10.0-py3-none-any.whl:

Publisher: release.yml on ArthurBernard/Fynance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page