Package: rie-estimator
With this package, you can clean correlation matrices of data sets in the context of high dimensionality using theRIE Estimator(Rotationally Invariant Estimator, a.k.a oracle estimator) developed by Bouchaud and Knowles in 2016 that can be foundhere.Broadly speaking, the estimator is defined as:The algorithm to standardize the data matrix and to calculate this estimator is followed exactly as proposed by this authors, and this implementation try to use vectorized operations when possible to improve the speed of the calculations.In general, this estimator is used mainly in finance to obtain the correlation between assets, and it has been shown that this estimator is more precise when working with matrices in which N is approximate of the same order than T (that is, that the number of columns is of the same order that the number of rows) compared to the sample correlation matrix estimator, which is defined as below (X is the data matrix):The package takes as the input apandas dataframewith no empty values and containing only numeric features and returns anumpy matrixwith the cleansed correlation matrix (i.e. the RIE estimator).InstallationYou can install the package withpip:pipinstallrie_estimatorDependencies.There are only two dependencies so far:pandasandnumpy.Example of useThe input has to be a pandas dataframe containing the raw data with N columns and T rows (in Finance, this would be a matrix containing T returns of N assets), for example:BTC-USDGC=FGOOGL^MXX2021-01-050.0631970.0041140.0047840.0045892021-01-060.083311-0.023455-0.0020180.0151212021-01-070.0691570.002832-0.0123820.0131952021-01-080.036234-0.0408930.0175180.011705We can calculate the cleansed correlation matrix between this 4 assets as follows:# importing the libraryimportrie_estimator# load your data matrixdata=pd.read_csv('./my dataframe')#Calculate the RIE estimator# If you don't want your data matrix to be standardize,# then set normalize = Falsecleansed_rie=rie_estimator.get_rie(data,normalize=True,max_ones=True)#Take a look at your cleansed RIE!print(cleansed_rie)#Output[[1.10561502-0.02218840.001433680.07711][-0.02218841.10813374-0.07954577-0.00211591][0.00143368-0.079545771.10425599-0.01714854][0.07711-0.00211591-0.017148541.10154842]]ResultsJust to show the advantages of using the RIE estimator against the sample correlation matrix, below it is shown the difference between the in-sample risk and out-of-sample risk of the optimal frontier when using the RIE with the Markowitz portfolio theory with assets from the S&P500. It is known that the true risk of the portfolio lies between the calculated in-sample and out-of-sample risk, and therefore a smaller gap between these two indicates a more precise estimation of the true risk, which is the result of using a more precise estimator.It can be seen that the gap between both risks is reduced when using the RIE estimator, in contrast to the sample covariance matrix.To-doI hope to be able to eventually implement a couple of things:Alternative forms of standardizing the data matrix, as suggested by Bouchaud and Potters.Accepting other objects as inputs (such as numpy matrices).Implementing new research related to enhancing the precission of this estimator.