Correlation Filter – Custom Analysis
Especially when using Genetic Evolution and/or when using optimisation tasks in your workflow, strategies can sometimes be highly correlated, not only as a result of the build task, but because of other tasks.
This filter can be added to a Custom Project as a task at any stage in your workflow so that correlated strategies are removed.
This Custom Analysis accepts an input argument which corresponds to the correlation threshold which will be applied. When there is a correlation between two strategies higher than the threshold, the strategy with the highest fitness score of the two will be kept and the other one will not be included into the target databank.
Correlation is calculated based on daily profit and loss.
If you specify different source and target databanks, then only the uncorrelated strategies will be copied to the target databank.
If you want the analysis to remove correlated strategies from a databank, you can set the same databank as the source and target, and enable the option “Filter by results of custom analysis. If true strategies that don’t pass will be removed”.
This was inspired by the Filter by Correlation Plugin example, cf. https://strategyquant.com/doc/programming-for-sq/filter-by-correlation-plugin-example/
and noticing that in SQX discord and in the forum many were looking for this functionality (including myself).
to which folder have to copy this snippet and compile?
It needs to be placed under SQX\user\extend\Plugins
info: file .sxp must be imported by Import Extension tool in code editor and compile.It required SQX build 140 or higher
I think this is a good filter. I think this filter should be integrated in the product.
I agree with you
Hello Kevin, Firstly thank you for your share in codebase about CorrelationFilter in the custom Analysis.
I tried to use it, however i have always some duplicated strategies, max 2 or 3 unic strategy after several cycles in my custom. See the example. Possible that is an error in CorrelationFilter ? Thank you in advance Jean
Hi! I haven’t been able to reproduce this error.
For the implementation of the correlation calculation itself, the custom analysis is using functions already provided by the core SQX code.
Thank you Kevin !