QuantConnect / Lean

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

Daily History Request Returns an Extra Day for Delisted Asset #7740

Closed DerekMelchin closed 7 months ago

DerekMelchin commented 8 months ago

Expected Behavior

If an asset is delisted on 2019-02-02, then a history request should not include a 2019-02-02 bar.

Actual Behavior

qb = QuantBook()
qb.History(qb.Symbol('IEI R735QTJ8XC9X'), datetime(2019, 1, 25), datetime(2019, 2, 5), Resolution.Daily)

image

Potential Solution

N/A

Reproducing the Problem

This backtest shows the delisting events Logs:

2019-02-01 00:00:00 : | 2019-02-01 00:00:00 // 0 2019-02-02 00:00:00 : | The security with symbol 'IEI' is marked as non-tradable. 2019-02-02 00:00:00 : | 2019-02-02 00:00:00 // 1

System Information

Checklist

jhonabreul commented 7 months ago

The last row is not an extra day, but the data for Feb01. Data in dataframes is indexed by EndDate, if you try the same case in C# you will see the last bar has Time=Feb01;EndTime=Feb02 (see this backtest).

image

In this specific case the volume is 0 because the data is being fill forwarded and the last raw data is for Jan31.

Check this other backtest for a different asset, for which the last data is actually on the day before the delisting date.

image
jhonabreul commented 7 months ago

In fact, this is a data issue, because the last trading date for the asset in the example was Jan 31 2019, being the delisting date actually Feb 01, not Feb 02 (which was a Saturday, btw).

References for the delisting (a merger with CenterPoint Energy, Inc.):

Martin-Molinero commented 7 months ago

Data issue created https://www.quantconnect.com/forum/discussion/16639/iei-r735qtj8xc9x-daily-the-issue-starts-from-feb-1st-2019-12-00-am-and-continues-until-feb-2nd-2019-11-59-pm/p1