Skip to content

Commit

Permalink
Fix HSI future expirations (#8505)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero authored Jan 6, 2025
1 parent 7ee297a commit f17726b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Common/Securities/Future/FuturesExpiryFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,12 @@ public static Func<DateTime, DateTime> FuturesExpiryFunction(Symbol symbol)

// The Business Day immediately preceding the last Business Day of the Contract Month
var lastDay = new DateTime(time.Year, time.Month, DateTime.DaysInMonth(time.Year, time.Month));
var priorBusinessDay = lastDay.AddDays(-1);

var holidays = FuturesExpiryUtilityFunctions.GetHolidays(Market.HKFE, Futures.Indices.HangSeng);
while (holidays.Contains(priorBusinessDay) || !priorBusinessDay.IsCommonBusinessDay())
{
priorBusinessDay = priorBusinessDay.AddDays(-1);
}
var lastBusinessDay = FuturesExpiryUtilityFunctions.AddBusinessDaysIfHoliday(lastDay, -1, holidays);
var priorBusinessDay = lastBusinessDay.AddDays(-1);

priorBusinessDay = FuturesExpiryUtilityFunctions.AddBusinessDaysIfHoliday(priorBusinessDay, -1, holidays);
return priorBusinessDay.Add(new TimeSpan(16, 0, 0));
})
},
Expand Down
12 changes: 12 additions & 0 deletions Tests/Common/Securities/Futures/FuturesExpiryFunctionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public void Init()
}
}

[Test]
public void HSIFutures()
{
var canonical = Symbol.Create("HSI", SecurityType.Future, Market.HKFE);
var expiration = FuturesExpiryFunctions.FuturesExpiryDictionary[canonical];

// last day and previous are holidays
Assert.AreEqual(new DateTime(2025, 1, 27, 16, 0, 0), expiration(new DateTime(2025, 1, 1)));
// normal case
Assert.AreEqual(new DateTime(2025, 2, 27, 16, 0, 0), expiration(new DateTime(2025, 2, 1)));
}

[Test]
public void FuturesExpiryFunction_MissingSymbol_ShouldThrowArgumentException()
{
Expand Down

0 comments on commit f17726b

Please sign in to comment.