Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Jan 16, 2025
1 parent ceba1cd commit 38bfa3c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Tests/Common/Securities/Futures/FuturesExpiryFunctionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ public void EnergyExpiryDateFunction_WithDifferentDates_ShouldFollowContract(str
}
}

[Test]
public void BankHolidaysAreRespected()
{
//Arrange
var futureSymbol = GetFutureSymbol("6E", new DateTime(2025, 2, 1));
var func = FuturesExpiryFunctions.FuturesExpiryFunction(GetFutureSymbol("6E"));
// Expiry date is the second business day immediately preceding the third Wednesday of the contract month(usually Monday).
// The third wednesday is the 19th so the expiry date should be monday 17th, but that day is a bank holiday
// so the real expiry date is the 14th
var expiryDate = func(futureSymbol.ID.Date);

//Assert
Assert.AreEqual(new DateTime(2025, 2, 14), expiryDate.Date);
}

// 25th is a sunday
[TestCase(QuantConnect.Securities.Futures.Energy.MicroCrudeOilWTI, "20221001", "20220919")]
[TestCase(QuantConnect.Securities.Futures.Energy.CrudeOilWTI, "20221001", "20220920")]
Expand Down
23 changes: 23 additions & 0 deletions Tests/Common/Securities/MarketHoursDatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ public void CorrectlyReadsCMEGroupFutureEarlyCloses(string futureTicker, string
}
}

[TestCase("BIO", Market.CME, true)]
[TestCase("5YY", Market.CBOT, true)]
[TestCase("6E", Market.CME, true)]
[TestCase("BTC", Market.CME, true)]
[TestCase("A8O", Market.NYMEX, true)]
[TestCase("PAM", Market.NYMEX, true)]
[TestCase("ZC", Market.CBOT, false)]
[TestCase("LBR", Market.CME, false)]
[TestCase("HE", Market.CME, false)]
[TestCase("DY", Market.CME, false)]
[TestCase("YO", Market.NYMEX, true)]
public void CorrectlyReadsCMEGroupFutureBankHolidays(string futureTicker, string market, bool isBankHoliday)
{
var provider = MarketHoursDatabase.FromDataFolder();
var ticker = OptionSymbol.MapToUnderlying(futureTicker, SecurityType.Future);
var future = Symbol.Create(ticker, SecurityType.Future, market);

var futureEntry = provider.GetEntry(market, ticker, future.SecurityType);
var bankHolidays = futureEntry.ExchangeHours.BankHolidays;
var bankHoliday = new DateTime(2025, 11, 27);
Assert.AreEqual(isBankHoliday, bankHolidays.Contains(bankHoliday));
}

[TestCase("2YY", Market.CBOT, true)]
[TestCase("TN", Market.CBOT, true)]
[TestCase("6A", Market.CME, true)]
Expand Down

0 comments on commit 38bfa3c

Please sign in to comment.