8. 10. 2024

5 8

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).

 

 

 

 

Subscribe
Notify of
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Libor Stepan
Libor Stepan
18. 10. 2024 4:49 pm

to which folder have to copy this snippet and compile?

tomas262
Admin
Reply to  Libor Stepan
18. 10. 2024 7:42 pm

It needs to be placed under SQX\user\extend\Plugins

Libor Stepan
Libor Stepan
19. 10. 2024 8:59 am

info: file .sxp must be imported by Import Extension tool in code editor and compile.It required SQX build 140 or higher

tnickel
4. 11. 2024 2:12 pm

I think this is a good filter. I think this filter should be integrated in the product.

Libor Stepan
Libor Stepan
Reply to  tnickel
7. 11. 2024 3:02 pm

I agree with you

JeanJean
11. 11. 2024 12:45 pm

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

comment image

Emmanuel
23. 1. 2025 8:46 am

Thank you Kevin !