Library for portfolio creation (by clustering) of financial time series with evaluation and visualizations.
Click to expand!
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.
python -m pip install git+https://github.com/JakRys/finclust
It is simple to use this package. After the import, you need to do three steps:
- Create PortfolioManager (according to how you want to evaluate);
- Run the evaluation.
- 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 .
This package is licensed under the MIT license, so it is open source.
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.
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.
@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},
}