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?
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;
Rename
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; }
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
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
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.
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.
It seems that with WL8 B11...
...has been removed...
What's the proper replacement here?
CODE:
bars.Scale.Scale.DaysInScale()
...has been removed...
What's the proper replacement here?
CODE:
bars.Scale.Frequency.DaysInScale
Your Response
Post
Edit Post
Login is required