Created
July 8, 2020 21:29
-
-
Save nvladimus/277ab9b397b0b96306d750ac8462ec5b to your computer and use it in GitHub Desktop.
MOOC: Finance for non-finance professionals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Week 1: Financial Valuation Discounting\n", | |
"### Compound interest rate \n", | |
"* can be calculated annually or on smaller periods\n", | |
"* $ FutureValue = PresentValue (1 + r)^N$, where $r$ is the interest rate, $N$ is the number of periods.\n", | |
"* the correct way of calculating monthly rate from yearly rate is $r_m = (r_y)^{1/12}$, but a simpler formula of $r_y/12$ is sometimes also used." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1628.894626777441\n" | |
] | |
} | |
], | |
"source": [ | |
"# example: Compound interest of bank deposit\n", | |
"s = 1000.\n", | |
"n_years = 10\n", | |
"rate_yearly = 0.05\n", | |
"for i in range(n_years):\n", | |
" s += s*(rate_yearly)\n", | |
" \n", | |
"print(s)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Discounted cash flow (DCF)\n", | |
"How much a future cash flow costs now, at a given interest rate $r$?\n", | |
"- one-time payment in future: $PresentValue = FutureValue / (1+r\\%)^N$, N is number of years (months, quarters)\n", | |
"- multiple periodic payments: $PresentValue = \\sum_1^N \\frac{CF_i}{(1+r\\%)^i}$, where $CF_i$ are future cash flows.\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1038.2693939108303" | |
] | |
}, | |
"execution_count": 36, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# example: DCF of bond price\n", | |
"coupon = 50\n", | |
"rate = 0.03\n", | |
"principal = 1000\n", | |
"n_years = 2\n", | |
"\n", | |
"s = 0\n", | |
"for i in range(1, n_years+1):\n", | |
" if i == n_years:\n", | |
" s += (principal + coupon)/(1 + rate)**i\n", | |
" else:\n", | |
" s += coupon/(1 + rate)**i\n", | |
"s" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Week 2: Capital budgeting\n", | |
"### Net Present Value (NPV)\n", | |
"* NPV = - IniCost + $\\sum \\frac{CF_i}{(1+r\\%)^i}$, where $CF_i$ are future cash flows.\n", | |
"* is NPV > 0?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"361.6240146852392" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ini = 1000\n", | |
"cf = np.array([500, 500, 500])\n", | |
"rate = 0.05\n", | |
"r_i = np.array([(1 + rate)**(i+1) for i in range(len(cf))])\n", | |
"npv = -ini + (cf/r_i).sum()\n", | |
"npv" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Payback period\n", | |
"- its the time period when IniCost becomes =$\\sum \\frac{CF_i}{(1+r\\%)^i}$\n", | |
"- a weaker budgeting tool than NVP, few pros and many cons." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"2.352 years\n" | |
] | |
} | |
], | |
"source": [ | |
"# example of payback period calculation (fractional 3. year)\n", | |
"ini = 2000\n", | |
"cf = np.array([1000, 1000, 1000])\n", | |
"rate = 0.1\n", | |
"r_i = np.array([(1 + rate)**(i+1) for i in range(len(cf))])\n", | |
"t_payback = len(cf) - ((cf/r_i).sum() - ini)/(cf[-1]/r_i[-1])\n", | |
"print(f\"{t_payback:2.3f} years\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"... to be continued" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:py36]", | |
"language": "python", | |
"name": "conda-env-py36-py" | |
}, | |
"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.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment