QuantConnect/Lean · error · RegressionTestException
Future contracts did not work up as expected: {addedSecurity
Error message
Future contracts did not work up as expected: {addedSecurity.Symbol} What it means
Same invariant as BasicTemplateFuturesAlgorithm: OnSecuritiesChanged asserts every non-canonical future contract added by the universe has data (HasData). A concrete contract added without data is untradeable and signals a filter or data-feed problem in the extended-market configuration.
Source
Thrown at Algorithm.CSharp/BasicTemplateFuturesWithExtendedMarketAlgorithm.cs:134
if (buyingPowerModel == null)
{
throw new RegressionTestException($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
}
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var addedSecurity in changes.AddedSecurities)
{
if (addedSecurity.Symbol.SecurityType == SecurityType.Future
&& !addedSecurity.Symbol.IsCanonical()
&& !addedSecurity.HasData)
{
throw new RegressionTestException($"Future contracts did not work up as expected: {addedSecurity.Symbol}");
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 117079;View on GitHub (pinned to d2c3659f87)
Solutions
- Tighten the future contract SetFilter to contracts with data.
- Ensure extended-hours futures data for selected contracts is downloaded.
- Filter the chain on HasData/liquidity before selecting.
- Verify the subscription/data-feed configuration covers added contracts.
Example fix
// before where futuresContract.Expiry > Time.Date.AddDays(90) // after where futuresContract.Expiry > Time.Date.AddDays(90) && futuresContract.HasData
Defensive patterns
Strategy: validation
Validate before calling
foreach (var added in changes.AddedSecurities)
{
if (added.Symbol.SecurityType == SecurityType.Future
&& !added.Symbol.IsCanonical() && !added.HasData)
{
Log($"{added.Symbol} added without data; tighten filter.");
}
} Type guard
bool IsTradeableFutureWith(Security s) => s.Symbol.SecurityType == SecurityType.Future && !s.Symbol.IsCanonical() && s.HasData;
Prevention
- Tighten the contract SetFilter to exclude dataless contracts.
- Ensure extended-hours futures data for selected contracts is present.
- Filter the chain on HasData before selecting.
When it happens
Trigger: OnSecuritiesChanged receives an added security that is SecurityType.Future, non-canonical, but HasData == false in the extended-market algorithm — a real contract was selected without a backing data subscription.
Common situations: The contract filter selected an expiry with no data; extended-hours data for the contract is missing; the SetFilter range included empty/illiquid contracts; the data feed was not configured for the selected contract.
Related errors
- Future contracts did not work up as expected: {addedSecurity
- Invalid buying power model. Found: {buyingPowerModel.GetType
- Invalid buying power model. Found: {buyingPowerModel.GetType
- Empty history at {Time}
- {Time} unexpected symbol changed event {changedEvent}!
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/3522b243f7f8f972.
Report an issue: GitHub.