- ago
I have a coded rotation strategy. In the PreExecute() event, I need to generate the signals on the last trading day of a month. I came across a member called TradingDaysRemaining() (which is undocumented...).

Here is my current code snippet. Is this the correct way to calculate the last trading day of a month in a coded rotation strategy?

CODE:
      public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          rebalance = false;          BarHistory participant = participants.First();          int idx = GetCurrentIndex(participant);          remaining = participant.TradingDaysRemaining(GetCurrentIndex(participant), HistoryScales.Monthly);          if (remaining == 0)          {             rebalance = true;          }                    if (!rebalance)             return;
0
832
Solved
5 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.08% )
- ago
#1
In the next Build 7 we will offer this DateTime extension method, here is the code:

CODE:
//is this the last trading day of the month? public static bool IsLastTradingDayOfMonth(this DateTime dt, BarHistory bars) { int daysPerBar = bars.Scale.Scale.DaysInScale(); if (daysPerBar <= 0) daysPerBar = 1; DateTime next = dt.AddDays(daysPerBar); while (!bars.Market.IsTradingDay(next)) next = next.AddDays(1); if (dt.Month != next.Month) return true; return false; }
0
- ago
#2
Good idea.

In QS, I have used a Helper Utilities class with the following extension methods. Could make sense that you include them as well:

- Bars since entry execution
- First trading day of a new month
- Fixed trading day within a month
- Fixed trading day within a week


0
- ago
#3
We've translated the most frequently used date/time functions (Post #3):
https://www.wealth-lab.com/Discussion/DateTime-functions-from-WL6-5847

But in WL7 their syntax may change and they'll get documented in the QuickRef.
0
- ago
#4
It seems that with WL8 B11...
CODE:
bars.Scale.Scale.DaysInScale()

...has been removed...
What's the proper replacement here?

0
- ago
#5
CODE:
bars.Scale.Frequency.DaysInScale
0
Best Answer

Reply

Bookmark

Sort