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
Subpackages
Algorithms fynance.algorithms
Portfolio allocation methods (ERC, HRP, IVP, MDP, MVP), walk-forward wrappers, and position sizing (fractional Kelly, volatility targeting, transaction costs).
Backtest fynance.backtest
Profit-and-loss plotting and performance measurement.
Estimator fynance.estimator
Cython ARMA / GARCH parameter estimation.
Features fynance.features
Kalman filter, technical indicators (Bollinger, RSI, MACD, ROC, realized volatility, rolling skew/kurtosis/autocorr, …),
statistical momentums (SMA, EMA, WMA, …), metrics (Sharpe, Sortino, Calmar, drawdown, tail ratio, …), scaling
(incl. rolling rank), feature-engineering tools (multi-resolution, Granger causality), and market-regime detection.
Models fynance.models
Econometric models (MA, ARMA, ARMA-GARCH), neural networks with PyTorch (MLP, RNN, GRU, LSTM,
MultiHeadAttention, TCN, Transformer), a direction+magnitude stacking ensemble,
differentiable loss functions (Sharpe, Sortino, Calmar, Omega, directional, hybrid),
robust-training utilities (purged CV, early stopping, sample weighting), and walk-forward rolling evaluation.
Quick start
import numpy as np
import fynance as fy
# Sharpe ratio
returns = np.random.randn(252) * 0.01
print(fy.sharpe(returns))
# ERC portfolio allocation
cov = np.cov(np.random.randn(5, 252))
weights = fy.ERC(cov)
print(weights)
Rolling walk-forward training with a neural network:
import torch
import torch.nn as nn
from fynance.models.rolling import RollMultiLayerPerceptron
model = RollMultiLayerPerceptron(X, y, layers=[64, 32])
model.set_optimizer(nn.MSELoss, torch.optim.Adam, lr=1e-3)
model(train_period=252, test_period=21, roll_period=21) # walk-forward windows
for eval_set, test_set in model: # each step trains on the past, tests the next
model._training()
See Notebooks/pytorch_examples.ipynb for a
runnable tour (metrics, allocation, MLP/TCN/Transformer with custom losses,
walk-forward CV).
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 Distributions
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-1.6.0.tar.gz.
File metadata
- Download URL: fynance-1.6.0.tar.gz
- Upload date:
- Size: 854.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c229b417c67677e1aa223f1746a53ee3d3d766cbbb12e8bb9eadffe878030e1
|
|
| MD5 |
8dd57a799ba2f43d96094a3eaaa0ee5b
|
|
| BLAKE2b-256 |
1cbfe6c17dbe1ffa7eb76a535dbf00cb42ea14880fdcc0e48ef8e118b59a4ce6
|
Provenance
The following attestation bundles were made for fynance-1.6.0.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-1.6.0.tar.gz -
Subject digest:
1c229b417c67677e1aa223f1746a53ee3d3d766cbbb12e8bb9eadffe878030e1 - Sigstore transparency entry: 1818859276
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fynance-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fynance-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d09fda6bd665ee5830d1c67b2d095cdb5a3b19be74d02c1c3e922b2eb85377fd
|
|
| MD5 |
c77eb9e6859e61962f8c87f82c580c19
|
|
| BLAKE2b-256 |
c4a08297e623787c71d23d6c676cfd6f2447238bd31bb558e341f4863aead9ff
|
Provenance
The following attestation bundles were made for fynance-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.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-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
d09fda6bd665ee5830d1c67b2d095cdb5a3b19be74d02c1c3e922b2eb85377fd - Sigstore transparency entry: 1818859454
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fynance-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fynance-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e59d3d3f9b07019b9dd5c217f52a8442b34c4740a45e70fdc31cf7392343733
|
|
| MD5 |
886fc1d0632c1402203a5cbf9a701aaf
|
|
| BLAKE2b-256 |
18f7cc0a09ded584cdb9e8c96acd90c4eb4e022ea3df3a399c3c13a6a158084c
|
Provenance
The following attestation bundles were made for fynance-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.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-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
5e59d3d3f9b07019b9dd5c217f52a8442b34c4740a45e70fdc31cf7392343733 - Sigstore transparency entry: 1818859358
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fynance-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fynance-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f768748dfe0270400048e2cd38f266081323c3916bafab06c0978ac52570c74
|
|
| MD5 |
15db5366c16721be20767e14efe93a3d
|
|
| BLAKE2b-256 |
aff33f1ca2bb64fd028eca82296475f47ea9cf4ed3de12b4573c42eb52ffb211
|
Provenance
The following attestation bundles were made for fynance-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.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-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
4f768748dfe0270400048e2cd38f266081323c3916bafab06c0978ac52570c74 - Sigstore transparency entry: 1818859521
- Sigstore integration time:
-
Permalink:
ArthurBernard/Fynance@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/ArthurBernard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e0e857ebbf8e9d9f7daea0d60d1f3bd83a41aa3 -
Trigger Event:
push
-
Statement type: