This code calculates the average daily balance for each account in your You Need a Budget (YNAB) budget within a specific statement period. The calculation takes into account all transactions that occurred within the specified period and computes the average daily balance.
- Install Node.js if you haven't already.
- Clone the repository or download the code.
- Navigate to the project directory in your terminal/command prompt.
- Run
npm install
to install all necessary dependencies.
- Create an
.env
file in the project directory. - Add your YNAB API key to the
.env
file in the following format:YNAB_API_KEY=your_api_key_here
. - Update the
STATEMENT_PERIOD_END_DAY
constant in the code to reflect the last day of your desired statement period.
- Log in to your YNAB account by visiting app.youneedabudget.com.
- Click on your account name in the lower-left corner of the screen. This will open a menu.
- In the menu, click on
Account Settings
. - Scroll down to the
Developer
section. - Here, you will find your
Personal Access Token
. Click onNew Token
if you don't have one yet or if you want to generate a new one. - A pop-up window will appear. Enter your YNAB account password and click
Generate
to create a new token. - The newly generated token will appear in a text box. Make sure to copy and save it securely, as you won't be able to access it again.
Note: Your YNAB authorization token grants access to your YNAB account data. Keep it secure and never share it with anyone you don't trust.
Run the code by executing node index.js
in the terminal/command prompt. The average daily balance for each account in your YNAB budget will be displayed in the console.
Let's assume you have two accounts in your YNAB budget: "Checking" and "Savings". The statement period is set to end on the 3rd of each month. After running the code, you may see output similar to the following:
Account: Checking
Average Daily Balance: $1,234.56
Account: Savings
Average Daily Balance: $5,678.90
This output indicates that the average daily balance for the "Checking" account within the statement period is $1,234.56, and the average daily balance for the "Savings" account is $5,678.90.