Best way to write a CompoundMetric

Hi All,

I have a couple of questions.

I have defined this CM:

eval('MAX', 'DAY', (rolling('MAX', ChInRevproMeTruePositive) == 0) || (rolling('SUM', identity(1), ChInRevproMeTruePositive) > 3652) ? identity(5000) : rolling('SUM', identity(1), ChInRevproMeTruePositive), now() - period(15, 'YEAR'))

  1. the expression rolling(‘SUM’, identity(1), ChInRevproMeTruePositive) is evaluated 1 or 2 times? should I create a dedicated metric to increase the performance or is already manage (if the performance is not affected I prefer to not create a new metric that is used only here)?

  2. Ideally, I’d like that the eval (function) start to be the “start” in the evalMetrics minus 10 years. there is a way to use that date inside the metric? In this moment I’m using now() - period(15, ‘YEAR’)) to ensure that when I evaluated a metric in the last 5 year the metric is evaluated on a minimum of 10 years. I would like to do something like: start() - period(‘10’, YEAR’). The current solution is acceptable but it means that sometime I’m using 15 years when I really need only 10 and create the need for the condition “> 3652” to ensure that the same range is used for all the point in the training set. With the current logic if for some reason I evaluate the metric with a start period before 5 years ago the metric is calculated on less then 10 years.

The logic of the metric is:
Count the number of days since the last TP, if there is no TP in the last 10 years put a default value of 5000.


For this part you may use evalStart() in your metric to access the start of the evaluation period. See: How to get 'evalStart', 'evalEnd', 'evalInterval' in expression?

I am not sure. I want to say the metrics engine is able to compile the expression so that duplicate statements are not evaluated twice, but I am not familiar enough with the metrics engine to be certain on that

Thanks Scott, very useful, I will try it!

For the second part maybe @lpoirier is the right guy?