Пример #1
0
def impact_calculator_total(present_value, annual_rate, payments, lump_sum, future_value=0):
    # Calculate the impact (time) in throwing more money at a single debt
    annual_rate /= 12
    t0 = np.nper([annual_rate], [-payments], [present_value], [future_value])
    t1 = np.nper([annual_rate], [-payments], [present_value - lump_sum], [future_value])

    time_saved = t1 - t0
    print('t {} - {} = {}'.format(t1, t0, time_saved))

    impact_rate = ((annual_rate / 12 + 1) ** (t0 * 12)) - 1
    money_saved = impact_rate * lump_sum

    return -round(time_saved[0] * 365/12), round(money_saved[0], 2)
    def test_broadcast(self):
        assert_almost_equal(np.nper(0.075,-2000,0,100000.,[0,1]),
                            [ 21.5449442 ,  20.76156441], 4)

        assert_almost_equal(np.ipmt(0.1/12,list(range(5)), 24, 2000),
                            [-17.29165168, -16.66666667, -16.03647345,
                                -15.40102862, -14.76028842], 4)

        assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000),
                            [-74.998201  , -75.62318601, -76.25337923,
                                -76.88882405, -77.52956425], 4)

        assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000, 0,
            [0,0,1,'end','begin']),
                            [-74.998201  , -75.62318601, -75.62318601,
                                -76.88882405, -76.88882405], 4)
Пример #3
0
    def test_broadcast(self):
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000., [0, 1]),
                            [21.5449442, 20.76156441], 4)

        assert_almost_equal(np.ipmt(0.1 / 12, list(range(5)), 24, 2000), [
            -17.29165168, -16.66666667, -16.03647345, -15.40102862,
            -14.76028842
        ], 4)

        assert_almost_equal(np.ppmt(0.1 / 12, list(range(5)), 24, 2000), [
            -74.998201, -75.62318601, -76.25337923, -76.88882405, -77.52956425
        ], 4)

        assert_almost_equal(
            np.ppmt(0.1 / 12, list(range(5)), 24, 2000, 0,
                    [0, 0, 1, 'end', 'begin']), [
                        -74.998201, -75.62318601, -75.62318601, -76.88882405,
                        -76.88882405
                    ], 4)
Пример #4
0
def loan_schedule(loan, payment=1000, start_date=datetime.now()):
    """
	Create amortization schedule for loan.
	loan: dict or DataFrame with the following keys or columns
		1) name 2) int_rate 3) balance
	payment: float or int, Default 1000
	start_date (optional): datetime object
	"""

    # Initialize variables and dataframe
    schedule = pd.DataFrame()
    num_payments = np.nper(loan['int_rate'] / (100 * 12), -1000,
                           loan['balance'])
    dates = pd.date_range(start=start_date,
                          freq='M',
                          periods=np.ceil(num_payments))
    int_rate, initial_balance = loan['int_rate'] / 100, loan['balance']

    # For each date, calculate interest and principal payment until balance is 0
    for date in dates:
        interest_payment = initial_balance * int_rate / 12
        remaining_balance = initial_balance * (1 + int_rate / 12) - payment
        principal_payment = payment - interest_payment
        if payment > initial_balance + interest_payment:
            principal_payment = initial_balance
            remaining_balance = 0
            payment = principal_payment + interest_payment
        schedule = schedule.append([{
            'Date': date,
            'Initial Balance': initial_balance,
            'Payment': payment,
            'Interest Payment': interest_payment,
            'Principal Payment': principal_payment,
            'Remaining Balance': remaining_balance
        }])
        initial_balance = remaining_balance
    # Insert Loan Information
    schedule.insert(1, 'Name', loan['name'])
    schedule.insert(2, 'Interest Rate', loan['int_rate'])
    # Clean Table
    schedule['Date'] = schedule['Date'].dt.strftime('%m/%d/%Y')
    schedule = schedule.set_index(['Date', 'Name']).round(2).reset_index()
    return schedule
Пример #5
0
def calc_goals(user, roi, total):

    roi = float(roi)
    total = float(total)

    annual_expenses = float(user.expected_annual_expenses)
    add_money = float(user.months_add_money)
    money = float(user.monthly_savings_amt)

    egoal = annual_expenses / roi

    print("end goal:" + str(egoal))  #calculated
    print("estimated annual roi: " + str(roi))  #from assets
    print("additional payments per year: " + str(add_money))
    print("amount added: " + str(money))
    print("curr total: " + str(total))

    #good example here https://xplaind.com/696036/excel-nper-function
    ytg = numpy.nper(roi / 12, money, total, -egoal) / 12

    print("years to goal: {:.2f}".format(ytg))
    return egoal, ytg
Пример #6
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)
Пример #7
0
#按折现率计算的净现金流之和
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)

#内部收益率
#净现值为0时的有效利率
print "Internal rate of return", np.irr(cashflows)

#分期付款
#借30年,年利率为10%. 等额本息
print "Payment:", np.pmt(0.10 / 12, 12 * 30, 1000000)

#计算付款期数
print "Number of payments:", np.nper(0.10 / 12, -100, 9000)

#等额本金计算。麻烦点,每个月要算利息

#窗函数

#巴特利特窗
window = np.bartlett(42)
plt.clf()
plt.plot(window)
plt.savefig('images/bartlett.png', format='png')

#布莱克曼窗
#三项余弦的和: w(n) = 0.42 - 0.5*cos(2*pi*n/M) + 0.08*cos(4*pi*n/M)
#使用布莱克曼窗平滑股价
#用到了卷积。忘了,需要了解下
Пример #8
0
# 净现值 = 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])
print(npv)
# 每期支付 = np.pmt(利率, 期数, 现值)
# 以1%的年利率从银行贷款1000元,分5年还清,
# 平均每年还多少钱?
pmt = np.pmt(0.01, 5, 1000)
print(round(pmt, 2))
# 期数 = np.nper(利率, 每期支付, 现值)
# 以1%的年利率从银行贷款1000元,平均每年还pmt元,
# 多少年还清?
nper = np.nper(0.01, pmt, 1000)
print(int(nper))
# 利率 = np.rate(期数, 每期支付, 现值, 终值)
# 从银行贷款1000元,平均每年还pmt元,nper年还清,
# 年利率多少?
rate = np.rate(nper, pmt, 1000, 0)
print(round(rate, 2))
Пример #9
0
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参数为贷款利率,固定的月供和贷款额,输出付款期数
print "Number of payments", np.nper(0.10/12,-100,9000)
#rate参数为付款期数,每期付款资金,现值和终值计算利率
print "Interest rate",12*np.rate(167,-100,9000,0)

print u"窗函数"
#bartlett函数可以计算巴特利特窗
window = np.bartlett(42)
print "bartlett",window
#blackman函数返回布莱克曼窗。该函数唯一的参数为输出点的数量。如果数量
#为0或小于0,则返回一个空数组。
window = np.blackman(10)
print "blackman",window
# hamming函数返回汉明窗。该函数唯一的参数为输出点的数量。如果数量为0或
# 小于0,则返回一个空数组。
window = np.hamming(42)
print "hamming",window
def single_period(pv, n, rate, fv, pmt):
    n=np.nper(rate/n, pmt, pv, fv, when = 'end')
Пример #11
0
# 存100元, 到期后本息一共多少钱?
# 求金融终值 fv
fv = np.fv(0.01, 5, -100, -1000)
print(fv)

# 将多少钱以1%的年利率存入银行5年, 每年
# 加存100元,到期后本息合计fv元.
# 求金融现值 pv
pv = np.pv(0.01, 5, -100, fv)
print(pv)

# 净现值
# 将1000元以1%的年利率存入银行5年, 每年加存
# 100元, 相当于现在要一次性存入多少钱
npv = np.npv(0.01, [-1000, -100,
                    -100, -100, -100, -100])
print(npv)

# 每期支付
# 以1%的利率从银行贷款1000元, 分5年还清.
# 平均每年还多少钱?
pmt = np.pmt(0.01, 5, 1000)
print(pmt)
pmt = np.pmt(0.0441 / 12, 360, 1000000)
print(pmt)

# 以4.41%/12的利率从银行贷款100万元,
# 平均每期还pmt元, 多少年还清?
nper = np.nper(0.0441 / 12, pmt, 1000000)
print(nper)
Пример #12
0
import numpy as np

print(np.fv(0.02, 20 * 12, -100, -100))
print(np.pv(0.02, 20 * 12, -100, 586032.549))
print(np.npv(0.281, [-100, 823, 59, 55, 20]))
print(np.pmt(0.02 / 12, 20 * 12, 1000000))
print(np.ppmt(0.02 / 12, -100, 20 * 12, 1000000))
print(np.ipmt(0.02 / 12, 0.001, 20 * 12, 200000))
print(round(np.irr([-5, 10.5, 1, -8, 1]), 5))
print(np.mirr([-100, 823, 59, 55, 20], -100, -150))
print(np.nper(0.02, -1e7, 1e8))
print(np.rate(0.7, -1e8, 200000, 0))
Пример #13
0
2举例:某用户去银行存款,假设年利率 3% 、每季度续存金额 10 元、存 5年后可领 1376.0963320,则计算 5年前存取的本金是多 少金额。
'''
print(np.pv(0.03 / 4, 5 * 4, -10, 1376.0963320407982))
'''
np.npv(rate,values)
rate:折现率
values:现金流
03.投资 100,收入39,59,55,20,折现率为28.1% 则净现值为
'''
print(np.npv(0.281, [-100, 39, 59, 55, 20]))
'''
举例:某同学房贷 20 万,准备 15 年还清,利率为 7.5% 7.5% ,则每 月需还贷多少金额?
pmt = np.pmt(0.075/12, 15*12,200000) 计算还款金额
'''
pmt = np.pmt(0.075 / 12, 15 * 12, 200000)
'''
小明房贷 70 万,年利率 4% ,准备还 20 年,
则每月供多少?
'''
pmt1 = np.pmt(0.04 / 12, 20 * 12, 700000)
print("每月需要还款{}元".format(-pmt1))
'''
举例:某同学房贷 20 万,年利率为 7.5% 7.5% ,每月能还贷 2000 ,则 需要还多少期?
np.nper(0.075/12,-2000,200000) 计算还款期数
'''
nper = np.nper(0.075 / 12, -2000, 200000)
month = np.ceil(nper)
year = np.ceil(month / 12)
print("需要还{}年", year)

print((18.5 - 14.30) / 14.30)
Пример #14
0
 def calc_months_to_payoff(self, rate, pmt, closing_balance):
     nper = np.nper(rate/12/100.00, pmt, closing_balance)
     return nper
Пример #15
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, 0, 1),
            np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, "begin"),
        )
        # end
        assert_equal(
            np.pmt(0.08 / 12, 5 * 12, 15000.0, 0),
            np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, "end"),
        )
        assert_equal(
            np.pmt(0.08 / 12, 5 * 12, 15000.0, 0, 0),
            np.pmt(0.08 / 12, 5 * 12, 15000.0, 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.0, 1),
            np.nper(0.075, -2000, 0, 100000.0, "begin"),
        )
        # end
        assert_equal(
            np.nper(0.075, -2000, 0, 100000.0),
            np.nper(0.075, -2000, 0, 100000.0, "end"),
        )
        assert_equal(
            np.nper(0.075, -2000, 0, 100000.0, 0),
            np.nper(0.075, -2000, 0, 100000.0, "end"),
        )
Пример #16
0
 def test_nper(self):
     assert_almost_equal(np.nper(-.01,-100,1000),9.483283066, 3)
Пример #17
0
 def test_nper(self):
     assert_almost_equal(np.nper(0,-100,1000),10)
Пример #18
0
 def test_nper(self):
     assert_almost_equal(np.nper(.05,-100,1000,100,1),14.2067, 3)
Пример #19
0
#==============================================================================
#计算年化利率
Num =240
payment =-3000
PV =500000
FV =0
due = 0 #期末还款
Rate = np.rate(Num,payment,PV,FV,due)
print('年化利率为: %.4f%%' % (100*Rate*12))
#计算周期

rate = 0.038862/12
payment =-4000
PV =500000
FV =0
Periods = np.nper(rate,payment,PV,FV,when='end')
print('周期为:%s' % Periods )

#==============================================================================
# 6.5 按揭贷款分析
#==============================================================================
# 等额还款
def Ajfixpayment(MP,Num,B,rate):
    # MP 月还款额
    # Num 期数
    # B 贷款本金
    # rate 贷款利率
    # 初始化相关变量
    # 初始化行向量,用来存储每次循环的值
    IR = [0] * Num # 月利息
    YE = [0] * Num  # 贷款余额
Пример #20
0
#4
n = 16
g = 0.05
r = 0.1
payment = 540000
A = (1 + g) / (1 + r)
B = A**n
pv = (payment / (r - g)) * (1 - B)  #The growing annuity payment formula
print("Present value of winings is", "{:,.2f}".format(pv))

#5
pmt = -380  #the PMT
i = 0.08  #the interest rate
fv = 25694  #the future value
n = np.nper(rate=i, pmt=pmt, pv=0, fv=fv)  #number of payments function
print("There are", "{:,.0f}".format(n), "payments")

#6
n = 360
I = 0.076 / 12
pmt = -800
pv = np.pv(rate=I, nper=n, pmt=pmt)  #present value of given pmt
ball = 230000 - pv
ballfv = np.fv(nper=n, rate=I, pmt=0, pv=-ball)  #future value of ballpayment
print("The ballpayment should be", "{:,.2f}".format(ballfv))

#7
pmt = 17000
pv = -0.8 * 2800000
n = 30 * 12
 def test_nper(self):
     assert_almost_equal(np.nper(0.075,-2000,0,100000.),
                         21.54, 2)
Пример #22
0
 def test_nper(self):
     assert_almost_equal(np.nper(.05, -100, 1000, 100, 1), 14.2067, 3)
Пример #23
0
def crea_oferta(df_consolidado_info_impacto, periodo_de_gracia, tasa_oferta):

    df_oferta = pd.DataFrame()

    for index, cada_cliente in df_consolidado_info_impacto.iterrows():
        df_oferta.loc[index, "cli_rut"] = int(cada_cliente["cli_rut"])
        df_oferta.loc[index, "ope_tasa"] = tasa_oferta
        df_oferta.loc[index, "ope_tasa_oferta_1"] = tasa_oferta
        df_oferta.loc[index, "ope_tasa_oferta_2"] = tasa_oferta

        monto_temp_o1 = np.ceil(cada_cliente["pago_mensual"]*(1-0.05))
        monto_temp_o2 = np.ceil(cada_cliente["pago_mensual"]*(1-0.3))

        monto_final_credito = cada_cliente["saldo_adeudado_gar_final"]+cada_cliente["saldo_sin_gar_comercial_final"]+cada_cliente["saldo_adeudado_consumo_final"]

        num_cuotas_oferta_1 = np.ceil(np.nper(df_oferta.loc[index, "ope_tasa"], -monto_temp_o1, monto_final_credito))
        num_cuotas_oferta_2 = np.ceil(np.nper(df_oferta.loc[index, "ope_tasa"], -monto_temp_o2, monto_final_credito))

        if num_cuotas_oferta_1 > 84 - periodo_de_gracia:
            num_cuotas_oferta_1 = 84 - periodo_de_gracia

        if num_cuotas_oferta_2 > 84 - periodo_de_gracia:
            num_cuotas_oferta_2 = 84 - periodo_de_gracia

            
        ## OFERTA 1
        df_oferta.loc[index, "num_cuotas_oferta_1"] = num_cuotas_oferta_1
        df_oferta.loc[index, "monto_oferta_1"]      = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_oferta_1, -monto_final_credito))

        ##MONTO CUOTA COMERCIAL
        df_oferta.loc[index, "monto_c_oferta_1"]     = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_oferta_1, -cada_cliente["saldo_sin_gar_comercial_final"]))
        
        
        ##NUMERO DE CUOTAS CONSUMO
        if cada_cliente["num_cuotas_max_k"] == 0:
            num_cuotas_k_1 = num_cuotas_oferta_1
        else:
            if cada_cliente["num_cuotas_max_k"] < num_cuotas_oferta_1:
                num_cuotas_k_1 = cada_cliente["num_cuotas_max_k"]
            else:
                num_cuotas_k_1 = num_cuotas_oferta_1
        ##MONTO CUOTA CONSUMO
        df_oferta.loc[index, "monto_k_oferta_1"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_k_1, -cada_cliente["saldo_adeudado_consumo_final"]))
        df_oferta.loc[index, "num_cuotas_k_1"]   = num_cuotas_k_1
        
        
        ##NUMERO DE CUOTAS SI GAR 1 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_1"] == 0:
            num_cuotas_gar_1_oferta_1 = num_cuotas_oferta_1
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_1"] < num_cuotas_oferta_1:
                num_cuotas_gar_1_oferta_1 = cada_cliente["num_cuotas_max_fogape_gar_1"]
            else:
                num_cuotas_gar_1_oferta_1 = num_cuotas_oferta_1
        ##MONTO CUOTA GAR 1 SI FOGAPE
        df_oferta.loc[index, "monto_gar_1_oferta_1"]     = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_1_oferta_1, -cada_cliente["saldo_adeudado_gar_1_final"]))
        df_oferta.loc[index, "num_cuotas_gar_1_oferta_1"] = num_cuotas_gar_1_oferta_1
        
        
        ##NUMERO DE CUOTAS SI GAR 2 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_2"] == 0:
            num_cuotas_gar_2_oferta_1 = num_cuotas_oferta_1
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_2"] < num_cuotas_oferta_1:
                num_cuotas_gar_2_oferta_1 = cada_cliente["num_cuotas_max_fogape_gar_2"]
            else:
                num_cuotas_gar_2_oferta_1 = num_cuotas_oferta_1
        ##MONTO CUOTA GAR 2 SI FOGAPE
        df_oferta.loc[index, "monto_gar_2_oferta_1"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_2_oferta_1, -cada_cliente["saldo_adeudado_gar_2_final"]))
        df_oferta.loc[index, "num_cuotas_gar_2_oferta_1"] = num_cuotas_gar_2_oferta_1
        
        
        ##NUMERO DE CUOTAS SI GAR 3 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_3"] == 0:
            num_cuotas_gar_3_oferta_1 = num_cuotas_oferta_1
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_3"] < num_cuotas_oferta_1:
                num_cuotas_gar_3_oferta_1 = cada_cliente["num_cuotas_max_fogape_gar_3"]
            else:
                num_cuotas_gar_3_oferta_1 = num_cuotas_oferta_1
        ##MONTO CUOTA GAR 3 SI FOGAPE
        df_oferta.loc[index, "monto_gar_3_oferta_1"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_3_oferta_1, -cada_cliente["saldo_adeudado_gar_3_final"]))
        df_oferta.loc[index, "num_cuotas_gar_3_oferta_1"] = num_cuotas_gar_3_oferta_1
        
        
        ##NUMERO DE CUOTAS SI GAR 4 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_4"] == 0:
            num_cuotas_gar_4_oferta_1 = num_cuotas_oferta_1
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_4"] < num_cuotas_oferta_1:
                num_cuotas_gar_4_oferta_1 = cada_cliente["num_cuotas_max_fogape_gar_4"]
            else:
                num_cuotas_gar_4_oferta_1 = num_cuotas_oferta_1
        ##MONTO CUOTA GAR 4 SI FOGAPE
        df_oferta.loc[index, "monto_gar_4_oferta_1"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_4_oferta_1, -cada_cliente["saldo_adeudado_gar_4_final"]))
        df_oferta.loc[index, "num_cuotas_gar_4_oferta_1"] = num_cuotas_gar_4_oferta_1

        df_oferta.loc[index, "monto_oferta_1"] = df_oferta.loc[index, "monto_c_oferta_1"] + df_oferta.loc[index, "monto_k_oferta_1"] + df_oferta.loc[index, "monto_gar_1_oferta_1"] + df_oferta.loc[index, "monto_gar_2_oferta_1"] + df_oferta.loc[index, "monto_gar_3_oferta_1"] + df_oferta.loc[index, "monto_gar_4_oferta_1"]
        df_oferta.loc[index, "per_rebaja_oferta_1"]    = (1-df_oferta.loc[index, "monto_oferta_1"]/cada_cliente["pago_mensual"])
        df_oferta.loc[index, "total_a_pagar_oferta_1"] = df_oferta.loc[index, "num_cuotas_oferta_1"] * df_oferta.loc[index, "monto_oferta_1"]


        
        ##OFERTA 2
        
        
        df_oferta.loc[index, "num_cuotas_oferta_2"] = num_cuotas_oferta_2
        df_oferta.loc[index, "monto_oferta_2"]      = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_oferta_2, -monto_final_credito))

        ##MONTO CUOTA COMERCIAL
        df_oferta.loc[index, "monto_c_oferta_2"]     = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_oferta_2, -cada_cliente["saldo_sin_gar_comercial_final"]))
        
        
        ##NUMERO DE CUOTAS CONSUMO
        if cada_cliente["num_cuotas_max_k"] == 0:
            num_cuotas_k_2 = num_cuotas_oferta_2
        else:
            if cada_cliente["num_cuotas_max_k"] < num_cuotas_oferta_2:
                num_cuotas_k_2 = cada_cliente["num_cuotas_max_k"]
            else:
                num_cuotas_k_2 = num_cuotas_oferta_2
        ##MONTO CUOTA CONSUMO
        df_oferta.loc[index, "monto_k_oferta_2"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_k_2, -cada_cliente["saldo_adeudado_consumo_final"]))
        df_oferta.loc[index, "num_cuotas_k_2"]   = num_cuotas_k_2
        
        
        ##NUMERO DE CUOTAS SI GAR 1 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_1"] == 0:
            num_cuotas_gar_1_oferta_2 = num_cuotas_oferta_2
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_1"] < num_cuotas_oferta_2:
                num_cuotas_gar_1_oferta_2 = cada_cliente["num_cuotas_max_fogape_gar_1"]
            else:
                num_cuotas_gar_1_oferta_2 = num_cuotas_oferta_2
        ##MONTO CUOTA GAR 1 SI FOGAPE
        df_oferta.loc[index, "monto_gar_1_oferta_2"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_1_oferta_2, -cada_cliente["saldo_adeudado_gar_1_final"]))
        df_oferta.loc[index, "num_cuotas_gar_1_oferta_2"]   = num_cuotas_gar_1_oferta_2
        
        
        ##NUMERO DE CUOTAS SI GAR 2 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_2"] == 0:
            num_cuotas_gar_2_oferta_2 = num_cuotas_oferta_2
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_2"] < num_cuotas_oferta_2:
                num_cuotas_gar_2_oferta_2 = cada_cliente["num_cuotas_max_fogape_gar_2"]
            else:
                num_cuotas_gar_2_oferta_2 = num_cuotas_oferta_2
        ##MONTO CUOTA GAR 2 SI FOGAPE
        df_oferta.loc[index, "monto_gar_2_oferta_2"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_2_oferta_2, -cada_cliente["saldo_adeudado_gar_2_final"]))
        df_oferta.loc[index, "num_cuotas_gar_2_oferta_2"]   = num_cuotas_gar_2_oferta_2
        
        
        ##NUMERO DE CUOTAS SI GAR 3 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_3"] == 0:
            num_cuotas_gar_3_oferta_2 = num_cuotas_oferta_2
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_3"] < num_cuotas_oferta_2:
                num_cuotas_gar_3_oferta_2 = cada_cliente["num_cuotas_max_fogape_gar_3"]
            else:
                num_cuotas_gar_3_oferta_2 = num_cuotas_oferta_2
        ##MONTO CUOTA GAR 3 SI FOGAPE
        df_oferta.loc[index, "monto_gar_3_oferta_2"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_3_oferta_2, -cada_cliente["saldo_adeudado_gar_3_final"]))
        df_oferta.loc[index, "num_cuotas_gar_3_oferta_2"]   = num_cuotas_gar_3_oferta_2
        
        
        ##NUMERO DE CUOTAS SI GAR 4 FOGAPE
        if cada_cliente["num_cuotas_max_fogape_gar_4"] == 0:
            num_cuotas_gar_4_oferta_2 = num_cuotas_oferta_2
        else:
            if cada_cliente["num_cuotas_max_fogape_gar_4"] < num_cuotas_oferta_2:
                num_cuotas_gar_4_oferta_2 = cada_cliente["num_cuotas_max_fogape_gar_4"]
            else:
                num_cuotas_gar_4_oferta_2 = num_cuotas_oferta_2
        ##MONTO CUOTA GAR 4 SI FOGAPE
        df_oferta.loc[index, "monto_gar_4_oferta_2"] = np.ceil(np.pmt(df_oferta.loc[index, "ope_tasa"], num_cuotas_gar_4_oferta_2, -cada_cliente["saldo_adeudado_gar_4_final"]))
        df_oferta.loc[index, "num_cuotas_gar_4_oferta_2"]   = num_cuotas_gar_4_oferta_2

        df_oferta.loc[index, "monto_oferta_2"] = df_oferta.loc[index, "monto_c_oferta_2"] + df_oferta.loc[index, "monto_k_oferta_2"] + df_oferta.loc[index, "monto_gar_1_oferta_2"] + df_oferta.loc[index, "monto_gar_2_oferta_2"] + df_oferta.loc[index, "monto_gar_3_oferta_2"] + df_oferta.loc[index, "monto_gar_4_oferta_2"]
        df_oferta.loc[index, "per_rebaja_oferta_2"]    = (1-df_oferta.loc[index, "monto_oferta_2"]/cada_cliente["pago_mensual"])
        df_oferta.loc[index, "total_a_pagar_oferta_2"] = df_oferta.loc[index, "num_cuotas_oferta_2"] * df_oferta.loc[index, "monto_oferta_2"]

    df_oferta.drop("ope_tasa", axis = 1, inplace = True)
    return df_oferta
@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)
Пример #25
0
 def test_nper(self):
     assert_almost_equal(np.nper(0, -100, 1000), 10)
Пример #26
0
import numpy as np

print
round(np.nper(0.07 / 12, -150, 8000), 5)
np.nper(*(np.ogrid[0.07 / 12: 0.08 / 12: 0.01 / 12,
          -150: -99: 50,
          8000: 9001: 1000]))
Пример #27
0
pv = np.pv(0.03 / 4, 4 * 5, -10, fv)
print 'present value', pv

years = np.linspace(1, 10, 10)
print years
fv_vals = np.fv(0.03 / 4, years * 4, -10, -1000)
pv_vals = np.pv(0.03 / 4, years * 4, -10, fv_vals)
print fv_vals
# print pv_vals
# plt.plot(fv_vals,'bo')
# plt.plot(pv_vals,'ro')
# plt.show()

cashflows = np.random.randint(100, size=5)
cashflows = np.insert(cashflows, 0, -100)
print 'cashflows', cashflows
print 'npv', np.npv(0.03, cashflows)
sum = 0
for i in xrange(len(cashflows)):
    df = (1 + 0.03)**(-1 * i)
    sum += df * cashflows[i]
print sum
print 'irr', np.irr(cashflows)

#分期付款
print 'Payment', np.pmt(0.10 / 12, 12 * 30, 100000)
print 'Number of payments', np.nper(0.1 / 12, -100, 9000)

#rate
print 'Interest rate', 12 * np.rate(167, -100, 9000, 0)
Пример #28
0
 def test_nper(self):
     assert_almost_equal(np.nper(-.01, -100, 1000), 9.483283066, 3)
Пример #29
0
    when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
        When payments are due ('begin' (1) or 'end' (0))

    Notes
    -----
    The number of periods ``nper`` is computed by solving the equation::

     fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate*((1+rate)**nper-1) = 0

    but if ``rate = 0`` then::

     fv + pv + pmt*nper = 0

    Examples
    --------
    If you only had $150/month to pay towards the loan, how long would it take
    to pay-off a loan of $8,000 at 7% annual interest?

    >>> np.nper(0.07/12, -150, 8000)
    64.073348770661852

    So, over 64 months would be required to pay off the loan.

    The same analysis could be done with several different interest rates
    and/or payments and/or total amounts to produce an entire table.

    >>> np.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12,
    ...                    -150   : -99     : 50    ,
    ...                    8000   : 9001    : 1000]))
    array([[[  64.07334877,   74.06368256],
            [ 108.07548412,  127.9902265
        print("\nError: Must be a minimum of 1 year")
    else:
        rate=np.rate(float(time_range)*float(n), float(pmt), float(pv), float(fv))
        print("Rate: "+str(rate))
elif(choice=="3"):
    print("\nEnter values as prompted")
    print("Enter interest rate as decimal")
    pv = input("\nEnter PV: ")
    rate = input("\nEnter rate as decimal: ")
    fv = input("\nEnter FV: ")
    pmt = input("\nEnter Pmt: ")
    time_range = input("\nEnter number of years: ")
    if(float(time_range)==0 or float(time_range)<0):
        print("\nError: Must be a minimum of 1 year")
    else:
        n=np.nper(float(rate), float(pmt), float(pv), float(fv))
        print("Number of Periods: "+str(n))
elif(choice=="4"):
    print("\nEnter values as prompted")
    print("Enter interest rate as decimal")
    n = input("\nEnter times compounded: ")
    rate = input("\nEnter rate as decimal: ")
    fv = input("\nEnter FV: ")
    pv = input("\nEnter PV: ")
    time_range = input("\nEnter number of years: ")
    if(float(time_range)==0 or float(time_range)<0):
        print("\nError: Must be a minimum of 1 year")
    else:
        pmt=np.pmt(float(rate), float(n)/float(time_range), float(pv), float(fv))
        print("Payment: "+str(pmt))
else
Пример #31
0
import numpy as np

print
round(np.nper(0.07 / 12, -150, 8000), 5)
np.nper(*(np.ogrid[0.07 / 12:0.08 / 12:0.01 / 12, -150:-99:50,
                   8000:9001:1000]))
 * when : string 'begin' või 'end', valikultine
   Millal makse sooritama peab (alguses või lõpus)

Näide 3
Kui laenu tagasimakse suurus on 330€ kuus, siis kui kaua kulub 68000€ suuruse
laenu maksmiseks aastase intressimäära 2.8% juures?
------------------------------------------------------------------------------
"""

print("\nNäide 3\n-------\n")

RATE = 0.03 / 12  # 4% aastas, 3.5%/12 kuus
PAYMENT = -330  # maksame 330€ kuus, '-' tähendab raha väljavoolu
PV = 68000  # laenu suurus

PERIOD_COUNT = np.nper(RATE, PAYMENT, PV)
print("{0}€ tasumiseks kulub {1:.2f} kuud ehk {2:.0f} aastat."
      .format(PV, PERIOD_COUNT, PERIOD_COUNT/12)
      )

PAYMENTS = np.arange(300, 350, 10)
PERIOD_COUNTS = np.nper(RATE, -PAYMENTS, PV)
for pmt, period in zip(PAYMENTS, PERIOD_COUNTS):
    print("{0}€ suuruse tagasimaksega kulub {1:.2f} kuud ehk {2:.0f} aastat."
          .format(pmt, period, period/12)
          )

"""
------------------------------------------------------------------------------
rate -- perioodi intressimäära arvutamine
rate(nper, pmt, pv, fv, when='end', guess=0.1, tol=1e-06, maxiter=100)
Пример #33
0
def tvmm(pval=None, fval=None, pmt=None, nrate=None, nper=None, due=0, pyr=1, noprint=True):
    """Computes the missing argument (set to ``None``) in a model relating the
    present value, the future value, the periodic payment, the number of
    compounding periods and the nominal interest rate in a cashflow.

    Args:
        pval (float, list): Present value.
        fval (float, list): Future value.
        pmt (float, list): Periodic payment.
        nrate (float, list): Nominal interest rate per year.
        nper (int, list): Number of compounding periods.
        due (int): When payments are due.
        pyr (int, list): number of periods per year.
        noprint (bool): prints enhanced output

    Returns:
        Argument set to None in the function call.


    **Details**

    The ``tvmmm`` function computes and returns the missing value (``pmt``, ``fval``,
    ``pval``, ``nper``, ``nrate``) in a model relating a finite sequence  of payments
    made at the beginning or at the end of each period, a present value, a future value,
    and a nominal interest rate. The time intervals between consecutive payments are
    assumed to be equal. For internal computations, the effective interest rate per
    period is calculated as ``nrate / pyr``.


    **Examples**

    This example shows how to find different values for a loan of 5000, with a
    monthly payment of 130 at the end of the month, a life of 48 periods, and a
    interest rate of 0.94 per month (equivalent to a nominal interest
    rate of 11.32%). For a loan, the future value is 0.

    * Monthly payments: Note that the parameter ``pmt`` is set to ``None``.

    >>> tvmm(pval=5000, nrate=11.32, nper=48, fval=0, pyr=12) # doctest: +ELLIPSIS
    -130.00...


    When the parameter ``noprint`` is set to ``False``, a user friendly table with
    the data computed by the function is print.

    >>> tvmm(pval=5000, nrate=11.32, nper=48, fval=0, pyr=12, noprint=False) # doctest: +ELLIPSIS
    Present Value: .......  5000.00
    Future Value: ........     0.00
    Payment: .............  -130.01
    Due: .................      END
    No. of Periods: ......    48.00
    Compoundings per Year:    12
    Nominal Rate: .......     11.32
    Effective Rate: .....     11.93
    Periodic Rate: ......      0.94


    * Future value:

    >>> tvmm(pval=5000, nrate=11.32, nper=48, pmt=pmt, fval=None, pyr=12) # doctest: +ELLIPSIS
    -0.0...

    * Present value:

    >>> tvmm(nrate=11.32, nper=48, pmt=pmt, fval = 0.0, pval=None, pyr=12) # doctest: +ELLIPSIS
    5000...

    All the arguments support lists as inputs. When a argument is a list and the
    ``noprint`` is set to ``False``, a table with the data is print.

    >>> tvmm(pval=[5, 500, 5], nrate=11.32, nper=48, fval=0, pyr=12, noprint=False) # doctest: +ELLIPSIS
    #   pval   fval    pmt   nper  nrate  erate  prate due
    ------------------------------------------------------
    0   5.00   0.00  -0.13  48.00  11.32  11.93   0.94 END
    1 500.00   0.00  -0.13  48.00  11.32  11.93   0.94 END
    2   5.00   0.00  -0.13  48.00  11.32  11.93   0.94 END


    * Interest rate:

    >>> tvmm(pval=5000, nper=48, pmt=pmt, fval = 0.0, pyr=12) # doctest: +ELLIPSIS
    11.32...

    * Number of periods:

    >>> tvmm(pval=5000, nrate=11.32/12, pmt=pmt, fval=0.0) # doctest: +ELLIPSIS
    48.0...


    """

    #pylint: disable=too-many-arguments
    #pylint: disable=too-many-branches

    numnone = 0
    numnone += 1 if pval is None else 0
    numnone += 1 if fval is None else 0
    numnone += 1 if nper is None else 0
    numnone += 1 if pmt is None else 0
    numnone += 1 if nrate is None else 0

    if numnone > 1:
        raise ValueError('One of the params must be set to None')

    if numnone == 0:
        pmt = None

    if pmt == 0.0:
        pmt = 0.0000001

    nrate = numpy.array(nrate)

    if pval is None:
        result = numpy.pv(rate=nrate/100/pyr, nper=nper, fv=fval, pmt=pmt, when=due)
    elif fval is None:
        result = numpy.fv(rate=nrate/100/pyr, nper=nper, pv=pval, pmt=pmt, when=due)
    elif nper is None:
        result = numpy.nper(rate=nrate/100/pyr, pv=pval, fv=fval, pmt=pmt, when=due)
    elif pmt is None:
        result = numpy.pmt(rate=nrate/100/pyr, nper=nper, pv=pval, fv=fval, when=due)
    else:
        result = numpy.rate(pv=pval, nper=nper, fv=fval, pmt=pmt, when=due) * 100 * pyr

    if noprint is True:
        if isinstance(result, numpy.ndarray):
            return result.tolist()
        return result


    nrate = nrate.tolist()

    if pval is None:
        pval = result
    elif fval is None:
        fval = result
    elif nper is None:
        nper = result
    elif pmt is None:
        pmt = result
    else:
        nrate = result

    params = _vars2list([pval, fval, nper, pmt, nrate])
    pval = params[0]
    fval = params[1]
    nper = params[2]
    pmt = params[3]
    nrate = params[4]

    # raise ValueError(nrate.__repr__())

    erate, prate = iconv(nrate=nrate, pyr=pyr)

    if len(pval) == 1:
        if pval is not None:
            print('Present Value: ....... {:8.2f}'.format(pval[0]))
        if fval is not None:
            print('Future Value: ........ {:8.2f}'.format(fval[0]))
        if pmt is not None:
            print('Payment: ............. {:8.2f}'.format(pmt[0]))
        if due is not None:
            print('Due: .................      {:s}'.format('END' if due == 0 else 'BEG'))
        print('No. of Periods: ...... {:8.2f}'.format(nper[0]))
        print('Compoundings per Year: {:>5d}'.format(pyr))
        print('Nominal Rate: .......  {:8.2f}'.format(nrate[0]))
        print('Effective Rate: .....  {:8.2f}'.format(erate))
        print('Periodic Rate: ......  {:8.2f}'.format(prate))

    else:
        if due == 0:
            sdue = 'END'
            txtpmt = []
            for item, _ in enumerate(pval):
                txtpmt.append(pmt[item][-1])
        else:
            sdue = 'BEG'
            txtpmt = []
            for item, _ in enumerate(pval):
                txtpmt.append(pmt[item][0])


        maxlen = 5
        for value1, value2, value3, value4 in zip(pval, fval, txtpmt, nper):
            maxlen = max(maxlen, len('{:1.2f}'.format(value1)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value2)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value3)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value4)))

        len_aux = len('{:d}'.format(len(pval)))

        fmt_num = ' {:' + '{:d}'.format(maxlen) + '.2f}'
        fmt_num = '{:<' + '{:d}'.format(len_aux) +  'd}' + fmt_num * 7 + ' {:3s}'
        # fmt_shr = '{:' + '{:d}'.format(len_aux) + 's}'
        fmt_hdr = ' {:>' + '{:d}'.format(maxlen) + 's}'
        fmt_hdr = '{:' + '{:d}'.format(len_aux) + 's}' + fmt_hdr * 7 + ' due'


        txt = fmt_hdr.format('#', 'pval', 'fval', 'pmt', 'nper', 'nrate', 'erate', 'prate')
        print(txt)
        print('-' * len_aux + '-' * maxlen * 7 + '-' * 7 + '----')
        for item, _ in enumerate(pval):
            print(fmt_num.format(item,
                                 pval[item],
                                 fval[item],
                                 txtpmt[item],
                                 nper[item],
                                 nrate[item],
                                 erate[item],
                                 prate[item],
                                 sdue))
Пример #34
0
 def Year_nper():
     a = np.nper(e1.get()), eval(e2.get()), eval(e3.get())
     a = int(a) + 1
     v1.set(a)
Пример #35
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'))
Пример #36
0
 def test_nper2(self):
     assert_almost_equal(np.nper(0.0, -2000, 0, 100000.), 50.0, 1)
Пример #37
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, 1),
                            np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'begin'), 4)
        # end
        assert_almost_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0),
                            np.pmt(0.08 / 12, 5 * 12, 15000., 0, 'end'), 4)
        assert_almost_equal(np.pmt(0.08 / 12, 5 * 12, 15000., 0, 0),
                            np.pmt(0.08 / 12, 5 * 12, 15000., 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., 1),
                            np.nper(0.075, -2000, 0, 100000., 'begin'), 4)
        # end
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000.),
                            np.nper(0.075, -2000, 0, 100000., 'end'), 4)
        assert_almost_equal(np.nper(0.075, -2000, 0, 100000., 0),
                            np.nper(0.075, -2000, 0, 100000., 'end'), 4)
Пример #38
0
#!/usr/bin/python

import numpy

print "Number of payments", numpy.nper(0.10 / 12, -100, 9000)
Пример #39
0
 def test_nper(self):
     assert_almost_equal(np.nper(0.075, -2000, 0, 100000.), 21.54, 2)
Пример #40
0
    rate = rate / period

    #Begin the if statement

    # if user desires a time output

    if output_type == '1':

        pmt = float(
            input('What are your desired monthly payments, in dollars?'))

        # Calculate the time
        try:

            time = np.nper(rate, -pmt, principle)

        except RuntimeWarning:

            print(
                "Your inputted payments do not cover your interest. You would never pay off the loan at that rate."
            )

            continue

        #print time to the console

        print('You have ' + str(format(time, '.2f')) +
              ' payments to make. \nThat is approximately ' +
              str(format(time / period, '.2f')) + ' years.')
Пример #41
0
import numpy as np
fv = np.fv(0.001, 5, -100, -1000)
print(round(fv, 2))
pv = np.pv(0.001, 5, -100, fv)
print(pv)
npv = np.npv(0.001, [-1000, -100, -100, -100, -100, -100])
print(round(npv, 2))
fv = np.fv(0.001, 5, 0, npv)
print(round(fv, 2))
irr = np.irr([-1000, 100, 200, 300, 400, 500])
print(irr)
npv = np.npv(irr, [-1000, 100, 200, 300, 400, 500])
print(npv)
nper = np.nper(0.001, -100, 1000)
print(nper)
pmt = np.pmt(0.001, 5, 1000)
print(pmt)
rate = np.rate(15, -100, 1000, 0)
print(rate)
Пример #42
0
def tvmm(pval=None,
         fval=None,
         pmt=None,
         nrate=None,
         nper=None,
         due=0,
         pyr=1,
         noprint=True):
    """Computes present and future values, interest rate and number
    of periods.

    Args:
        pval (float, list): Present value.
        fval (float, list): Future value.
        pmt (float, list): Periodic payment.
        nrate (float, list): Nominal rate per year.
        nper (int, list): Number of compounding periods.
        due (int): When payments are due.
        pyr (int, list): number of periods per year.
        noprint (bool): prints enhanced output


    Returns:
        Argument set to None in the function call.

    Effective interest rate per period is calculated as `nrate` / `pyr`.


    >>> tvmm(pval=5000, nrate=11.32, nper=48, fval=0, pyr=12, noprint=False) # doctest: +ELLIPSIS
    Present Value: .......  5000.00
    Future Value: ........     0.00
    Payment: .............  -130.01
    Due: .................      END
    No. of Periods: ......    48.00
    Compoundings per Year:    12
    Nominal Rate: .......     11.32
    Effective Rate: .....     11.93
    Periodic Rate: ......      0.94

    >>> tvmm(pval=[5, 500, 5], nrate=11.32, nper=48, fval=0, pyr=12, noprint=False) # doctest: +ELLIPSIS
    #   pval   fval    pmt   nper  nrate  erate  prate due
    ------------------------------------------------------
    0   5.00   0.00  -0.13  48.00  11.32  11.93   0.94 END
    1 500.00   0.00  -0.13  48.00  11.32  11.93   0.94 END
    2   5.00   0.00  -0.13  48.00  11.32  11.93   0.94 END
    """

    #pylint: disable=too-many-arguments
    #pylint: disable=too-many-branches

    numnone = 0
    numnone += 1 if pval is None else 0
    numnone += 1 if fval is None else 0
    numnone += 1 if nper is None else 0
    numnone += 1 if pmt is None else 0
    numnone += 1 if nrate is None else 0

    if numnone > 1:
        raise ValueError('One of the params must be set to None')

    if numnone == 0:
        pmt = None

    if pmt == 0.0:
        pmt = 0.0000001

    nrate = numpy.array(nrate)

    if pval is None:
        result = numpy.pv(rate=nrate / 100 / pyr,
                          nper=nper,
                          fv=fval,
                          pmt=pmt,
                          when=due)
    elif fval is None:
        result = numpy.fv(rate=nrate / 100 / pyr,
                          nper=nper,
                          pv=pval,
                          pmt=pmt,
                          when=due)
    elif nper is None:
        result = numpy.nper(rate=nrate / 100 / pyr,
                            pv=pval,
                            fv=fval,
                            pmt=pmt,
                            when=due)
    elif pmt is None:
        result = numpy.pmt(rate=nrate / 100 / pyr,
                           nper=nper,
                           pv=pval,
                           fv=fval,
                           when=due)
    else:
        result = numpy.rate(pv=pval, nper=nper, fv=fval, pmt=pmt,
                            when=due) * 100 * pyr

    if noprint is True:
        if isinstance(result, numpy.ndarray):
            return result.tolist()
        return result

    nrate = nrate.tolist()

    if pval is None:
        pval = result
    elif fval is None:
        fval = result
    elif nper is None:
        nper = result
    elif pmt is None:
        pmt = result
    else:
        nrate = result

    params = vars2list([pval, fval, nper, pmt, nrate])
    pval = params[0]
    fval = params[1]
    nper = params[2]
    pmt = params[3]
    nrate = params[4]

    # raise ValueError(nrate.__repr__())

    erate, prate = iconv(nrate=nrate, pyr=pyr)

    if len(pval) == 1:
        if pval is not None:
            print('Present Value: ....... {:8.2f}'.format(pval[0]))
        if fval is not None:
            print('Future Value: ........ {:8.2f}'.format(fval[0]))
        if pmt is not None:
            print('Payment: ............. {:8.2f}'.format(pmt[0]))
        if due is not None:
            print('Due: .................      {:s}'.format('END' if due ==
                                                            0 else 'BEG'))
        print('No. of Periods: ...... {:8.2f}'.format(nper[0]))
        print('Compoundings per Year: {:>5d}'.format(pyr))
        print('Nominal Rate: .......  {:8.2f}'.format(nrate[0]))
        print('Effective Rate: .....  {:8.2f}'.format(erate))
        print('Periodic Rate: ......  {:8.2f}'.format(prate))

    else:
        if due == 0:
            sdue = 'END'
            txtpmt = []
            for item, _ in enumerate(pval):
                txtpmt.append(pmt[item][-1])
        else:
            sdue = 'BEG'
            txtpmt = []
            for item, _ in enumerate(pval):
                txtpmt.append(pmt[item][0])

        maxlen = 5
        for value1, value2, value3, value4 in zip(pval, fval, txtpmt, nper):
            maxlen = max(maxlen, len('{:1.2f}'.format(value1)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value2)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value3)))
            maxlen = max(maxlen, len('{:1.2f}'.format(value4)))

        len_aux = len('{:d}'.format(len(pval)))

        fmt_num = ' {:' + '{:d}'.format(maxlen) + '.2f}'
        fmt_num = '{:<' + '{:d}'.format(
            len_aux) + 'd}' + fmt_num * 7 + ' {:3s}'
        # fmt_shr = '{:' + '{:d}'.format(len_aux) + 's}'
        fmt_hdr = ' {:>' + '{:d}'.format(maxlen) + 's}'
        fmt_hdr = '{:' + '{:d}'.format(len_aux) + 's}' + fmt_hdr * 7 + ' due'

        txt = fmt_hdr.format('#', 'pval', 'fval', 'pmt', 'nper', 'nrate',
                             'erate', 'prate')
        print(txt)
        print('-' * len_aux + '-' * maxlen * 7 + '-' * 7 + '----')
        for item, _ in enumerate(pval):
            print(
                fmt_num.format(item, pval[item], fval[item], txtpmt[item],
                               nper[item], nrate[item], erate[item],
                               prate[item], sdue))
 def test_nper2(self):
     assert_almost_equal(np.nper(0.0,-2000,0,100000.),
                         50.0, 1)
Пример #44
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)