Hi Members, I am new to Python and Quantconnect. I am trying to fetch quarterly EPS history of stock:
eps_history = qb.GetFundamental(acad.Symbol, "EarningReports.BasicContinuousOperations.ThreeMonths", datetime(2022,3,1), endTime)
As here one EPS value gets repeated for three months I am using :
eps_history_filtered = eps_history.drop_duplicates()
but it is causing a bug in case of earnings where lets say Q1 EPS is 0.5 and Q4 EPS was also 0.5, so it removes one quarter data altogether.
Hence, I am trying to remove ONLY CONSECUTIVE duplicate values from my dataframe. I tried below approach (mentioned here: solution):
eps_history.loc[eps_history.shift() != eps_history]
but it is throwing below error:
ValueError: Cannot index with multidimensional key
can you please help me on how can I remove only consecutive duplicates in my case. Thanks in advance
Nico Xenox
Hey Log Up
Looking at your problem you simply could use the resample method.
Here it takes the first value of each month.
OUT:
From here on you can change or delete the data or use resample again to get what you need.
Hope it helps ;)
Log Up
Hi Nico Xenox, I tried it, but it is giving the same issue, let's say if I use drop_duplicates() on below dataframe
It is removing month 09,10 entries too:
Whereas I want the output like below:
Nico Xenox
Well it isnt the best solution but theoretically you could do this. The problem occurs when other stocks dont have the same Q as this one.
Note that 2022-09-30 didnt happen yet.
Log Up
Yes and another problem is I have seens stocks posting two quarter earnings with difference of just one month, so in that case we will mistakenly omit one value and it becomes hard to keep track of quarter over quarter earnings
Louis Szeto
Hi Log Up and Nico
Thank you for your great answer Nico. I think Nico is giving you a direction but not a copy-and-paste answer to solve your problem. You'll have to decide on how often was the resample frequency. For example, you could do “3M" instead of “M”.
Best
Louis
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.
Log Up
Hi Louis, I am not asking for copy-and-paste answer either. the problem with 3M is quarterly date is companies don't post earnings 3 Months apart precisely. For example this is for ACAD tickr:
in first two records there is only 1 month difference between disclosure. How can I get such values if I group over 3M data?
Nico Xenox
Well one way would be to compare them to the SECReport10Q.
Log Up
I have found below code works after many trial and errors, kindly check it and let me know if it is correct/if you have better solution:
It is removing consecutive duplicates only (please see -0.27 is appearing 2 times for different quarters).
Log Up
Hi Nico Xenox Thank you so much, will check it!
Log Up
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!