Hi, I'm trying to check that the values for SharesOutstanding in the Fundamental dataset are correct. I use the following code in my research notebook:
qb = QuantBook()
ticker = 'AAPL' # let's try for Apple
symbol = qb.AddEquity(ticker)
# for aprox 10 years
history = qb.History(Fundamental, qb.Securities.Keys, 365 * 10, Resolution.Daily).loc[ticker]
# print values for the first and the last items
print(f"first on {history.iloc[0].name}: {history.iloc[0]['companyprofile'].SharesOutstanding}")
print(f"last on {history.iloc[-1].name}: {history.iloc[-1]['companyprofile'].SharesOutstanding}")
# let's check. maybe not all items have the same data.
shares_outstanding = [x.SharesOutstanding for x in history['companyprofile']]
for i, x in enumerate(shares_outstanding):
if x != shares_outstanding[0]:
print(f"(i): (x)") # <-- this doesn't get printed
print(f"completed. i: {i}")
and I get the following:
first on 2009-06-26 00:00:00: 15552752000
last on 2023-12-23 00:00:00: 15552752000
completed. i: 3649
That is all items in the history seem to have the same value for SharesOutstanding. I believe that it should not be the same. On tradingview I see that the number of shares outstanding gets decreased every quarter. The same thing reproduces for MSFT.
I suspect that I'm doing something wrong. Could you please suggest.
PS: I'm new to quantconnect and I just started to try it on a free (not paid) account.
Mia Alissi
Hi Stanislav,
It seems like you're trying to get the historical data for the number of shares outstanding for a given stock. In your code, you're using the
History
method withFundamental
type and the EquitySymbol
. This is the correct approach as per the QuantConnect documentation.However, it's important to note that if there is no data in the period you request, the history result is empty. This could potentially explain why you're seeing the same value for all items in the history.
Here's an example of how you can get historical fundamental data:
If you're still seeing the same value for all items in the history, it might be worth running a backtest on QuantConnect and comparing the result of
self.History
with the same data from another source. This can help you understand where the differences are coming from.If you continue to observe significant discrepancies, I would recommend posting a detailed question on the QuantConnect forum with specific examples. The community there may be able to provide further insights.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Stanislav Baranov
Nope. AI doesn't help here. In my example I requested data for 10 years, not 30 days. And it reproduces for IBM and df_history = qb.History(Fundamental, ibm, timedelta(365)).
Mia Alissi
I apologize for the confusion earlier. You're correct in your approach to request historical fundamental data for a period of 10 years. The code you've shared seems to be correct as per the QuantConnect documentation.
However, it's important to note that the data you receive depends on the availability of the data for the requested period. If there is no data available for the period you request, the history result will be empty.
If you're consistently seeing the same value for
SharesOutstanding
for all items in the history, it could be due to the data source or it could be a potential issue with the data provider.As per the QuantConnect forum discussion, to access fundamental data in QuantConnect, you need to use the
FineFundamental
objects in your fine universe selection function or theFundamentals
property of theEquity
objects in your algorithm.Here's an example of how to use the
FineFundamental
object to select symbols based on their P/E ratio:To access the fundamental data outside of your fine fundamental selection function, you can use the
Fundamentals
property of theEquity
objects in your algorithm:If you continue to observe discrepancies, I would recommend reaching out to the QuantConnect team or the community on the QuantConnect forum for further assistance.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Stanislav Baranov
It seems to be an issue only in research notebooks.Â
In backtests it works fine:
logs:
it looks correct. it doesn't match exactly the data on tradingview though.
Mia Alissi
Hi Stanislav,
It's great to hear that you're able to retrieve the correct
SharesOutstanding
data in backtests. The discrepancy you're observing between the data in research notebooks and backtests could be due to the different ways data is handled in these two environments.As for the difference between the data on QuantConnect and TradingView, it's important to note that different platforms may use different data sources, which can lead to slight discrepancies in the data. As mentioned in the QuantConnect documentation, QuantConnect uses institutional quality data from the Consolidated Tape Association (CTA) and Unlisted Trading Privileges (UTP) tick feeds, which cover the entire US tick feed. On the other hand, many charting websites use the Better Alternative Trading System (BATS), which only covers about 6-7% of the total market volume.
If you continue to observe significant discrepancies, I would recommend reaching out to the QuantConnect team or the community on the QuantConnect forum for further assistance.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Stanislav Baranov
I updated the code to be the minimum to reproduce the issue.
And TBH I also just wanted to try the project sharing feature because it's amazing.
Mia Alissi
Hi Stanislav,
Your code seems to be correct in terms of syntax and logic. However, the issue you're facing might be due to the way you're trying to access the
SharesOutstanding
data.In your
OnData
method, you're trying to access theSharesOutstanding
data using theFundamentals
property of theQCAlgorithm
class. However, this property is updated only once per day at midnight and it might not contain the most recent data.Here's an example of how you can access the
SharesOutstanding
data in theOnData
method:In this example, we're checking if the
Slice
object contains data for the symbol we're interested in. If it does, we're accessing theSharesOutstanding
data using theFundamentals
property of theSecurity
object.As for the research notebook, you're using the
History
method withFundamental
type and the EquitySymbol
. This is the correct approach as per the QuantConnect documentation. However, if there is no data in the period you request, the history result is empty. This could potentially explain why you're seeing the same value for all items in the history.If you continue to observe discrepancies, I would recommend reaching out to the QuantConnect team or the community on the QuantConnect forum for further assistance.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Stanislav Baranov
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!