Example #1
0
def pmt(*args):
    rate, nper, pv = args[0], args[1], args[2]
    return scipy.pmt(rate, nper, pv)
Example #2
0
### manipulate matrix col and row
np.std(x, axis=1) ##std by col
x.sum()
x.sum(axis=0) ##sum by row
### simulation
ret = np.array(range(1, 100), float)/100 ##create a grid of return pct
rand_50 = np.random.rand(50) ##50 rand num btw 0 and 1
rnorm_100 = np.random.normal(size=100)


## 2. Scipy ------------
### Compute the NPV of a Cashflow
cf = [-100, 50, 40, 20, 10, 50]
sp.npv(rate=0.1, values=cf)
### Monthly payment: APR = 0.045, compounded monthly, mortgage = 250k, T=30yrs
sp.pmt(rate=0.045/12, nper=12*30, pv=250000)
### PV of one future cf
sp.pv(rate=0.1,nper=5,pmt=0,fv=100)
### PV of Annuity (series of payments)
sp.pv(rate=0.1, nper=5, pmt=100)
### Geometric mean returns
def geoMeanreturn(ret):
    return pow(sp.prod(ret+1), 1./len(ret)) - 1
ret = np.array([0.1, 0.05, -0.02])
geoMeanreturn(ret)
### other fundamental stuff
sp.unique([1,1,2,3,4,1,1,1])
sp.median([1,1,2,3,4,1,1,1])


## 3. matplotlib ------------
Example #3
0
'''
The  sp.pmt() function is used to answer the following question: What is the monthly
cash flow to pay off a mortgage of $250,000 over 30 years with an annual percentage
rate (APR) of 4.5 percent, compounded monthly?
'''
import scipy as sp
'''
贷款:200'000.00
年利率:5%
还款周期:月
贷款年限:3年
每月还款:5'994.18
'''
payment2 = sp.pmt(0.05 / 12, 3 * 12, 200000, fv=0, when='end')
print(payment2)
Example #4
0
'''
The  sp.pmt() function is used to answer the following question: What is the monthly
cash flow to pay off a mortgage of $250,000 over 30 years with an annual percentage
rate (APR) of 4.5 percent, compounded monthly?
'''
import scipy as sp

'''
贷款:200'000.00
年利率:5%
还款周期:月
贷款年限:3年
每月还款:5'994.18
'''
payment2 = sp.pmt(0.05/12,3*12,200000,fv=0,when='end')
print (payment2)
Example #5
0
import scipy as sp

n = float(raw_input('N = '))
iy = float(raw_input('I/Y = '))
pv = float(raw_input('PV = '))
pmt = float(raw_input('PMT = '))
fv = float(raw_input('FV = '))
sol = raw_input('Solve for (n,iy,pv,pmt,fv): ')

if sol == "n":
    print("N = %f" % sp.nper(iy, pmt, pv, fv))
if sol == "iy":
    print("I/Y = %f" % sp.rate(n, pmt, pv, fv))
if sol == "pv":
    print("PV = %f" % sp.pv(iy, n, pmt, fv))
if sol == "pmt":
    print("PMT = %f" % sp.pmt(iy, n, pv, fv))
if sol == "fv":
    print("FV = %f" % sp.fv(iy, n, pmt, pv))
'''
print 'N = %f, ' % n
print 'I/Y = %f, ' % iy
print 'PV = %f, ' % pv
print 'PMT = %f, ' % pmt
print 'FV = %f, ' % fv
'''
import numpy.lib.financial as fin

# signature of fv fucntion is (Rate,nper(number of years),pmnt (payment),pv(present value), when='end' )
# the following is for rate = %10, one year, 0 payment and $100 principle 
futVal_1 = fin.fv(0.1,1,0,100)
help(fin.fv)
futVal_2 = fin.fv(0.1,5,0,100)

'''
Here is an example. John is planning to buy a used car with a price tag of $5,000. 
Assume that he would pay $1,000 as the down payment and borrow the rest. 
The annual interest rate for a car load is 1.9% compounded monthly. 
What is his monthly payment if he plans to retire his load in three years? 
We could calculate the monthly payment manually; see the following code:
'''

# manual calculation
r=0.019/12
pv=4000
n=3*12
pymnt = pv*r/(1-1/(1+r)**n)

pymntPermonth = 200

# Using scipy 
sp.pmt(r,n,pv)
sp.rate(n,pymntPermonth,-pv,0) 
round(sp.nper(r,-pymntPermonth,-pv,0))
fin.pmt(r,n,pv)
fin.rate(n,pymntPermonth,-pv,0)
Example #7
0
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import scipy as sp
>>> sp.fv(.0025,25,0,5000)
-5322.057184363162
>>> import scipy as sp
>>> sp.pv(.0541/2,20,55,0,1)
-863.7816463604273
>>> import scipy as sp
>>> sp.pmt(.0312,5,2400)
-525.8478442817194
>>>