def calc_compounding ( _rate, _periods, _principal, _contribution, _delta, _inflation ) :
	in_rate = 0.01 * _rate
	in_delta   = 0.01 * _delta
	in_contrib = -1* _contribution
	in_princ   = -1* _principal
	in_inflation = 0.01* inflation
	print("rate %g, periods %g, principal %g, contribution %g, delta %g, inflation %g" %( _rate, _periods, in_princ, in_contrib, _delta, _inflation))
	cf1 = np.array([round(np.fv(in_rate, i, in_contrib, in_princ, when='end'),2) for i in range(1,periods+1)])
	cf2 = np.array([round(np.fv((in_rate-in_delta), i, in_contrib, in_princ, when='end'),2) for i in range(1,periods+1)])
	if _inflation == 0:
		return(np.subtract(cf1,cf2))
	else:
		diff = np.subtract(cf1,cf2)
		return np.array([round(np.pv(in_inflation, i, 0, (-1*diff[i])),2)  for i in range(_periods)])
Beispiel #2
0
def portfolio_return_calc(age, investment, risk_portfolio, investor):
    portfolio_attr = []
    portfolio_list = Portfolio.objects.filter(name=risk_portfolio)
    stock_list = Investment.objects.filter(portfolios__name=risk_portfolio)
    stock_name = []
    stock_info_list = []
    for stock in stock_list:
        stock_name.append(stock.name)
        stock_description = {
            'name': stock.name,
            'info': stock.description}
        stock_info_list.append(stock_description)
    for portfolio in portfolio_list:
        portfolio_attr.append(portfolio.name)
        portfolio_attr.append(portfolio.expected_return)
    inv_return = numpy.fv((float(portfolio_attr[1]) / 12), ((65 - (int(age))) * 12), -(int(investment)), -investment)
    investment_return = '{:20,.2f}'.format(float(inv_return))
    inv_rt = '{:.20}'.format(inv_return)
    data2 = {'stocksp': {'stock1p': 25, 'stock2p': 25, 'stock3p': 20, 'stock4p': 20, 'stock5p': 10},
             'stocksn': {'stock1n': stock_name[0], 'stock2n': stock_name[1], 'stock3n': stock_name[2],
                         'stock4n': stock_name[3], 'stock5n': stock_name[4]},
             'portfolio': portfolio_attr[0],
             'expected': portfolio_attr[1],
             'return': investment_return, 'stock_list': stock_info_list}
    investor.portfolio_name = risk_portfolio
    investor.expected_return = inv_rt
    investor.save()
    return data2
Beispiel #3
0
def demo_age_calc(age):
    percent_month = (float(4000) * .70)
    investment_month = (float(4000) - float(percent_month))
    inv_return = numpy.fv((.058 / 12), ((65 - (int(age))) * 12), -(int(investment_month)), -investment_month)
    investment_return = '{:20,.2f}'.format(float(inv_return))
    vistior_age = {'investment': investment_month, 'age': age, 'return': investment_return,
                   "percent_mon": percent_month}
    return vistior_age
Beispiel #4
0
 def fuli(self):
     d1 = [np.fv(0.2, i, -1.4, -1.4) for i in range(1, 40)]
     # print(d1)
     d2 = [np.fv(0.15, i, -1.4, -1.4) for i in range(1, 40)]
     d3 = [np.fv(0.1, i, -1.4, -1.4) for i in range(1, 40)]
     d4 = [np.fv(0.05, i, -1.4, -1.4) for i in range(1, 40)]
     df = pd.DataFrame(columns=['d1','d2','d3','d4'])
     df['d1']=d1
     df['d2']=d2
     df['d3']=d3
     df['d4']=d4
     #print(df.tail())
     #df.plot()
     #plt.show()
     #
     #plt.savefig('data/fv1.png')
     #self.plot_style(df)
     self.style_color(df)
Beispiel #5
0
    def test_when(self):
        # begin
        assert_almost_equal(np.rate(10, 20, -3500, 10000, 1), np.rate(10, 20, -3500, 10000, "begin"), 4)
        # end
        assert_almost_equal(np.rate(10, 20, -3500, 10000), np.rate(10, 20, -3500, 10000, "end"), 4)
        assert_almost_equal(np.rate(10, 20, -3500, 10000, 0), np.rate(10, 20, -3500, 10000, "end"), 4)

        # begin
        assert_almost_equal(np.pv(0.07, 20, 12000, 0, 1), np.pv(0.07, 20, 12000, 0, "begin"), 2)
        # end
        assert_almost_equal(np.pv(0.07, 20, 12000, 0), np.pv(0.07, 20, 12000, 0, "end"), 2)
        assert_almost_equal(np.pv(0.07, 20, 12000, 0, 0), np.pv(0.07, 20, 12000, 0, "end"), 2)

        # begin
        assert_almost_equal(np.fv(0.075, 20, -2000, 0, 1), np.fv(0.075, 20, -2000, 0, "begin"), 4)
        # end
        assert_almost_equal(np.fv(0.075, 20, -2000, 0), np.fv(0.075, 20, -2000, 0, "end"), 4)
        assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0), np.fv(0.075, 20, -2000, 0, "end"), 4)

        # begin
        assert_almost_equal(np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, 1), np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, "begin"), 4)
        # end
        assert_almost_equal(np.pmt(0.08 / 12, 5 * 12, 15000.0, 0), np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, "end"), 4)
        assert_almost_equal(np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, 0), np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, "end"), 4)

        # begin
        assert_almost_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 1), np.ppmt(0.1 / 12, 1, 60, 55000, 0, "begin"), 4)
        # end
        assert_almost_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0), np.ppmt(0.1 / 12, 1, 60, 55000, 0, "end"), 4)
        assert_almost_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 0), np.ppmt(0.1 / 12, 1, 60, 55000, 0, "end"), 4)

        # begin
        assert_almost_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 1), np.ipmt(0.1 / 12, 1, 24, 2000, 0, "begin"), 4)
        # end
        assert_almost_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0), np.ipmt(0.1 / 12, 1, 24, 2000, 0, "end"), 4)
        assert_almost_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 0), np.ipmt(0.1 / 12, 1, 24, 2000, 0, "end"), 4)

        # begin
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000.0, 1), np.nper(0.075, -2000, 0, 100000.0, "begin"), 4)
        # end
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000.0), np.nper(0.075, -2000, 0, 100000.0, "end"), 4)
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000.0, 0), np.nper(0.075, -2000, 0, 100000.0, "end"), 4)
Näide 1
Mis on tulevikuväärtus 100€ alginvesteeringu korral 10 aasta pärast, kui
aastane intressimäär on 3.5% ning me lisame igal kuu alguses (lõpus)
investeeringule 100€?
------------------------------------------------------------------------------
"""

print("Näide 1\n-------\n")

RATE = 0.035 / 12  # 3.5% aastas, 3.5%/12 perioodis
PERIOD = 10*12  # 10 aastat
PAYMENT = -100  # maksame 100€ kuus, '-' tähendab raha väljavoolu
PRESENT_VALUE = -100  # alginvesteering 100€, '-' tähendab raha väljavoolu

FV_1 = np.fv(RATE, PERIOD, PAYMENT, PRESENT_VALUE, when='end')
FV_2 = np.fv(RATE, PERIOD, PAYMENT, PRESENT_VALUE, when='begin')

print("Kuu lõpus makstes koguneb 10 aastaga %.2f€." % FV_1)
print("Kuu alguses makstes koguneb 10 aastaga %.2f€." % FV_2)

"""
Sisestades intressimäära järjendina, saame võrrelda erinevate
määrade korral saadavaid tulemusi.
"""

RATES = np.array([0.02, 0.03, 0.035, 0.04, 0.045])
FUTURE_VALUES = np.fv(RATES/12, PERIOD, PAYMENT, PRESENT_VALUE, when='end')
for rate, fv in zip(RATES, FUTURE_VALUES):
    print("Intressimäära {0:.1f}% korral on tulevikuväärtus {1:.2f}€."
          .format(rate*100, fv)
import numpy as np
from matplotlib.pyplot import plot, show

print "Future value", np.fv(0.03/4, 5 * 4, -10, -1000)

fvals = []

for i in xrange(1, 10):
   fvals.append(np.fv(.03/4, i * 4, -10, -1000))

plot(fvals, 'bo')
show()
Beispiel #8
0
def generate_price_df(ticker,financialreportingdf,stockpricedf,discountrate,marginrate):
	dfprice = pd.DataFrame(columns =['ticker','annualgrowthrate','lasteps','futureeps'])
	#print(financialreportingdf)
	pd.options.display.float_format = '{:20,.2f}'.format



	# Find EPS Annual Compounded Growth Rate
	# annualgrowthrate =  financialreportingdf.epsgrowth.mean() #growth rate

	try:

		#print(financialreportingdf.eps.iloc[0])
		#print(financialreportingdf.eps.iloc[-1])
		annualgrowthrate =  np.rate(5, 0, -1*financialreportingdf.eps.iloc[0], financialreportingdf.eps.iloc[-1])
		#print(annualgrowthrate)

		# Non Conservative
		lasteps = financialreportingdf.eps.tail(1).values[0] #presentvalue

		# conservative
		# lasteps = financialreportingdf.eps.mean()

		years  = 10 #period
		futureeps = abs(np.fv(annualgrowthrate,years,0,lasteps))
		#print(futureeps,annualgrowthrate,lasteps)
		dfprice.loc[0] = [ticker,annualgrowthrate,lasteps,futureeps]
	except:
		print('eps does not exist')

	dfprice.set_index('ticker',inplace=True)



	#conservative
	dfprice['peratio'] = findMinimumEPS(stockpricedf,financialreportingdf)

	dfprice['FV'] = dfprice['futureeps']*dfprice['peratio']

	#print(dfprice[['futureeps','peratio' ]])

	dfprice['PV'] = abs(np.pv(discountrate,years,0,fv=dfprice['FV']))

	if dfprice['FV'].values[0] > 0:
		dfprice['marginprice'] = dfprice['PV']*(1-marginrate)
	else:
		dfprice['marginprice'] = 0

	dfprice['lastshareprice']=stockpricedf.close.head(1).values[0]
	dfprice['lastshareprice'] = pd.to_numeric(dfprice['lastshareprice'], errors='coerce')

	difference = dfprice['marginprice'] - dfprice['lastshareprice']

	if difference[0] < -30:
		dfprice['decision'] = 'SELL'
	elif difference[0] < 30 and  difference[0] >= -30:
		dfprice['decision'] = 'HOLD'
	elif difference[0] >= 30:
		dfprice['decision'] = 'BUY'

	return dfprice
Beispiel #9
0
import numpy as np

print(np.fv(0.05 / 12, 10 * 12, -100, -100))
'''
numpy.fv(rate, nper, pmt, pv[, when='end'])
#参数:
rate:每一期的利率(rate of interest)。数值或矩阵(M, )。
nper:期数。
pmt:payment。
pv:present value,现值。
when:{{‘begin’, 1}, {‘end’, 0}}, {string, int}, optional.
'''
Beispiel #10
0
 def test_fv(self):
     assert_equal(np.fv(0.075, 20, -2000, 0, 0), 86609.362673042924)
Beispiel #11
0
def sta001(k, nyear, xd):
    return round(np.fv(k, nyear, -xd, -xd))
Beispiel #12
0
print u"金融函数"
# fv函数计算所谓的终值(future value),即基于一些假设给出的某个金融资产在未来某一
# 时间点的价值。
# pv函数计算现值(present value),即金融资产当前的价值。
# npv函数返回的是净现值(net present value),即按折现率计算的净现金流之和。
# pmt函数根据本金和利率计算每期需支付的金额。
# irr函数计算内部收益率(internal rate of return)。内部收益率是是净现值为0时的有效利
# 率,不考虑通胀因素。
# mirr函数计算修正后内部收益率(modified internal rate of return),是内部收益率的改进
# 版本。
# nper函数计算定期付款的期数。
# rate函数计算利率(rate of interest)。
print u"终值"
#fv函数参数为利率,参数,每期支付金额,现值
print "Future value",np.fv(0.03/4, 5*4,-10,1000)
print u"现值"
#pv函数参数为利率,参数,每期支付金额,终值
print "Present value",np.pv(0.03/4,5*4,-10,1376.09633204)
#npv参数为利率和一个表示现金流的数组.
cashflows = np.random.randint(100,size=5)
cashflows = np.insert(cashflows,0,-100)
print "Cashflows",cashflows
print "Net present value",np.npv(0.03,cashflows)
print u"内部收益率"
print "Internal rate of return",np.irr([-100, 38, 48,90 ,17,36])

print u"分期付款"
#pmt输入为利率和期数,总价,输出每期钱数
print "Payment",np.pmt(0.10/12,12*30,100000)
#nper参数为贷款利率,固定的月供和贷款额,输出付款期数
Beispiel #13
0
import numpy as np

np.fv(0.05 / 12, 10 * 12, -100, -100)
a = np.array((0.05, 0.06, 0.07)) / 12
np.fv(a, 10 * 12, -100, -100)
# @version : Python3.6
# @Time    : 2017/4/25 15:07
# @Author  : Jianyang-Hu
# @contact : [email protected]
# @File    : finfunc_0425.py
# @Software: PyCharm
"""
fv终值
pv现值
npv净现值
pmt利息
irr内部收益率
mirr修正后neibushouyil
nper期数
rate利率
"""

import numpy as np
from numpy import *
from matplotlib.pyplot import plot, show

print("Future value", np.fv(0.03 / 4, 5 * 4, -10, -1000))

fvales = []
for i in range(1, 20):
    fvales.append(np.fv(0.03 / 4, i * 4, -10, -1000))

plot(fvales, "bo")
show()

print("Present value:", np.pv(0.03 / 4, 5 * 4, -10, 1376.09633204))
Beispiel #15
0
#!/usr/bin/python

import numpy

print "Future value", numpy.fv(0.03/4, 5 * 4, -10, -1000)
Beispiel #16
0
 def test_fv_decimal(self):
     assert_equal(
         np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), 0, 0),
         Decimal('86609.36267304300040536731624'))
Beispiel #17
0
#!/usr/bin/python3
# !coding=utf-8
'''
金融计算
'''

import numpy as np
# 终值 = np.fv(利率, 期数, 每期支付, 现值)
# 将1000元以1%的年利率存入银行5年,每年加存100元,
# 到期后本息合计多少钱?
fv = np.fv(0.01, 5, -100, -1000)
print(round(fv, 2))
# 现值 = np.pv(利率, 期数, 每期支付, 终值)
# 将多少钱以1%的年利率存入银行5年,每年加存100元,
# 到期后本息合计fv元?
pv = np.pv(0.01, 5, -100, fv)
print(pv)
# 净现值 = np.npv(利率, 现金流)
# 将1000元以1%的年利率存入银行5年,每年加存100元,
# 相当于一次性存入多少钱?
npv = np.npv(0.01, [-1000, -100, -100, -100, -100, -100])
print(round(npv, 2))
fv = np.fv(0.01, 5, 0, npv)
print(round(fv, 2))
# 内部收益率 = np.irr(现金流)
# 将1000元存入银行5年,以后逐年提现100元、200元、
# 300元、400元、500元,银行利率达到多少,可在最后
# 一次提现后偿清全部本息,即净现值为0元?
irr = np.irr([-1000, 100, 200, 300, 400, 500])
print(round(irr, 2))
npv = np.npv(irr, [-1000, 100, 200, 300, 400, 500])
Beispiel #18
0
def sta001(k, nyear, xd):
    d2 = np.fv(k, nyear, -xd, -xd)
    d2 = round(d2)
    # print(nyear,d2)
    return d2
Beispiel #19
0
import numpy as np

a = np.fv(0.06 / 12, 12 * 5, 5000, 0, when='end')

print(5000 * 36)
print(a)
Beispiel #20
0
    def test_when(self):
        # begin
        assert_equal(np.rate(10, 20, -3500, 10000, 1),
                     np.rate(10, 20, -3500, 10000, 'begin'))
        # end
        assert_equal(np.rate(10, 20, -3500, 10000),
                     np.rate(10, 20, -3500, 10000, 'end'))
        assert_equal(np.rate(10, 20, -3500, 10000, 0),
                     np.rate(10, 20, -3500, 10000, 'end'))

        # begin
        assert_equal(np.pv(0.07, 20, 12000, 0, 1),
                     np.pv(0.07, 20, 12000, 0, 'begin'))
        # end
        assert_equal(np.pv(0.07, 20, 12000, 0),
                     np.pv(0.07, 20, 12000, 0, 'end'))
        assert_equal(np.pv(0.07, 20, 12000, 0, 0),
                     np.pv(0.07, 20, 12000, 0, 'end'))

        # begin
        assert_equal(np.fv(0.075, 20, -2000, 0, 1),
                     np.fv(0.075, 20, -2000, 0, 'begin'))
        # end
        assert_equal(np.fv(0.075, 20, -2000, 0),
                     np.fv(0.075, 20, -2000, 0, 'end'))
        assert_equal(np.fv(0.075, 20, -2000, 0, 0),
                     np.fv(0.075, 20, -2000, 0, 'end'))

        # begin
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0, 1),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'begin'))
        # end
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'end'))
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0, 0),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'end'))

        # begin
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 1),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'begin'))
        # end
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'end'))
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 0),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'end'))

        # begin
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 1),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'begin'))
        # end
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'end'))
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 0),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'end'))

        # begin
        assert_equal(np.nper(0.075, -2000, 0, 100000., 1),
                     np.nper(0.075, -2000, 0, 100000., 'begin'))
        # end
        assert_equal(np.nper(0.075, -2000, 0, 100000.),
                     np.nper(0.075, -2000, 0, 100000., 'end'))
        assert_equal(np.nper(0.075, -2000, 0, 100000., 0),
                     np.nper(0.075, -2000, 0, 100000., 'end'))
Beispiel #21
0
 def test_fv(self):
     assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0), 86609.36, 2)
Beispiel #22
0
# Anual rate (4.5%) to month
rate = (4.5 / 100) / 12
# Number of periods (15 years) to month
nper = 15 * 12
# Monthly investment ($200) out of cash payment
pmt = -200
# Present Value ($50.227,88)
pv = -50227.88
# When will be made the investment each Month
# 'begin' = 1 , 'end' = 0
when = 'begin'

# The result represent the future amound that will be receive after 15 years
# if today is invested the PV (-$50.000), with an investment of $200 at the
# begining of each month
fv = np.fv(rate, nper, pmt, pv, when)
print('FV: {fvv:,.2f}$'.format(fvv=fv))
# As it is an return of investment the result is positive ($149.553)

# Future Value
# Anual rate (5%) to month
rate = (5 / 100) / 12
# Number of periods (10 years) to month
nper = 10 * 12
# Monthly investment ($100) out of cash payment
pmt = -100
# Present Value ($100)
pv = -100
# When will be made the investment each Month
# 'begin' = 1 , 'end' = 0
when = 'end'
@author: ESAccount24
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 26 11:34:21 2015

@author: ESAccount24
"""
#financial institutions
import numpy as np
import scipy.optimize as sp
def myfnc(x):
    return np.pv(x,2,0,125.44)+100.0
    
futval=np.fv(0.12,2,0,-100.0)
print futval
prval=np.pv(0.12,2,0,125.44)
print prval

nperiods=np.nper(0.12,0,-100.0,125.44)
print nperiods

intrate=np.rate(2,0,-100,125.44)
print intrate

initialRateGuess=0.134

#goalseek
#find interest rate that satisfies euqation connecting pv, fv, and nper
print sp.fsolve(myfnc,initialRateGuess)
Beispiel #24
0
    def test_when(self):
        # begin
        assert_equal(np.rate(10, 20, -3500, 10000, 1),
                     np.rate(10, 20, -3500, 10000, 'begin'))
        # end
        assert_equal(np.rate(10, 20, -3500, 10000),
                     np.rate(10, 20, -3500, 10000, 'end'))
        assert_equal(np.rate(10, 20, -3500, 10000, 0),
                     np.rate(10, 20, -3500, 10000, 'end'))

        # begin
        assert_equal(np.pv(0.07, 20, 12000, 0, 1),
                     np.pv(0.07, 20, 12000, 0, 'begin'))
        # end
        assert_equal(np.pv(0.07, 20, 12000, 0), np.pv(0.07, 20, 12000, 0,
                                                      'end'))
        assert_equal(np.pv(0.07, 20, 12000, 0, 0),
                     np.pv(0.07, 20, 12000, 0, 'end'))

        # begin
        assert_equal(np.fv(0.075, 20, -2000, 0, 1),
                     np.fv(0.075, 20, -2000, 0, 'begin'))
        # end
        assert_equal(np.fv(0.075, 20, -2000, 0),
                     np.fv(0.075, 20, -2000, 0, 'end'))
        assert_equal(np.fv(0.075, 20, -2000, 0, 0),
                     np.fv(0.075, 20, -2000, 0, 'end'))

        # begin
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0, 1),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'begin'))
        # end
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'end'))
        assert_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0, 0),
                     np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'end'))

        # begin
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 1),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'begin'))
        # end
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'end'))
        assert_equal(np.ppmt(0.1 / 12, 1, 60, 55000, 0, 0),
                     np.ppmt(0.1 / 12, 1, 60, 55000, 0, 'end'))

        # begin
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 1),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'begin'))
        # end
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'end'))
        assert_equal(np.ipmt(0.1 / 12, 1, 24, 2000, 0, 0),
                     np.ipmt(0.1 / 12, 1, 24, 2000, 0, 'end'))

        # begin
        assert_equal(np.nper(0.075, -2000, 0, 100000., 1),
                     np.nper(0.075, -2000, 0, 100000., 'begin'))
        # end
        assert_equal(np.nper(0.075, -2000, 0, 100000.),
                     np.nper(0.075, -2000, 0, 100000., 'end'))
        assert_equal(np.nper(0.075, -2000, 0, 100000., 0),
                     np.nper(0.075, -2000, 0, 100000., 'end'))
Beispiel #25
0
def sta001(k, nyear, xd):
    d2 = np.fv(k, nyear, -xd, -xd);
    d2 = round(d2)
    return d2
Beispiel #26
0
    def test_decimal_with_when(self):
        """Test that decimals are still supported if the when argument is passed"""
        # begin
        assert_equal(
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000'), Decimal('1')),
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000'), 'begin'))
        # end
        assert_equal(
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000')),
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000'), 'end'))
        assert_equal(
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000'), Decimal('0')),
            np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'),
                    Decimal('10000'), 'end'))

        # begin
        assert_equal(
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0'), Decimal('1')),
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0'), 'begin'))
        # end
        assert_equal(
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0')),
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0'), 'end'))
        assert_equal(
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0'), Decimal('0')),
            np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'),
                  Decimal('0'), 'end'))

        # begin
        assert_equal(
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0'), Decimal('1')),
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0'), 'begin'))
        # end
        assert_equal(
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0')),
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0'), 'end'))
        assert_equal(
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0'), Decimal('0')),
            np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'),
                  Decimal('0'), 'end'))

        # begin
        assert_equal(
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0'),
                Decimal('1')),
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0'),
                'begin'))
        # end
        assert_equal(
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0')),
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0'),
                'end'))
        assert_equal(
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0'),
                Decimal('0')),
            np.pmt(
                Decimal('0.08') / Decimal('12'),
                Decimal('5') * Decimal('12'), Decimal('15000.'), Decimal('0'),
                'end'))

        # begin
        assert_equal(
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0'), Decimal('1')),
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0'), 'begin'))
        # end
        assert_equal(
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0')),
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0'), 'end'))
        assert_equal(
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0'), Decimal('0')),
            np.ppmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'),
                Decimal('55000'), Decimal('0'), 'end'))

        # begin
        assert_equal(
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0'), Decimal('1')).flat[0],
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0'), 'begin').flat[0])
        # end
        assert_equal(
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0')).flat[0],
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0'), 'end').flat[0])
        assert_equal(
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0'), Decimal('0')).flat[0],
            np.ipmt(
                Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'),
                Decimal('2000'), Decimal('0'), 'end').flat[0])
Beispiel #27
0
    def test_decimal_with_when(self):
        """Test that decimals are still supported if the when argument is passed"""
        # begin
        assert_equal(np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000'), Decimal('1')),
                     np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000'), 'begin'))
        # end
        assert_equal(np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000')),
                     np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000'), 'end'))
        assert_equal(np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000'), Decimal('0')),
                     np.rate(Decimal('10'), Decimal('20'), Decimal('-3500'), Decimal('10000'), 'end'))

        # begin
        assert_equal(np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0'), Decimal('1')),
                     np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0'), 'begin'))
        # end
        assert_equal(np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0')),
                     np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0'), 'end'))
        assert_equal(np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0'), Decimal('0')),
                     np.pv(Decimal('0.07'), Decimal('20'), Decimal('12000'), Decimal('0'), 'end'))

        # begin
        assert_equal(np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0'), Decimal('1')),
                     np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0'), 'begin'))
        # end
        assert_equal(np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0')),
                     np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0'), 'end'))
        assert_equal(np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0'), Decimal('0')),
                     np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), Decimal('0'), 'end'))

        # begin
        assert_equal(np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0'), Decimal('1')),
                     np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0'), 'begin'))
        # end
        assert_equal(np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0')),
                     np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0'), 'end'))
        assert_equal(np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0'), Decimal('0')),
                     np.pmt(Decimal('0.08') / Decimal('12'), Decimal('5') * Decimal('12'), Decimal('15000.'),
                            Decimal('0'), 'end'))

        # begin
        assert_equal(np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0'), Decimal('1')),
                     np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0'), 'begin'))
        # end
        assert_equal(np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0')),
                     np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0'), 'end'))
        assert_equal(np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0'), Decimal('0')),
                     np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000'),
                             Decimal('0'), 'end'))

        # begin
        assert_equal(np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0'), Decimal('1')).flat[0],
                     np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0'), 'begin').flat[0])
        # end
        assert_equal(np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0')).flat[0],
                     np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0'), 'end').flat[0])
        assert_equal(np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0'), Decimal('0')).flat[0],
                     np.ipmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('24'), Decimal('2000'),
                             Decimal('0'), 'end').flat[0])
Beispiel #28
0
 def test_fv(self):
     assert_equal(np.fv(0.075, 20, -2000, 0, 0), 86609.362673042924)
Beispiel #29
0
 def test_fv_decimal(self):
     assert_equal(np.fv(Decimal('0.075'), Decimal('20'), Decimal('-2000'), 0, 0),
                  Decimal('86609.36267304300040536731624'))
Beispiel #30
0
 def test_fv(self):
     assert_almost_equal(np.fv(.10,12,-100,100),1824.59, 2)
 def test_fv(self):
     assert_almost_equal(np.fv(0.075, 20, -2000,0,0),
                         86609.36, 2)
Beispiel #32
0
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 26 11:34:21 2015

@author: ESAccount24
"""
#financial institutions
import numpy as np
import scipy.optimize as sp


def myfnc(x):
    return np.pv(x, 2, 0, 125.44) + 100.0


futval = np.fv(0.12, 2, 0, -100.0)
print futval
prval = np.pv(0.12, 2, 0, 125.44)
print prval

nperiods = np.nper(0.12, 0, -100.0, 125.44)
print nperiods

intrate = np.rate(2, 0, -100, 125.44)
print intrate

initialRateGuess = 0.134

#goalseek
#find interest rate that satisfies euqation connecting pv, fv, and nper
print sp.fsolve(myfnc, initialRateGuess)