Seasonality
All indicators

LibraryTime

Indicator

Seasonality

How the instrument did in the past in periods like the current one: the mean return, the share that went up and a t statistic for the bar's month, weekday, turn of the month or hour.

TimeOwn pane3 inputsSeason

How it is calculated

Periods are hours, days or months on the chosen clock. When one ends, its return (last close divided by the last close of the period before, minus 1) joins its bucket: the hour 0 to 23, the weekday 0 (Monday) to 6, the turn of the month (the last weekday and the first three of a month) as 1 against 0, or the month 1 to 12. t_stat is the mean divided by the sample deviation over the square root of the count.

Reference: Calendar effects: day of the week, turn of the month (Ariel 1987), month of the year

How to read it

The running period never counts, so a bar never feeds the number it reads. Mean, share and t wait for the minimum count. Small samples are noisy, and an effect found by looking at many buckets is often luck: a t around 2 from a dozen returns is weak evidence, and it assumes the returns are independent, which they rarely are.

In a strategy

As a filter: with s = ctx.ind("seasonality", by="weekday", min_count=20) take longs only while s.mean is above 0 and s.t_stat above 2, or skip the turn of the month with by="turn_of_month".

Inputs

InputTypeDefaultRange or choices
Group bybyChoice"weekday"Month, Weekday, Turn of the month, Hour
ClockzoneChoice"utc"UTC, London, New York, Tokyo, Sydney
Minimum returnsmin_countWhole number10min 2, max 1000

What it draws

LineDrawn as
Mean returnColumns

Used in

No strategy template reads it yet.

OrionQuant