Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cetusfinance/qwack
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Apr 1, 2021
2 parents e371462 + 39b23c2 commit 210f61c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Qwack.Futures/FutureCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,29 @@ public DateTime GetExpiry()
var dateInMonth2 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonth2.NthSpecificWeekDay(DayOfWeek.Friday, 3).Day;
break;
case "FRI2":
var dateInMonthf2 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonthf2.NthSpecificWeekDay(DayOfWeek.Friday, 2).Day;
break;
case "LASTFRI":
var dateInMonth1 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonth1.NthLastSpecificWeekDay(DayOfWeek.Friday, 1)
.IfHolidayRollBack(_settings.RollGen.CalendarObject)
.Day;
break;
case "LASTMON-EUA":
var dateInMonth3 = new DateTime(YearNumber, monthNum, 1);
var lastMon = dateInMonth3.NthLastSpecificWeekDay(DayOfWeek.Monday, 1);
var holidayInWeek = false;
for (var i = 0; i < 5; i++)
{
holidayInWeek = holidayInWeek || _settings.RollGen.CalendarObject.IsHoliday(lastMon.AddDays(i));
}
if (holidayInWeek)
lastMon = dateInMonth3.NthLastSpecificWeekDay(DayOfWeek.Monday, 2);

dayOfMonthToStart = lastMon.IfHolidayRollBack(_settings.RollGen.CalendarObject).Day;
break;
default:
throw new Exception($"Dont know how to handle date code {_settings.ExpiryGen.DayOfMonthToStartOther}");
}
Expand Down Expand Up @@ -226,12 +243,29 @@ public DateTime GetRollDate()
var dateInMonth2 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonth2.NthSpecificWeekDay(DayOfWeek.Friday, 3).Day;
break;
case "FRI2":
var dateInMonthf2 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonthf2.NthSpecificWeekDay(DayOfWeek.Friday, 2).Day;
break;
case "LASTFRI":
var dateInMonth1 = new DateTime(YearNumber, monthNum, 1);
dayOfMonthToStart = dateInMonth1.NthLastSpecificWeekDay(DayOfWeek.Friday, 1)
.IfHolidayRollBack(_settings.RollGen.CalendarObject)
.Day;
break;
case "LASTMON-EUA":
var dateInMonth3 = new DateTime(YearNumber, monthNum, 1);
var lastMon = dateInMonth3.NthLastSpecificWeekDay(DayOfWeek.Monday, 1);
var holidayInWeek = false;
for(var i=0;i<5; i++)
{
holidayInWeek = holidayInWeek || _settings.RollGen.CalendarObject.IsHoliday(lastMon.AddDays(i));
}
if (holidayInWeek)
lastMon = dateInMonth3.NthLastSpecificWeekDay(DayOfWeek.Monday, 2);

dayOfMonthToStart = lastMon.IfHolidayRollBack(_settings.RollGen.CalendarObject).Day;
break;
default:
throw new Exception($"Dont know how to handle date code {_settings.RollGen.DayOfMonthToStartOther}");
}
Expand Down

0 comments on commit 210f61c

Please sign in to comment.