Created
May 16, 2018 19:46
-
-
Save jukujala/504548ead7f0296d36a3501e801f4519 to your computer and use it in GitHub Desktop.
calculate annualised return R on financial investment that has returned 11% over 28 monthly investements of $1
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
import numpy as np | |
from scipy.optimize import minimize_scalar | |
def moneyh(R): | |
""" save 1$ every month for 28 month | |
Args: | |
R: annualised yearly interest rate | |
Returns: | |
how much you have at the end of 28 month | |
""" | |
moneys = np.sum([np.exp(R*t/12) for t in range(0, 28)]) | |
return moneys | |
def loss(R): | |
""" minimise loss, semi got 11% return | |
""" | |
return np.power(moneyh(R)-1.11*28, 2) | |
res = minimize_scalar(loss) | |
# >>> res.x | |
# 0.091093940594436429 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment