calculate_rolling_metrics#

API documentation for tradeexecutor.visual.grid_search_advanced.calculate_rolling_metrics Python function.

calculate_rolling_metrics(grid_search_result, visualised_parameters, fixed_parameters, sample_freq='MS', lookback=Timedelta('90 days 00:00:00'), benchmarked_metric=BenchmarkMetric.sharpe)[source]#

Calculate rolling metrics for grid search.

We can have two parameters e.g. - N: size of traded basket - M: number of different pick sizes

For each N: - Calc rolling sharpe using last 3 months of returns (do in pandas) - This will give you an M-sized array or returns

For each quarter: - Look back 3 months and plot - yaxis: sharpe ratios - x-axis: array of Ns

Example output if using a single visualised parameter:

                0.50      0.75      0.99
2021-06-01       NaN       NaN       NaN
2021-07-01 -7.565988 -5.788797 -7.554848
2021-08-01 -3.924643 -1.919256 -3.914840
2021-09-01 -1.807489 -1.050918 -1.798897
2021-10-01 -1.849303 -1.604062 -1.841385
2021-11-01 -3.792905 -3.924210 -3.784793
2021-12-01 -4.156751 -4.186192 -4.148683

Example of 2d heatmap output:

                0.50                0.75                0.99
                   a         b         a         b         a         b
2021-06-01       NaN       NaN       NaN       NaN       NaN       NaN
2021-07-01 -7.565988 -7.565988 -5.788797 -5.788797 -7.554848 -7.554848
2021-08-01 -3.924643 -3.924643 -1.919256 -1.919256 -3.914840 -3.914840
2021-09-01 -1.807489 -1.807489 -1.050918 -1.050918 -1.798897 -1.798897
2021-10-01 -1.849303 -1.849303 -1.604062 -1.604062 -1.841385 -1.841385
2021-11-01 -3.792905 -3.792905 -3.924210 -3.924210 -3.784793 -3.784793
2021-12-01 -4.156751 -4.156751 -4.186192 -4.186192 -4.148683 -4.148683
Parma visualised_parameters:

Single parameter name for a line chart, two parameter name tuple for a heatmap.

Parameters:
Returns:

DataFrame where

  • Index is timestamp, by step

  • Each column is value of visualisation parameter

  • Each row value is the visualised metric for that parameter and that timestamp

The first row contains NaNs as it cannot be calculated due to lack of data.

Return type:

DataFrame