Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HSI future expirations #8505

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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