quantlab.analysis.factor_correlation.FactorCorrelationFigure#

class quantlab.analysis.factor_correlation.FactorCorrelationFigure(label_limit=800, top_pairs=20, top_clusters=12)[source]#

Bases: object

Draw a FactorCorrelation so that hundreds of variables stay readable.

The main panel is the mean correlation in cluster order on a fixed -1..1 diverging scale (red negative, gray none, blue positive), so redundant factors form blocks on the diagonal; every cluster of two or more variables is outlined, and the diagonal, always 1, is left blank. Up to label_limit variables every row and column is named: the heatmap grows so each row is at least 6.5 points high, and past about a hundred variables the names are meant to be read zoomed in (the saved PNG is written at FIGURE_DPI). Beyond label_limit the axes name the clusters of two or more variables instead, and factor_clusters.csv maps every variable to its cluster and position. Beside it: the strongest pairs by |correlation|, the largest clusters with their first members, and the distribution of all pairs on a log count scale so the few strong pairs stay visible.

Parameters:
label_limitint, default 800

Most variables whose names are written on the heatmap axes. At 800 the heatmap is about 72 inches, some 10,800 pixels at FIGURE_DPI.

top_pairsint, default 20

Strongest pairs listed beside the heatmap.

top_clustersint, default 12

Largest clusters listed beside the heatmap.

Examples

>>> fig = FactorCorrelationFigure().render(corr)
>>> fig.savefig("factor_correlation.png")
render(corr)[source]#

Return the figure of corr.

Built with matplotlib.figure.Figure rather than pyplot, so it is never shown and needs no closing.

Examples

>>> FactorCorrelationFigure().render(corr).get_suptitle()
'Factor correlation   |   3 factors, 2 clusters at |corr| >= 0.7'