# Canada Tax-Free Savings Account simulator (JavaScript)

The rules regarding TFSA contributions, withdrawals, and penalties can be confusing. Here I provide a neat way to learn using a financial account simulator. (Rules and examples are explained below.)

## Program

## Usage

Press “Deposit” to add the specified amount of money to the chequing account.

Press “Withdraw” to subtract the specified amount of money from the chequing account. It must be no greater than the current chequing account balance.

Press “Transfer in” to move the specified amount of money from the chequing account to the tax-free savings account. It must be no greater than the current chequing account balance. This decreases the TFSA contribution room by the amount.

Press “Transfer out” to move the specified amount of money from the tax-free savings account to the chequing account. It must be no greater than the current tax-free savings account balance. The effect is that it first brings a negative contribution room closer to zero (if applicable), and then it increases the current year’s total withdrawn amount.

Press “Next month” to advance to the next month. Interest is paid to the TFSA at the specified interest rate based on the balance at the end of the month. If at any point in the month the contribution room was negative, then 1% of the maximum excess contribution during the month will be taxed to the chequing account. On January of each year, the contribution room increases by $5000 (years 2009, 2010, 2011, 2012) or $5500 (2013, 2014, 2016, 2017, 2018) or $10000 (2015) or $6000 (2019), plus the total amount withdrawn during the previous year (excluding “qualifying” withdrawal amounts to remedy a negative contribution room).

## Example scenarios

Alice is a millionaire and stuffs her TFSA each year as fully as allowed:

- Current date is January 2009.
- Interest rate is 3%.
- Deposit $1000000.
- Transfer in $5000.
- Next month ×12.
- She has $5152.08 in her TFSA at the beginning of January 2010.
- Transfer in $5000.
- Next month ×12.
- She has $10460.86 in her TFSA at the beginning of January 2011.
- Transfer in $5000.
- Next month ×12.
- She has $15931.12 in her TFSA at the beginning of January 2012.
- Transfer in $5000.
- Next month ×12.
- She has $21567.76 in her TFSA at the beginning of January 2013.
- Transfer in $5500.
- Next month ×12.
- She has $27891.05 in her TFSA at the beginning of January 2014.
- Transfer in $5500.
- Next month ×12.
- She has $34406.69 in her TFSA at the beginning of January 2015.
- Note that she contributed $31000 in total to her TFSA; the other $3406.69 was earned as tax-free interest.

Bob saves some money and spends it later:

- Current date is January 2009.
- Interest rate is 3%.
- Deposit $5000.
- Transfer in $5000.
- Next month ×6.
- Transfer out $3000.
- Note that the contribution room is still $0. He cannot contribute more without penalty.
- Next month ×6.
- Now in January 2010, the contribution room rises by $8000: A new $5000 amount plus the $3000 that he withdrew.
- Deposit $1000.
- Transfer in $4000.
- Next month ×3.
- Transfer out $4000.
- Next month ×3.
- Transfer in $4000. (He has enough contribution room.)

Carol makes a mistake of over-contributing and neglects it:

- Current date is January 2009.
- Interest rate is 3%.
- Deposit $10000.
- Transfer in $7000.
- Next month ×12. Each month she pays 1% tax on the $2000 excess contribution, which is $20 per month.
- In January 2010, the excess contribution is absorbed into the new contribution room, so she stops paying penalties.

Dave over-contributes but quickly corrects his mistake:

- Current date is January 2009.
- Interest rate is 3%.
- Deposit $10000.
- Transfer in $6000. (Contribution room −$1000.)
- Transfer in $500. (Contribution room −$1500.)
- Transfer out $1500. (Contribution room $0.)
- Next month. He pays 1% tax on the high water mark of January 2009, which is $1500 of excess contribution.
- Starting this month (February 2009), as long as things stay the same, he will not pay a penalty tax anymore.

## Notes

The simulation assumes that the person is at least 18 years of age in January 2009. (Contribution room only starts accumulating in year 2009 or the year the person turns 18, whichever is later.)

The rules are accurate as of the last update date. The contribution room added in years 2009–2019 are accurate, whereas future years are based on the assumption that current laws don’t change. It’s also unclear if the TFSA will ever be discontinued to increase tax revenue.

Chequing accounts have low (e.g. $0.01 per month on a $1000 balance) or no interest in practice, so this is excluded from the simulation.

In reality, the penalty tax is not charged to a chequing account after each month. Instead, it is recorded by the CRA throughout the calendar year, notified to the person sometime after the end of the year, and a “TFSA return” must be filed and paid by June 30th.

For simplicity, the case of a person having multiple TFSAs is not simulated. But to show how it works, we simply need a transaction log and balances per account, but the contribution room and the amount-withdrawn-this-year are global variables (per person, not per account).

Any amounts spent within the TFSA, such as account fees and trade commissions, are lost forever. They are never added to the amounts withdrawn or the contribution room.

Currently, the only way to reset the date and account transactions is to reload the web page.

The arithmetic and money flow in this simulation may seem easy, but handling such accounts in real life is nontrivial. This is because in reality, some variables are hard to access (e.g. contribution room) or even not directly available to the person (total-withdrawn-this-year, qualifying withdrawal amounts for reducing over-contribution); the person should keep track of these amounts themselves instead of relying on the bank or CRA. Furthermore, the feedback time for an action is measured in days (e.g. bank transactions), months (accumulation of TFSA penalty taxes), or years (increase in contribution room). The simulation, on the other hand, gives instant feedback and exposes all the hidden state variables, which help tremendously in understanding the financial situation.

The program source code is available for viewing.