[IMPROVE] ratios.collect_all_ratios() misses current year's first quarter
brianrasmusson opened this issue · 4 comments
When I calculate all ratios from 2018-01-01 until todays date (2023-11-03), I don't get data for 2023 Q1.
Printing the DataFrame returned by collect_all_ratios show date for these quarters - as you can see, 2023Q1 is missing:
2018Q1 2018Q2
2018Q3 2018Q4
2019Q1 2019Q2
2019Q3 2019Q4
2020Q1 2020Q2
2020Q3 2020Q4
2021Q1 2021Q2
2021Q3 2021Q4
2022Q1 2022Q2
2022Q3 2022Q4
2023Q2 2023Q3
companies = Toolkit(["AAPL"], api_key=API_KEY, start_date="2018-01-01", quarterly=True)
all_ratios = companies.ratios.collect_all_ratios()
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
print(all_ratios)
Using version 1.5.0
Hi @brianrasmusson,
Apple is quite an interesting one given that they have a different accounting year than the usual. E.g. their fourth quarter (Q4) ended on September 30, 2023 and their third on the 1st of July 2023. What I attempt to do is make it uniform for all companies so that even though its Q2 for Apple and Q1 for Microsoft, it's about the same period so they should fit in the same period basket.
However, I base this off the date column which unfortunately for Apple doesn't coincide with the correct period. E.g. Q1 2023 of Apple is actually the period September until December of 2022 and Q2 2023 is January until March of 2023. However, the data gets me the following:
{
"date": "2023-04-01",
"symbol": "AAPL",
"reportedCurrency": "USD",
"cik": "0000320193",
"fillingDate": "2023-05-05",
"acceptedDate": "2023-05-04 18:03:52",
"calendarYear": "2023",
"period": "Q2",
"revenue": 94836000000,
"costOfRevenue": 52860000000,
"grossProfit": 41976000000,
"grossProfitRatio": 0.4426167278,
"researchAndDevelopmentExpenses": 7457000000,
"generalAndAdministrativeExpenses": 0,
"sellingAndMarketingExpenses": 0,
"sellingGeneralAndAdministrativeExpenses": 6201000000,
"otherExpenses": 64000000,
"operatingExpenses": 13658000000,
"costAndExpenses": 66518000000,
"interestIncome": 918000000,
"interestExpense": 930000000,
"depreciationAndAmortization": 2898000000,
"ebitda": 31216000000,
"ebitdaratio": 0.3291577038,
"operatingIncome": 28318000000,
"operatingIncomeRatio": 0.2985996879,
"totalOtherIncomeExpensesNet": 64000000,
"incomeBeforeTax": 28382000000,
"incomeBeforeTaxRatio": 0.2992745371,
"incomeTaxExpense": 4222000000,
"netIncome": 24160000000,
"netIncomeRatio": 0.2547555781,
"eps": 1.53,
"epsdiluted": 1.52,
"weightedAverageShsOut": 15787154000,
"weightedAverageShsOutDil": 15847050000,
"link": "https://www.sec.gov/Archives/edgar/data/320193/000032019323000064/0000320193-23-000064-index.htm",
"finalLink": "https://www.sec.gov/Archives/edgar/data/320193/000032019323000064/aapl-20230401.htm"
}
As you can see, this is one day in the 2nd Quarter which is why you don't see any data for Q1 2023. This is a difficult one to fix so any suggestions please let me know. Of course I could deduct one day for Apple but I want to look for something that works in all cases. Any ideas?
EDIT: it could very well be that I can just deduct 1 day of all of them and it still works since 2023-01-31 minus 1 day is still Q1. Does seem to fix it, I'll keep you posted. It opens another issue, why is there no data on Q3 2023? 🤔
@JerBouma Hm, I hadn't noticed Apple had such an "off" fiscal year. I guess your fix will work in this particular case, but since Apple uses such strange periods it may occur on the 2nd or 3rd of a month as well, breaking your suggested fix.
I think it also causes the missing Q3 data. The date for that is 2023-07-01 when looking at https://financialmodelingprep.com/api/v3/balance-sheet-statement/AAPL?period=quarter&apikey=XX, so if you apply your suggested fix and deduct 1 from that as well, it ends up in Q2?
Perhaps you can create the appropriate date from the "calendarYear" and "period" values?
Q3 2023 of Apple is actually the period April to June 2023 which is Q2 in the calendar. So deducting 1 day also works in this case. E.g. if you look at the values they actually match up with what was reporting a couple of months ago. I'll test it on a few more companies and will let you know once the fix is in. The "date" column of Apple from FinancialModelingPrep seems to be unrelated to the actual date of the Press Release which is why I am optimistic this method will work.
The missing Q3 2023 data (which is Q4 2023 for Apple) is because the Press Release was released today and it takes a day or two for FinancialModelingPrep to parse the data.
This has been resolved, please update to v1.6.0: https://github.com/JerBouma/FinanceToolkit/releases/tag/v1.6.0