Skip to content
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

Stock prices must be adjusted for splits in DB #1624

Open
zachgoll opened this issue Jan 16, 2025 · 0 comments
Open

Stock prices must be adjusted for splits in DB #1624

zachgoll opened this issue Jan 16, 2025 · 0 comments
Labels
💡 Improvement Improvements to an existing feature or flow

Comments

@zachgoll
Copy link
Collaborator

zachgoll commented Jan 16, 2025

Breaking this out into a new issue for clarity, but this is highly related to #1615 and could be implemented alongside it.

In the Maybe app, we fetch stock prices from a stock price provider (currently Synth, but could be any). The Maybe app's assumption is that whatever provider we fetch from will present us with stock prices adjusted for stock splits. This is industry-standard and how most (or all) stock APIs work.

How Maybe stores prices

For net worth calculations, graphs, and other metrics, Maybe must have stock prices loaded to the DB in order to efficiently join the tables, combine results, and report them.

Because of this, it is required that we store stock prices in the database (and preload as #1615 describes).

Issue: Cached prices don't reflect new splits

Given the following scenario:

  1. Maybe fetches stock XYZ, and loads 2 years of historical prices
  2. A month passes, Maybe continues to load in new daily rates
  3. Stock XYZ has a 2:1 split
  4. Maybe continues fetching daily prices

In this scenario, Maybe is incorrectly presenting all historical prices prior to the split. For example, a price 1 year ago would need to be divided by 2 to adjust it for the split.

The table below shows an example of how splits affect price, and illustrates how Maybe's DB becomes "stale" for a given stock after a split:

Year Unadjusted Price Stock Split Adjusted Price Formula
2010 $10.00 $2.50 =10/2/2
2011 $11.00 $2.75 =11/2/2
2012 $12.00 $3.00 =12/2/2
2013 $6.00 2:1 $3.00 =6/2
2014 $7.00 $3.50 =7/2
2015 $8.00 $4.00 =8/2
2016 $9.00 $4.50 =9/2
2017 $10.00 $5.00 =10/2
2018 $12.00 $6.00 =12/2
2019 $15.00 $7.50 =15/2
2020 $20.00 $10.00 =20/2
2021 $10.00 2:1 $10.00 =10
2022 $11.00 $11.00 =11
2023 $12.00 $12.00 =12
2024 $14.00 $14.00 =14
2025 $19.00 $19.00 =19

Solution: Refresh mechanism

Either periodically, or when alerted of a split, Maybe will need to refresh the entire history of a stock's prices. This ensures that we're consistently reporting results based on adjusted stock prices from the provider, not just the cached prices that have become stale in the Maybe DB.

@zachgoll zachgoll added the 💡 Improvement Improvements to an existing feature or flow label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Improvement Improvements to an existing feature or flow
Projects
None yet
Development

No branches or pull requests

1 participant