Skip to content

cache behaves incorrectly, ignores period parameter #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
verbal opened this issue Apr 3, 2025 · 0 comments
Closed

cache behaves incorrectly, ignores period parameter #207

verbal opened this issue Apr 3, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@verbal
Copy link

verbal commented Apr 3, 2025

I think I found 2 problems with the cache

  1. cache will return any data thats less than the end_date even if its period parameter asked for something else.
>>> from tools import api
>>> [(m.report_period, m.period) for m in api.get_financial_metrics('TSLA', end_date='2025-04-03', period='annual')]
[('2024-12-31', 'annual'), ('2023-12-31', 'annual'), ('2022-12-31', 'annual'), ('2021-12-31', 'annual'), ('2020-12-31', 'annual'), ('2019-12-31', 'annual'), ('2018-12-31', 'annual'), ('2017-12-31', 'annual'), ('2016-12-31', 'annual'), ('2015-12-31', 'annual')]
>>> [(m.report_period, m.period) for m in api.get_financial_metrics('TSLA', end_date='2025-04-03', period='quarterly')]
[('2024-12-31', 'annual'), ('2023-12-31', 'annual'), ('2022-12-31', 'annual'), ('2021-12-31', 'annual'), ('2020-12-31', 'annual'), ('2019-12-31', 'annual'), ('2018-12-31', 'annual'), ('2017-12-31', 'annual'), ('2016-12-31', 'annual'), ('2015-12-31', 'annual')]

Since the first call asked for the period to be annual, thats the data stored in the cache. If I execute the call again asking for quarterly results, it will just get the annual results from the cache and return those instead.

  1. cache only merges on report_period, ignoring differences between ttm and quarterly results

If the first issue was fixed by knowing that different keys (report_period) will be returned by using period annual and quarterly/ttm, it will expose this second issue. For some api calls such as tools.api.get_financial_metrics, the call supports annual, ttm, and quarterly values for the period param. If you choose ttm or quarterly, the report_period will be the same, but the values will be different, so they need to be cached separately.

>>> [(m.report_period, m.revenue_growth) for m in api.get_financial_metrics('TSLA', end_date='2025-04-03', period='quarterly')]
[('2024-12-31', 0.020848224922563736), ('2024-09-30', -0.012470588235294117), ('2024-06-30', 0.1971268954509178), ('2024-03-31', -0.15361385941908054), ('2023-12-31', 0.07781584582441113), ('2023-09-30', -0.06326473302041963), ('2023-06-30', 0.06849843542372155), ('2023-03-31', -0.0406694629492557), ('2022-12-31', 0.13349491936235666), ('2022-09-30', 0.2669186252509744)]
>>> [(m.report_period, m.revenue_growth) for m in api.get_financial_metrics('TSLA', end_date='2025-04-03', period='ttm')]
[('2024-12-31', 0.0055584148224395264), ('2024-09-30', 0.019219874525273295), ('2024-06-30', 0.006047812549474906), ('2024-03-31', -0.020956258460521012), ('2023-12-31', 0.008850756849172262), ('2023-09-30', 0.020164206406602287), ('2023-06-30', 0.09290405067705004), ('2023-03-31', 0.05613660356976259), ('2022-12-31', 0.0881476831011314), ('2022-09-30', 0.11459667093469911)]

I think the solution is to take the period param into account when caching results.

@verbal verbal added the bug Something isn't working label Apr 3, 2025
@verbal verbal changed the title cache behaves incorrectly, ignores period cache behaves incorrectly, ignores period parameter Apr 3, 2025
Repository owner deleted a comment Jun 2, 2025
@virattt virattt closed this as completed Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants