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

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


Download files

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

Source Distribution

fynance-1.6.0.tar.gz (854.7 kB view details)

Uploaded Source

Built Distributions

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

fynance-1.6.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-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fynance-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Hashes for fynance-1.6.0.tar.gz
Algorithm Hash digest
SHA256 1c229b417c67677e1aa223f1746a53ee3d3d766cbbb12e8bb9eadffe878030e1
MD5 8dd57a799ba2f43d96094a3eaaa0ee5b
BLAKE2b-256 1cbfe6c17dbe1ffa7eb76a535dbf00cb42ea14880fdcc0e48ef8e118b59a4ce6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fynance-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d09fda6bd665ee5830d1c67b2d095cdb5a3b19be74d02c1c3e922b2eb85377fd
MD5 c77eb9e6859e61962f8c87f82c580c19
BLAKE2b-256 c4a08297e623787c71d23d6c676cfd6f2447238bd31bb558e341f4863aead9ff

See more details on using hashes here.

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

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-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fynance-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e59d3d3f9b07019b9dd5c217f52a8442b34c4740a45e70fdc31cf7392343733
MD5 886fc1d0632c1402203a5cbf9a701aaf
BLAKE2b-256 18f7cc0a09ded584cdb9e8c96acd90c4eb4e022ea3df3a399c3c13a6a158084c

See more details on using hashes here.

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

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-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fynance-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f768748dfe0270400048e2cd38f266081323c3916bafab06c0978ac52570c74
MD5 15db5366c16721be20767e14efe93a3d
BLAKE2b-256 aff33f1ca2bb64fd028eca82296475f47ea9cf4ed3de12b4573c42eb52ffb211

See more details on using hashes here.

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

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