{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Finance Calculator Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Welcome to the **FinanceCalculator2025** package documentation! **FinanceCalculator2025** is a Python package that can be used for calculating financial metrics specifically for loans and investment scenarios. This package is a convenient tool for managing personal finances, offering 4 useful functions: **`present_value`**, **`future_value`**, **`n_periods`**, and **`calculate_contribution`**."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Meet Tommy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy is a middle-aged family man juggling work, raising kids, and managing household responsibilities. Recently, he's realized he needs to take his financial planning more seriously if he wants to secure a comfortable future for himself and his family. With some loans to pay off, a growing list of goals, and a desire to save more, Tommy is looking for practical tools that can help him make smarter financial decisions. \n",
"Enter **FinanceCalculator2025** — a simple, easy-to-use Python package designed to help people like Tommy take control of their finances. Whether he's planning for his retirement, saving for a dream family vacation, or just trying to understand how much he needs to set aside each month, **FinanceCalculator2025** is here to guide him through the process. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tommy's Financial Goals"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy currently has **$151,000** dollars in his savings account. Each month, after all living expenses have been paid off, he has **$2,000** left over that he wants to use to start achieving his goals. Using the **FinanceCalculator2025** package, we will walk Tommy through the following steps: \n",
"1. **Buying a Home**: Tommy can use the `present_value` function to estimate how much funds he needs to put away today in order to buy a home in 10 years.\n",
"2. **Retirement**: Tommy can use the `future_value` function to calculate how much he can save for retirement.\n",
"3. **Car Loan**: Tommy can use the `calculate_contribution` function to calculate how much he needs to contribute monthly to pay off his car loan.\n",
"4. **Family Vacation**: Tommy can use the `n_periods` function to calculate how long it will take him to save up for a dream family vacation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To get started, lets import the `financecalculator2025` package and functions:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"import financecalculator2025\n",
"from financecalculator2025.present_value import present_value\n",
"from financecalculator2025.future_value import future_value\n",
"from financecalculator2025.contribution import calculate_contribution\n",
"from financecalculator2025.n_periods import n_periods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **present_value()**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Buying a Home"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy dreams of buying a house in the next 10 years. He decides to set aside **$50,000** of his savings, and will contribute **$500** per month towards this goal, with an annual interest rate of **4%**, compounded monthly."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the `present_value` function, Tommy can estimate how much his savings will grow at the end of 10 years, considering his monthly contributions and interest earned over time."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Input Parameters:\n",
"1. **Current Savings (`principal`)**: $50,000\n",
"2. **Annual Interest Rate (`annual_rate`)**: 4% (provided by the bank)\n",
"3. **Total Number of Periods (`n_periods`)**: 120 months (10 years * 12 months)\n",
"4. **Monthly Contribution (`contribution`)**: 500 (monthly saving from Tommy’s budget)\n",
"\n",
"Tommy runs the following calculation in Python:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Present Value | \n",
" Principal | \n",
" Contributions | \n",
" Interest Saved | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 99385.087429 | \n",
" 50000 | \n",
" 60000 | \n",
" 39385.087429 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Present Value Principal Contributions Interest Saved\n",
"0 99385.087429 50000 60000 39385.087429"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from financecalculator2025.present_value import present_value\n",
"\n",
"principal = 50000 # current saving for education\n",
"annual_rate = 4 # Annual interest rate in percentage\n",
"n_periods = 10 * 12 # Time period (in months)\n",
"contribution = 500 # Monthly contribution\n",
"\n",
"present_value(principal, annual_rate, n_periods, contribution)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Under the current plan, Tommy's initial savings, in addition to his interest earned on monthly contributions will be worth **$99,385.09**! This, combined with his $500 contributions over 10 years will hopefully be enough for a downpayment on a home (although it may not be if he lives in Vancouver!)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***Note**: The `annual_rate` input parameter should be entered in percentage form i.e. enter 4 for 4%. If you enter a low interest rate (less than 1), `FinanceCalculator2025` will return a warning so Tommy can make sure he entered the correct inputs. For example, if Tommy input `annual_rate = 0.04` he would recieve this warning:*"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/meagangardner/git/DSCI_524/financecalculator/src/financecalculator2025/present_value.py:69: UserWarning: Warning: Annual rate is percentage. E.g. if you want to enter 0.05 for 5%, please enter 5.\n",
" warnings.warn(\"Warning: Annual rate is percentage. E.g. if you want to enter 0.05 for 5%, please enter 5.\", UserWarning)\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Present Value | \n",
" Principal | \n",
" Contributions | \n",
" Interest Saved | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 109879.163854 | \n",
" 50000 | \n",
" 60000 | \n",
" 49879.163854 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Present Value Principal Contributions Interest Saved\n",
"0 109879.163854 50000 60000 49879.163854"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"present_value(principal=50000, annual_rate=0.04, n_periods=120, contribution=500)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After contributing towards the house, Tommy still has **$101,000** left in his savings and **$1,500** remaining for his monthly savings. Let's see how else Tommy can manage his finances! \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **future_value()**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Retirement"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On top of buying a home, Tommy also wants to ensure he has enough funds saved up for a comfortable retirement. The `future_value` function can help him calculate how much his current savings will grow over time. Tommy thinks he should start by setting aside **$75,000**. He hopes to retire in **25 years**, and he also decides he should contribute **$900** dollars each month to go towards this goal. The bank will give him an average annual interest rate of **6%**, compounded monthly. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Input Parameters:\n",
"1. **Current Savings (`principal`)**: $75,000\n",
"2. **Annual Interest Rate (`annual_rate`)**: 6% (provided by the bank)\n",
"3. **Total Number of Periods (`n_periods`)**: 300 months (25 years * 12 months)\n",
"4. **Monthly Contribution (`contribution`)**: 900 (monthly saving from Tommy’s budget)\n",
"\n",
"Tommy runs the following calculation in Python:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Future Value | \n",
" Principal | \n",
" Contributions | \n",
" Interest Earned | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 958567.3 | \n",
" 75000 | \n",
" 270000 | \n",
" 613567.3 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Future Value Principal Contributions Interest Earned\n",
"0 958567.3 75000 270000 613567.3"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from financecalculator2025.future_value import future_value\n",
"\n",
"principal = 75000 # Current savings\n",
"annual_rate = 6 # Annual interest rate in percentage\n",
"n_periods = 12*25 # time period (in months)\n",
"contribution = 900 # Monthly contribution\n",
"\n",
"future_value(principal, annual_rate, n_periods, contribution)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy will be able to save a total of $958,567.30 dollars by the time of his retirement! This is such a relief for Tommy, he's so glad he started planning now!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **calculate_contribution()**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Car Loan"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy recently purchased a car and took out a loan of **$25,000.** The loan has an annual interest rate of **6%** (compounded monthly) and must be repaid in **5 years.** Tommy wants to figure out how much he needs to contribute each month to fully repay the loan by the end of the term. The `calculate_contribution` function allows for adjustments in terms, rates, and goals, making it useful for diverse financial planning scenarios!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Input Parameters:\n",
"1. **Loan Value (`principal`)**: $-25,000\n",
"2. **Future Value (`future_value`):** $0 (To pay off the entire loan)\n",
"3. **Annual Interest Rate (`annual_rate`)**: 6% (provided by the bank)\n",
"4. **Total Number of Periods (`n_periods`)**: 60 months (5 years * 12 months)\n",
"\n",
"Tommy runs the following calculation in Python:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"483.32003823570676"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from financecalculator2025.contribution import calculate_contribution\n",
"\n",
"principal = -25000 # Loan amount (negative value)\n",
"future_value = 0 # Goal is to pay off the loan completely\n",
"annual_rate = 6 # Annual interest rate in percentage\n",
"n_periods = 5 * 12 # Loan term (in months)\n",
"\n",
"calculate_contribution(principal, future_value, annual_rate, n_periods)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To fully repay his car loan in 5 years, Tommy will need to make monthly payments of **$483.32**. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***Note**: The `principal` input parameter for a loan is entered as a negative value to represent amount owed.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **n_periods()**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Family Vacation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tommy is feeling so relieved that he has enough in savings and after monthly expenses to save for a home, retirement, and pay off his car loan! He still has a little extra money left over that he wants to put aside to save for a family vacation. He hopes to have **$2,000** saved over the next **2 years**. Given he still has $1,000 left in his savings, if sets aside $100 per month, and a **5%** interest rate compounded monthly, he wonders how long it will take him to save for this dream vacation. Using the `n_periods` function, Tommy can input his principal amount, annual interest rate, future value, and monthly contributions to determine how long he needs to save."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Input Parameters:\n",
"1. **Current Savings (`principal`)**: $1,000\n",
"2. **Annual Interest Rate (`annual_rate`)**: 5% (provided by the bank)\n",
"3. **Savings Goal (`n_periods`)**: $2,000\n",
"5. **Monthly Contribution (`contribution`)**: 100 (monthly saving from Tommy’s budget)\n",
"\n",
"Tommy runs the following calculation in Python:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tommy needs to save for 9 months to reach his goal.\n"
]
}
],
"source": [
"from financecalculator2025.n_periods import n_periods\n",
"\n",
"principal = 1000 # Current savings\n",
"annual_rate = 5 # Annual interest rate in percentage\n",
"future_value = 2000 # Savings goal\n",
"contribution = 100 # Monthly contribution\n",
"\n",
"# Calculate the number of periods (months)\n",
"months = n_periods(principal, annual_rate, future_value, contribution)\n",
"\n",
"print(f\"Tommy needs to save for {months} months to reach his goal.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This means Tommy can reach his $2,000 goal in just 9 months if he consistently saves $100 per month! The interest from the bank helps him achieve his goal even faster."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Final Remarks"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We hope you found these examples useful, and see how the `FinanceCalculator2025` package can help you realize your financial goals, just like Tommy! If you would like to explore our package further, please refer to the documentation or checkout the packages github repository [here](https://github.com/UBC-MDS/FinanceCalculator)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}