QuantConnect / Lean

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

Absence of fundamental data in Many tickers in backtest #7892

Closed ashutoshrana171 closed 7 months ago

ashutoshrana171 commented 7 months ago

Expected Behavior

In backtest the algorithm should give correct fundamental values.

Actual Behavior

For a lot of securities in backtest the algorithm does not give fundamental values. One example: the ticker "AFTY" gives correct fundamental data during Live but not in the backtest. The fundamental values are either 0 or nan during the backtest. This creates discrepancy in universe selection in backtest and live.

1) Backtest mode values:

image

2) Live mode values:

image

3) We can access correct data in research environment by calling History method:

image

Reproducing the Problem

We can run this code in backtest and live mode to check for the bug.

# region imports
from AlgorithmImports import *
# endregion

class SmallCapsScreener(QCAlgorithm):
    def Initialize(self):
        self.SetCash(10000)
        self.SetStartDate(2024,3,1)
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.FundamentalFilterFunction)
        self.SetWarmup(20)

    def FundamentalFilterFunction(self, fundamental: List[Fundamental]) -> List[Symbol]:
        selected = [x for x in fundamental if x.Symbol.Value == "AFTY"]
        self.Log(f" { [x.Symbol.Value for x in selected]} | MarketCap: {[x.MarketCap for x in selected]} | DollarVolume {[x.DollarVolume for x in selected]} | Price: {[x.Price for x in selected]} | Time: {self.Time}")
        return []

System Information

QC Cloud

Checklist

Martin-Molinero commented 7 months ago

Thank you for the report, the issue has been fixed starting from lean engine version 16336. To clarify, AFTY does not have fundamental data but just coarse data set, that's why market cap is 0, expected, dollar volume/price are available 👍.

does not have fundamental data

The boolean HasFundamentalData can be used to determine this.