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) and rolling walk-forward wrappers.

Backtest fynance.backtest
Profit-and-loss plotting and performance measurement.

Estimator fynance.estimator
Cython ARMA / GARCH parameter estimation.

Features fynance.features
Kalman filter, financial indicators (Bollinger, RSI, MACD, …), statistical momentums (SMA, EMA, WMA, …), metrics (Sharpe, Sortino, Calmar, drawdown, …), scaling, and rolling functions.

Models fynance.models
Econometric models (MA, ARMA, ARMA-GARCH), neural networks with PyTorch (MLP, RNN, GRU, LSTM, MultiHeadAttention), differentiable loss functions (SharpeLoss, SortinoLoss, DirectionalAccuracyLoss), 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.5.0.tar.gz (840.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-1.5.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.5.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.5.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.5.0.tar.gz.

File metadata

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

File hashes

Hashes for fynance-1.5.0.tar.gz
Algorithm Hash digest
SHA256 904d5b559504fa38d1488dbb8904f8f28e593fc40b4c8e1bf4ac222900163398
MD5 3cedddb5f8feeb9bc72a4540f92b20c6
BLAKE2b-256 af941848189c102933b92bb7fad5e6131de9236f326d86c040a5a735ff704aa0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fynance-1.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f22c67b4673dcf8b3dda999330bae09b61fa009ca4268a48dc2cc5465759bf47
MD5 c6c0e477c2efefe1aec4bd5bc10f23bf
BLAKE2b-256 093adad8f2a3ee4865c2511b8cdec857167fb785f3a4c7d42e4fa1def4b51b18

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fynance-1.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71fb0d0c72806a8686605fc7d27880e62474399c7a29ffa16f1b4118a5c785d6
MD5 fc780cc9fe56ca51ea48d52826a41816
BLAKE2b-256 006ce9b78086cc4871c803dce20538a26743e1a32d7231e2f31ee1f10ee7bc5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fynance-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5406c203abc95a9e08b28f1b96eebacc29a3b87e23c650c1768fbb6c7b0150b
MD5 726704988ea8e28355f455b148dde9cd
BLAKE2b-256 773f80c2d27a36eb2bbf539a05230743f316a7bf76ef140236e35e0f6d22b390

See more details on using hashes here.

Provenance

The following attestation bundles were made for fynance-1.5.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