Parameter optimization for finance
Project description
Fintuna: Parameter optimization for finance
Fintuna is a framework that uses machine learning for asset management. It enables fast prototyping for multi-asset applications such as stock-picking.
- Features:
model training
hyper-parameters tuning
walk-forward backtesting
strategy evaluation
It is a lightweight framework that combines LightGBM, Optuna, Quantstats and Shap to develop ML-based stock-picking strategies.
Multi Asset
Looking at multiple assets is supposed to reveal more alpha-opportunities than looking at a single one. Also, the more assets the more data which is beneficial for machine learning tasks. Therefore, Fintuna is designed for multi-asset applications. The data structure is a Pandas Multiindex Dataframe where the index is time, the first column-level is the asset and the second is the feature (= panel or longitudinal data). Internally features are stacked and a model is trained to learn cross-asset patterns.
# |
Asset 1 |
Asset 2 |
Asset 3 |
Asset 4 |
||||
---|---|---|---|---|---|---|---|---|
# |
feature1 |
feature2 |
feature1 |
feature2 |
feature1 |
feature2 |
feature1 |
feature2 |
t0 |
float |
category |
float |
category |
float |
category |
float |
NaN |
t1 |
float |
category |
float |
category |
float |
category |
float |
NaN |
Strategy Agnostic
Fintuna is not tied to one specific trading strategy. Strategies are implemented as fintuna.model.ModelBase. It defines the classification task (= extract_label) as well as a a classification-to-returns mapping (= realized_returns). A simple example is to predict the directional change and buy the asset with the most confident prediction (see fintuna.model.LongOnly).
Backtesting
Fintuna uses walk-forward backtesting.
Train data is used to train the classifier.
Tune data is used for hyper-parameter optimization.
Eval data is used for backtesting
Executing the fintuna.Finstudy.explore method multiple times on same data introduces the risk of overfitting. Use feature importance and shap values, rather than merely looking at trading performance.
Calling fintuna.Finstudy.finish prepares the model for deployment. It sub-selects models that also perform well on evaluation data. and refits them on all data.
Data First
A good trading strategy demands good and possibly unique data. Fintuna does NOT help you in finding the right data. But consider the following guidelines:
Have at least a few hundreds of observations.
Use multiple assets.
Use assets with similar characteristics (e.g. cryptos, tech-stocks, etc.).
Make sure features across assets have similar properties (otherwise use zscore).
Use lagged features to boost performance.
Usage
Install fintuna via pip.
pip install fintuna
Run the most basic example below. For detailed guidance look at examples at docs or at docs/source/examples.
import fintuna as ft
# get data
data, specs = ft.data.get_crypto_features()
# explore
crypto_study = ft.FinStudy(ft.model.LongOnly, data, data_specs=specs)
results = crypto_study.explore(n_trials=50, ensemble_size=3)
# analyze
ft.utils.plot_backtest(results['performance'], results['benchmark'])
TODO
Binance Trading Sink
MajorityVoteEnsemble
Backtest plots with shap values
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
Built Distribution
File details
Details for the file fintuna-0.1.5.tar.gz
.
File metadata
- Download URL: fintuna-0.1.5.tar.gz
- Upload date:
- Size: 36.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7527aeb6a792490e4dfd135aa387dab65911b00337de731ad015e8ef3a1a3ebc |
|
MD5 | 12bc88db5510b641cad98dcbfe26a6a7 |
|
BLAKE2b-256 | 82b4db4270ba2c4e333eef01712ada1114838815566cd04d1e58a16b55458152 |
File details
Details for the file fintuna-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: fintuna-0.1.5-py3-none-any.whl
- Upload date:
- Size: 36.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0b9c2b3987d5d33170020b5f6819d555f196595ef2574a54df3973e7ec2dd65 |
|
MD5 | 47a76fe7c52a4e92ad7d41ee848149fd |
|
BLAKE2b-256 | ae478558db24d5aa8df324156e7cf1c12b60040194707dee108d184cde5e52c5 |