Giter Site home page Giter Site logo

jduarte00 / clustering_shrinkage_estimator Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 5.59 MB

Implementation of the correlation matrix estimator using shrinkage technique with clustering.

Jupyter Notebook 99.86% Python 0.14%
quantitative-finance machine-learning clustering correlation-matrix

clustering_shrinkage_estimator's Introduction

Cluster based shrinkage of correlation matrix implementation

This is an implementation using Python of the Cluster-based shrinkage correlation estimator proposed by Begusic and Kostanjcar in the paper Cluster-Based Shrinkage of Correlation Matrices for Portfolio Optimization (2019) that can be found here.

This estimator uses a clustering method to identify the underlying structure in the sample correlation matrix and then uses the structure to regularize the entries of the sample correlation estimator.

The purpose of this estimator is to regularize the correlation matrix estimation of a data set in high dimensionality (i.e. when the number of columns and the number of rows of your data set are big). There is a shrink factor $\alpha$ that allows adjusting the level of regularization of the estimator between the sample correlation estimator (R) (this is the one that is typically implemented in np.corrcoef or pd.Dataframe.corr ) and a shrinked version of R.

Use

You can use this estimator on a pandas dataframe of size $T \times N$ (in Finance, this dataframe would typically be a matrix with T returns of N assets ). You need to first clone the repo and replace the source of your data (to be able to import the estimator, you have to make sure to execute your import from a file in the same directory that the 'implementation_sbs.py' file is ). An example of use is the following:

# importing the library
import clustering_shrinkage_estimator

# load your data matrix
import pandas as pd
data = pd.read_csv('./my dataframe')

#Calculate the shrinked estimator with an alpha of 1
r_clustering = clustering_shrinkage_estimator.get_shrinkage_est(data, alpha = 1)

Results

The purpose of this estimator is to regularize the correlation matrix estimation of a data set in high dimensionality (i.e. when the number of columns and the number of rows of your data set are big). There is a shrink factor $\alpha$ that allows adjusting the level of regularization of the estimator. An example of the estimator calculated using the S&P 500 over 6 years of historical data using three different levels of $\alpha$ (1, 0.5 and 0) is shown below:

In the future, I'll try to turn this estimator into a function that will be available for download through PIP.

clustering_shrinkage_estimator's People

Contributors

jadm07 avatar jduarte00 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

anjalijha167

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.