I am trying to create an exploration for SharpeRatio of Stocks. So far this works well with a fixed range period. However, when I try to adjust the range period to the maximum number of bars available for the stock (using BarIndex() as shown in the code) it shows me an error "range must be greater than zero and not null"
Would there be a workaround to display each stock's Sharpe Ratio individually using it's maximum historical bars? Many thanks in advance.
//SharpeRange = LastValue(BarIndex()); // This does not work
SharpeRange = 30; // This works
SDF = StDev(ROC(Close, 1), SharpeRange);
Sharpe = MA(ROC(Close,1), SharpeRange) /(SDF);
AddColumn(Sharpe, "Sharpe", 1.2 );
But I'm still getting an error message "Invalid argument value for MA() function; range must be greater than zero (and not Null)"
Seems the issue is the functions only allow a static period despite the filter. Still appreciate any ideas how to calculate the average returns, StDev of stocks using BarCount instead of a fixed period.
No, it's not true. If you have an Error saying, that for MA() or StDev() function, range must be greater than zero (and not Null), you should make sure, that the range is indeed grater than zero. For example like this: