Standard Deviation of monthly returns

Hi P123 power users.

Could you please help me code monthly standard deviation of returns over, say, a year for any ticker?

Thanks!

You can use [font=courier new]PctDev(12, #Month, 0, 12)[/font] to approximate this. [font=courier new]#Month[/font] evaluates to 21, the approximate number of day bars in a month. The last ‘12’ causes it to yield [font=courier new]NA[/font] whenever fewer than 252 bars are available.

If you really, really need calendar months, you would currently have to do something like this:

SetVar(@Year, AsOfDate / 10000)
LoopStdDev("Close(BarsSince(Eval(@CTR < 12, Eval(Month > @CTR, @Year, @Year - 1) * 10000 + (@CTR + 1) * 100, @Year * 10000 + 100) + 1)) / Close(BarsSince(Eval(@CTR < 12, Eval(Month > @CTR, @Year, @Year - 1) * 10000 + @CTR * 100, (@Year - 1) * 10000 + 1200) + 1))", 12) * 100

This is still not entirely correct because it’s using the first day of the month, only falling back to the last day of the previous month if the first day of the month is not a trading day.

Feel free to open a feature request if you think it’s warranted.