Skip to main content

Python and Cython scripts of machine learning, econometrics and statistical features for financial analysis

Project description

Fynance logo

Fynance

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


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.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, …), 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


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.0.0.tar.gz (878.8 kB view details)

Uploaded Source

Built Distributions

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

fynance-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fynance-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fynance-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: fynance-2.0.0.tar.gz
  • Upload date:
  • Size: 878.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.0.0.tar.gz
Algorithm Hash digest
SHA256 6cb0e2a42c8cb806ef7008deced9ee04859ffd793247673de4a822fe56680ad4
MD5 0f8b12e9cfce338eb1d4f6f85d9cdc52
BLAKE2b-256 493588ca35632d8fbb8d6838ecea9f164b12aaf9fc5a268e0464bcf880b2003c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.0.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.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fynance-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0163a86549e601ce9571e3128c9e2fadfa322cd32bd98cc0aa2e8e638e1c209
MD5 6259144008af5e6c1ecae7620536db58
BLAKE2b-256 ce3583710bf39feb1e89a4ccc142a310dacef470b7b9fb72cad27e1ce8cf7418

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.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.

File details

Details for the file fynance-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fynance-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd0d16f75ec730e5dff7f42ab069fe6e60ffec6d7d20eb84de59715f1fd4b6e2
MD5 8d30dc41e5de5e29a5c7a343c94150dc
BLAKE2b-256 9a98bfe1e4f1ece285152fbf2b47e4d365eacdeb52e1d5ea63b4d1abd6e243b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.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.

File details

Details for the file fynance-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fynance-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 740c96f4f40408ec56bf8a63dc52f8c7a98b24a92e9b33baf920f3469f8d21ca
MD5 0e9279eedfc08fc2ecb94e9d34c8b626
BLAKE2b-256 56a3bc7b4b73cc7dceda99ca77b7d6090f7a48014e92216183c20e7614f89848

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.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