JakRys / finclust

Library for portfolio creation (by clustering) of financial time series with evaluation and visualizations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FinClust

Open Source? Yes! GitHub license Imports: isort CodeFactor Open in Colab

Library for portfolio creation (by clustering) of financial time series with evaluation and visualizations.

Table of Content

Click to expand!

Description

This library aims to simplify the workflow of portfolio creation and evaluation. It is primarily focused on financial time series data. It helps with:

  • data preprocessing,
  • calculation of affinities,
  • clustering of assets/portfolio selection,
  • calculation and evaluation of portfolios returns,
  • visualizations.

The framework is designed for easy customization and extension of its functionality.

Installation

python -m pip install git+https://github.com/JakRys/finclust

Usage

It is simple to use this package. After the import, you need to do three steps:

  1. Create PortfolioManager (according to how you want to evaluate);
  2. Run the evaluation.
  3. Create visualizations.
## Import the required modules
from datetime import timedelta
import numpy as np

from finclust import PortfolioManager
from finclust.clustering import ScikitClusterer
from finclust.evaluation import QuantstatsEvaluator

from sklearn.cluster import AgglomerativeClustering

## Create instance of PortfolioManager
mgr = PortfolioManager(
    window = timedelta(weeks=16),
    step = timedelta(weeks=4),
    affinity_func = np.corrcoef,
    clusterer = ScikitClusterer(
        cluster_method = AgglomerativeClustering(affinity="precomputed", linkage="single", n_clusters=5),
    ),
    evaluator = QuantstatsEvaluator(),
)
## Run the process
mgr.run(data=data)

See the examples folder for more details or Open in Colab.

License

GitHub license

This package is licensed under the MIT license, so it is open source.

Disclaimer

This library was created as part of my master's thesis.

The structure is heavily inspired by the SeqRep package (my earlier project), which is designed for supervised learning.

Acknowledgement

First of all, I would like to thank Petr Sojka for supervising my thesis. I am grateful to Michal Stefanik for his valuable consultations, especially regarding the code. Gratitude also belongs to all members of the MIR-MU group for their comments.

How to cite

@mastersthesis{Rysavy2022thesis,
  AUTHOR = {Ryšavý, Jakub},
  TITLE = {Machine Learning for Algorithmic Trading of Decentralized Finances},
  YEAR = {2022},
  TYPE = {Master's thesis},
  INSTITUTION = {Masaryk University, Faculty of Informatics},
  LOCATION = {Brno},
  SUPERVISOR = {Petr Sojka},
  URL = {https://is.muni.cz/th/xc3yt/},
  URL_DATE = {2022-12-13},
}

About

Library for portfolio creation (by clustering) of financial time series with evaluation and visualizations.

License:MIT License


Languages

Language:Python 100.0%