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

[WIP] [Feature] Financial cashflow forecast #2674

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

nsulzer
Copy link

@nsulzer nsulzer commented Apr 27, 2024

Attempt to contribute to #2673 to continue the conversation and get some feedback.

Most of it is based on on #2126, with the addition of forecast based on past averages, and a move to Recahrts. Average spending is based on the average of the relevant month in past years (so the June projection is the average of all June's). If there is no data, it will take the average of all available months.

I am extremely open to feedback. I hope this can help move the discussion along and work towards something good :)

mk-french and others added 16 commits December 26, 2023 09:30
Missed a few things in the rebase.
Cater for transfers, account filtering and off-budget accounts.
- Refactored some of the date handling to minimise changes to existing code and fix some edge case bugs when months don't have 31 days.
- Added a feature flag
Non repeating schedules store their dates differently to the repeating kind. Add the date directly instead of using the 'get-occurrances...' function.
- Make isConcise dependent on forecast length as well
- Style line and bars based on isFuture
- Remove explicit future data keys from graph
- Map graphData per date
- Separate stacked bars for future and past
- Separate labels for past and future
- Dummy average source
- Minor visual fix on buttons
- Minor formatting
- Exclude current incomplete month
- Calculcate average of all months to fill in data
- Account for this month's spending in forecast amont for this month
- Filter out starting balance
@trafico-bot trafico-bot bot added the 🚧 WIP Still work-in-progress, please don't review and don't merge label Apr 27, 2024
Copy link

netlify bot commented Apr 27, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit b0d1944
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/66316c77bce60200084e49af
😎 Deploy Preview https://deploy-preview-2674.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Apr 27, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 4.67 MB → 4.69 MB (+20.19 kB) +0.42%
Changeset
File Δ Size
node_modules/date-fns/esm/max/index.js 🆕 +1.36 kB 0 B → 1.36 kB
src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx 📈 +9.01 kB (+143.48%) 6.28 kB → 15.29 kB
src/components/reports/graphs/CashFlowGraph.tsx 📈 +5.22 kB (+113.54%) 4.59 kB → 9.81 kB
src/components/reports/Header.jsx 📈 +2.29 kB (+50.26%) 4.55 kB → 6.84 kB
src/components/reports/reports/CashFlow.tsx 📈 +1.87 kB (+28.42%) 6.58 kB → 8.45 kB
src/hooks/useFeatureFlag.ts 📈 +27 B (+7.24%) 373 B → 400 B
src/components/settings/Experimental.tsx 📈 +151 B (+4.86%) 3.04 kB → 3.18 kB
src/style/themes/development.ts 📈 +70 B (+0.98%) 6.95 kB → 7.02 kB
src/style/themes/dark.ts 📈 +70 B (+0.98%) 7 kB → 7.07 kB
src/style/themes/light.ts 📈 +70 B (+0.97%) 7.08 kB → 7.14 kB
src/style/themes/midnight.ts 📈 +66 B (+0.95%) 6.76 kB → 6.82 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.2 MB → 1.22 MB (+19.74 kB) +1.61%
static/js/index.js 2.99 MB → 2.99 MB (+454 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 59.68 kB 0%
static/js/usePreviewTransactions.js 790 B 0%
static/js/AppliedFilters.js 20.41 kB 0%
static/js/wide.js 263.53 kB 0%

Copy link
Contributor

github-actions bot commented Apr 27, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.2 MB → 1.2 MB (+232 B) +0.02%
Changeset
File Δ Size
packages/loot-core/src/server/schedules/app.ts 📈 +503 B (+2.90%) 16.95 kB → 17.44 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.2 MB → 1.2 MB (+232 B) +0.02%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@Teprifer
Copy link

Average spending is based on the average of the relevant month in past years (so the June projection is the average of all June's). If there is no data, it will take the average of all available months.

I'd like to suggest this is limited to the past 1 or 2 Junes, using myself as example, I used Actual before it went free, and imported nYNAB data, I have a number of years of data (back to 2017) and so averaging all those Junes will generate an number not as representative as it could be. I think moving with the last 1 or 2 years is better as personal circumstances change.

Likewise others have imported years of data from nYNAB and YNAB4.

I lean towards just the last year for my personal circumstances to reflect changes, but see using the last 2 as perfectly valid as well

Got an error when trying to add a filter:

  1. Settings: image

(Same error occurred when using the Average Spending Option)

  1. Add category filter per: image

  2. Result:
    image

image

Also recommend checking all the other filter options for the same.

@mk-french
Copy link
Contributor

This is great! Thanks for picking it up and contributing! I lost a bit of steam and never really pushed it any further after the PR was closed... The community seemed a little divided on how it should work and with the change in graphing library, I never found the time/motivation.

I did extend it to also use the budget as a source, very similar to how you've done it, see: mk-french@9b2a73c but I hadn't pushed it before the PR was closed.

If I get a moment, I'll try merge it with your changes here. Also I think there may have been a few bugs fixed along the way...

I also echo the issue of including too many years in the past. When testing, my August forecast expense has blown out because of a house purchase from many years back! 😂
Maybe months with expenses detected as outliers compared to other years could be excluded at a minimum?

There's lot's of work to be done around the filtering, as some of the filtering options don't make sense in some contexts...

@glowtape
Copy link

I suppose you can't run two filters? One for the current cashflow graph as-is, and another for the forecast based on average spending? Say if I would have had extraordinary expenses that I want in the cashflow graph, but not show in the forecast.

- Query schedules/transactions only when relevant
- Exclude impossible schedule filters
- Fix divide by 0 when averaging.
@nsulzer
Copy link
Author

nsulzer commented Apr 30, 2024

Hi all, thank you for the testing and suggestions :)

The point of wanting to limit the number of past years considered is a good one. I have (I hope, though I still struggle to test this) added the option to limit the number of years. That may be a bit overkill, but I think we might as well add features until it becomes clear what sticks.

As to the filtering errors, they should be resolved. However, the filtering options for schedules are limited to account and payee, while date (speaking of filtering options that don't make sense in context...) and amount should be possible as well.

Then to better forecasting, I like both of these ideas.

  • I suppose you can't run two filters? One for the current cashflow graph as-is, and another for the forecast based on average spending? Say if I would have had extraordinary expenses that I want in the cashflow graph, but not show in the forecast.

    We're already running separate queries, so a separate filter is definitely possible. It would just require a separate filter selection UI for the forecast.

  • Maybe months with expenses detected as outliers compared to other years could be excluded at a minimum?

    Perhaps instead of removing the outlier month, filtering outlying transaction values using above suggestion might be sufficient. The heuristics around classifying an outlier might be difficult to nail down.

In the trend of throwing features at the wall to see what sticks, I'll definitely have a go at implementing separate filtering for the forecast. If that doesn't adequately deal with outliers, well... we'll see.

There's lot's of work to be done around the filtering, as some of the filtering options don't make sense in some contexts...

Definitely, do you have any concrete examples?

@Teprifer
Copy link

Teprifer commented May 1, 2024

Hi!

I think the average x years isn't working, I have a big lump sum I made in February and so I'd expect the curve to change a lot if I use more years than 1.
This is may a good way to test too, just have a mega large transaction in a month that is just outside the 1 year point. Then changing between 2 years and 1 should be very obvious.
I think it may be sufficient to have a drop down to set of buttons for 1 year, 2 year, 3 year, and All Time?

Can see the forecast line looks the same regardless of 1 or 10 years and the big drop in February to affect numbers that more years would have smoothed out

image
image

Extreme example, all time history, max forecast:

image
image

Regarding filtering, instead of having two sets of filters, maybe instead(if you think it's a good idea, technically doable, etc etc.) might be to simply reset the filters when changing between Average Spending and Schedules (optional toast window to let them know). Then the filter options list itself could be filtered for only what makes sense for each option.

I can kinda see a case for having a different filter list that only applies to the forecasted portion, but even done this way, I think resetting them when changing options is a clean simple way to avoid breakages with incompatible filters and communicate to the user the different availability

In terms of editing the filtering list, Carkom did this in #2622 so if you want to(ideally) filter the filter list options based on which forecast is option is used it might help you. :)

@glowtape
Copy link

glowtape commented May 5, 2024

See for instance this month November, the expenses are lower than normal and the income is lacking:

image

If I had to guess, since it's beginning of May right now, your code adds six months to the beginning of November, but doesn't round up to the end of the interval, and gets all schedules only until November 5th (it's May 5th posting this).

Comment on lines +163 to +165
$transform: '$month',
$lte: monthUtils.prevMonth(end),
$gt: monthUtils.subMonths(end, forecastDivideYears * 12),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how to contribute to your PR (I can't push to your branch in your repo due to permissions) but you need to split these into seperate objects and combine them with an $and operator.
#2674 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nsulzer , I have the above fix and also the budget source merged in and ready to push. I've created a PR to your branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚧 WIP Still work-in-progress, please don't review and don't merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants