Your interactive trading laboratory!
 • 
17 users online

Profiting From Monthly Trading Cycles

Hi Glitch,

I'm currently trying to map the cycle in the image using a coded rotational model. What do you think about my entry and exit conditions? Are they correct so far or have I forgotten something?

public override void PreExecute(DateTime dt, List<BarHistory> participants)
{
  // From the 7th to the 12th of the month and from the 20th to the 28th of the month
  if ((dt.Day < 7 || dt.Day > 12) && (dt.Day < 20 || dt.Day > 28))
  {
    rebalance = false;
    return;
  }
  
  // Is it a valid trading day according to the built-in holiday calendar?
  MarketDetails mkt = participants[0].Market;
  if (!mkt.IsTradingDay(dt))
  {
    rebalance = false;
    return;
  }
    
  rebalance = true;
  ...
}

public override void Execute(BarHistory bars, int idx)
{
  bool inBuyList = buys.Contains(bars);
  if (!HasOpenPosition(bars, PositionType.Long))
  {
    //buy logic - buy if it's in the buys list
    if (inBuyList)
    {
      PlaceTrade(bars, TransactionType.Buy, OrderType.Market);
    }
  }
  else
  {
    //sell logic, sell if entry execution is N days a go
    if (BarsSinceEntryExecution(bars, idx) >= (6 - 1))
    {
      PlaceTrade(bars, TransactionType.Sell, OrderType.Market);
    }
  }
}

Thanks...


Attachment

Cancel

Responses

A first test shows, that the entry date is not always kept in the required range.

A dump of a single symbol after the first two checks shows that the set of rules is kept so far.
Any ideas where this could come from?

Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 25 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 7 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 21 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 28 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 7 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 21 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 28 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Friday
Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Monday
Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Tuesday
Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Wednesday
Symbol is = AAON MonthDay is = 25 IsTradingDay = True WeekDay is = Thursday
Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Friday
A first test shows, that the entry date is not always kept in the required range. A dump of a single symbol after the first two checks shows that the set of rules is kept so far. Any ideas where this could come from? [CODE] Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 25 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 7 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 21 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 28 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 7 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 20 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 21 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 27 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 28 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 8 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 9 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 10 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 11 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 12 IsTradingDay = True WeekDay is = Friday Symbol is = AAON MonthDay is = 22 IsTradingDay = True WeekDay is = Monday Symbol is = AAON MonthDay is = 23 IsTradingDay = True WeekDay is = Tuesday Symbol is = AAON MonthDay is = 24 IsTradingDay = True WeekDay is = Wednesday Symbol is = AAON MonthDay is = 25 IsTradingDay = True WeekDay is = Thursday Symbol is = AAON MonthDay is = 26 IsTradingDay = True WeekDay is = Friday [/CODE]

Hi Merlin, I can't comment on your code at this moment, but the Figure 3 catches my eye. I don't at all see the clusters the way they are circled in green... I mean, of course I can see them, but that's not how I would draw them. That just makes them look like random blobs.
Consider: there's a known end-of-month rebalancing anomaly for momentum models, thought to be due to investment inflows from paychecks. And you can kinda see that here, with 1-day holding times and day-of-months 30, 31, and 1 with high hit rates. Similarly, there's another cluster around the mid-month for two paychecks a month (13, 14, 15, 16, 17).
Now any longer holding days (2+) can include that anomaly... you just back up the number of dates in your month by the number of holding days... and hey, you can draw wedges of anomalies here. I've kinda squiggled the wedges in here. At any rate, that's the kind of interpretation I see without reading the article or studying this at all. I just needed to put some sort of rationale on the patterns I was seeing, and it may be a well known phenomenon.

Hi Merlin, I can't comment on your code at this moment, but the Figure 3 catches my eye. I don't at all see the clusters the way they are circled in green... I mean, of course I can see them, but that's not how I would draw them. That just makes them look like random blobs. Consider: there's a known end-of-month rebalancing anomaly for momentum models, thought to be due to investment inflows from paychecks. And you can kinda see that here, with 1-day holding times and day-of-months 30, 31, and 1 with high hit rates. Similarly, there's another cluster around the mid-month for two paychecks a month (13, 14, 15, 16, 17). Now any longer holding days (2+) can include that anomaly... you just back up the number of dates in your month by the number of holding days... and hey, you can draw wedges of anomalies here. I've kinda squiggled the wedges in here. At any rate, that's the kind of interpretation I see without reading the article or studying this at all. I just needed to put some sort of rationale on the patterns I was seeing, and it may be a well known phenomenon.

Thanks for your answer. I've seen something similar in that picture. However, this analysis was done on the SPY. I would like to do the test selectively on stocks to see, if a useful pattern turns up.

Thanks for your answer. I've seen something similar in that picture. However, this analysis was done on the SPY. I would like to do the test selectively on stocks to see, if a useful pattern turns up.
Forum Tips

Please sign in if you want to participate in our forum.

Our forum uses Markdown syntax to format posts.

To embed code snippets, enclose them in [CODE][/CODE] tags.