Skip to content

Instantly share code, notes, and snippets.

@bicubic
Created May 12, 2013 04:17
Show Gist options
  • Save bicubic/5562401 to your computer and use it in GitHub Desktop.
Save bicubic/5562401 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "Finance"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Question 1"
},
{
"cell_type": "code",
"collapsed": false,
"input": "rate = 0.04\nperiods = 12\nmath.pow(1 + rate / periods, periods) - 1",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "pyout",
"prompt_number": 115,
"text": "0.040741542919790596"
}
],
"prompt_number": 115
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Question 2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "We can apply tax before or after discounting, it doesn't matter because the tax rate is constant\n\nOption 1 will give us exactly 500k after tax, lets see what option 2 gives"
},
{
"cell_type": "code",
"collapsed": false,
"input": "tax = 0.5\ninterest = 0.03\nop2 = np.array([120000] * 10) * tax\nnpv(interest, op2)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "pyout",
"prompt_number": 123,
"text": "511812.17020654969"
}
],
"prompt_number": 123
},
{
"cell_type": "markdown",
"metadata": {},
"source": "So the NPV of option 2 is 512k. This is the better option"
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Question 3"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Numpy makes question 3 trivial, just give it the cash flows"
},
{
"cell_type": "code",
"collapsed": false,
"input": "project1 = [-50, 18, 18, 18, 18]\nproject2 = [-75, 26, 26, 26, 26]\n\nprint np.irr(project1), np.irr(project2)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "0.163674891689 0.144911895394\n"
}
],
"prompt_number": 128
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Question 4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Question 4 is very badly worded. My answer was to simply calculate the NPV of each given stream"
},
{
"cell_type": "code",
"collapsed": false,
"input": "project1 = [-50, 18, 18, 18, 18]\nproject2 = [-75, 26, 26, 26, 26]\nrate = 0.1\nprint np.npv(rate, project1), np.npv(rate, project2)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "6.41598003117 6.74227418644\n"
}
],
"prompt_number": 130
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Turns out when they say year 1, they actually mean year 0, so the initial cash outflows are **immediate**. What they really mean is this"
},
{
"cell_type": "code",
"collapsed": false,
"input": "project1 = [18, 18, 18, 18]\nproject2 = [26, 26, 26, 26]\nrate = 0.1\nprint np.npv(rate, project1) - 50, np.npv(rate, project2) - 75",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "7.05757803429 7.41650160508\n"
}
],
"prompt_number": 132
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment