QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.99k stars 3.29k forks source link

MapResolver should return null if we ask for a delisted ticker #4049

Closed Jay-Jay-D closed 4 years ago

Jay-Jay-D commented 4 years ago

Expected Behavior

MapResolver.ResolveMapFile(ticker, date) should return null if we ask for a ticker delisted before date

Actual Behavior

It returns the last MapFile with the ticker

Potential Solution

Check the MapResolver.ResolveMapFile date logic.

Reproducing the Problem

This test should pass, but it fails in current master.

[Test]
public void ResolvesDelistedSymbolAsNull()
{
    var mapResolver = new MapFileResolver(new List<MapFile>
    {
        new MapFile(
            "amz",
            new List<MapFileRow>
            {
                new MapFileRow(new DateTime(1998, 01, 02), "uwz"),
                new MapFileRow(new DateTime(1998, 09, 11), "uwz"),
                new MapFileRow(new DateTime(2004, 12, 31), "amz")
            }
        )
    });
    var date = new DateTime(2007, 01, 03);
    var ticker = "AMZ";
    Assert.IsNull(mapResolver.ResolveMapFile(ticker, date));
}

System Information

Windows

Checklist

Martin-Molinero commented 4 years ago

Closing based on https://github.com/QuantConnect/Lean/pull/4051#issuecomment-582968395