本文整理汇总了Python中numpy.ppmt函数的典型用法代码示例。如果您正苦于以下问题:Python ppmt函数的具体用法?Python ppmt怎么用?Python ppmt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ppmt函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_broadcast_decimal
def test_broadcast_decimal(self):
# Use almost equal because precision is tested in the explicit tests, this test is to ensure
# broadcast with Decimal is not broken.
assert_almost_equal(np.ipmt(Decimal('0.1') / Decimal('12'), list(range(5)), Decimal('24'), Decimal('2000')),
[Decimal('-17.29165168'), Decimal('-16.66666667'), Decimal('-16.03647345'),
Decimal('-15.40102862'), Decimal('-14.76028842')], 4)
assert_almost_equal(np.ppmt(Decimal('0.1') / Decimal('12'), list(range(5)), Decimal('24'), Decimal('2000')),
[Decimal('-74.998201'), Decimal('-75.62318601'), Decimal('-76.25337923'),
Decimal('-76.88882405'), Decimal('-77.52956425')], 4)
assert_almost_equal(np.ppmt(Decimal('0.1') / Decimal('12'), list(range(5)), Decimal('24'), Decimal('2000'),
Decimal('0'), [Decimal('0'), Decimal('0'), Decimal('1'), 'end', 'begin']),
[Decimal('-74.998201'), Decimal('-75.62318601'), Decimal('-75.62318601'),
Decimal('-76.88882405'), Decimal('-76.88882405')], 4)
示例2: test_broadcast
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: test_ppmt_special_rate_decimal
def test_ppmt_special_rate_decimal(self):
# When rounded out to 8 decimal places like the float based test, this should not equal the same value
# as the float, substituted for the decimal
def raise_error_because_not_equal():
assert_equal(
round(np.ppmt(Decimal('0.23') / Decimal('12'), 1, 60, Decimal('10000000000')), 8),
Decimal('-90238044.232277036'))
assert_raises(AssertionError, raise_error_because_not_equal)
assert_equal(np.ppmt(Decimal('0.23') / Decimal('12'), 1, 60, Decimal('10000000000')),
Decimal('-90238044.2322778884413969909'))
示例4: test_when
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)
示例5: test_ppmt
def test_ppmt(self):
np.round(np.ppmt(0.1/12,1,60,55000),2) == 710.25
示例6: test_ppmt_special_rate
def test_ppmt_special_rate(self):
assert_equal(np.round(np.ppmt(0.23 / 12, 1, 60, 10000000000), 8), -90238044.232277036)
示例7: test_ppmt_decimal
def test_ppmt_decimal(self):
assert_equal(np.ppmt(Decimal('0.1') / Decimal('12'), Decimal('1'), Decimal('60'), Decimal('55000')),
Decimal('-710.2541257864217612489830917'))
示例8: test_ppmt
def test_ppmt(self):
assert_equal(np.round(np.ppmt(0.1 / 12, 1, 60, 55000), 2), -710.25)
示例9: test_decimal_with_when
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])
示例10: test_when
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'))
示例11: raise_error_because_not_equal
def raise_error_because_not_equal():
assert_equal(
round(np.ppmt(Decimal('0.23') / Decimal('12'), 1, 60, Decimal('10000000000')), 8),
Decimal('-90238044.232277036'))
示例12: cashflows
def cashflows(self):
"""
Construct a dataframe with projections of balances and cashflows for a loan portfolio
in an homogeneous loan pool, where the loans share the same origination period.
:rtype: pandas dataframe
"""
loss_rates = self._credit_model.get('loss')
nonperforming_rates = self._credit_model.get('nonperforming')
provision_rates = self._credit_model.get('provision')
prepayment_rates = self._prepayment_vector
rates = self._rates_vector
index_to_apply = list(range(self.origination_month(), self.origination_month() + self._nper + 1))
ans_df = pd.DataFrame(0.,
index = index_to_apply,
columns = ('saldo_inicial',
'desembolsos',
'amortizacion',
'prepago',
'castigo',
'saldo_final',
'interes',
'improductiva',
'saldo_provision'))
ans_df.loc[self.origination_month()] = [0,
self._origination,
0,
0,
0,
self._origination,
0,
0,
self._origination * provision_rates[0]]
rounding = 6
min_balance = 0.01
initial_balance = self._origination
for payment in range(self._nper):
index = payment + self.origination_month()
loss = np.round(initial_balance * loss_rates[payment], rounding)
prepayment = np.round(initial_balance * prepayment_rates[payment], rounding)
nonperforming = np.round(initial_balance * nonperforming_rates[payment], rounding)
provision = np.round((provision_rates[payment] * (initial_balance - nonperforming)) + nonperforming,
rounding)
ipmt = np.round((initial_balance - nonperforming) * rates[payment], rounding)
contractual_ppmt = np.round(-(np.ppmt(rates[payment],
payment + 1, self._nper, self._origination)), rounding)
if contractual_ppmt > (initial_balance - prepayment - loss):
ppmt = np.round(initial_balance - prepayment - loss, rounding)
else:
ppmt = contractual_ppmt
ending_balance = np.round(initial_balance - ppmt - prepayment - loss, rounding)
if ending_balance < min_balance:
ending_balance = 0.
origination = np.round(0., rounding)
ans_df.loc[index + 1] = [initial_balance,
origination,
ppmt,
prepayment,
loss,
ending_balance,
ipmt,
nonperforming,
provision]
initial_balance = ending_balance
return ans_df
示例13: loans
'default': 'ls_default'}
df = df.rename(columns=rename_dict)
df = df.rename(columns=purpose_dict)
# identify good loans and bad loans (might include the 31 to 120 day late category later)
df.loc[df['ls_default'] == 1, 'bad_loan'] = 1
df.loc[df['ls_chargeoff'] == 1, 'bad_loan'] = 1
df.loc[df['bad_loan'] != 1, 'bad_loan'] = 0
df.loc[df['bad_loan'] != 1, 'good_loan'] = 1
df.loc[df['good_loan'] != 1, 'good_loan'] = 0
# add columns related to debt service and debt service coverage
# calculate annual debt service payments for Lending Club loans
df['annual_prin'] = sum([np.ppmt(df['int_rate'] / 12, i, df['term'], -df['loan_amnt'], 0) for i in range(1, 13)])
df['annual_prin'] = df['annual_prin'].round(2)
df['annual_int'] = sum([np.ipmt(df['int_rate'] / 12, i, df['term'], -df['loan_amnt'], 0) for i in range(1, 13)])
df['annual_int'] = df['annual_int'].round(2)
df['annual_debt_svc'] = df['annual_prin'] + df['annual_int']
df['annual_debt_svc'] = df['annual_debt_svc'].round(2)
# total revolving debt NOT attributable to Lending Club loans
df['other_rev_debt'] = df['total_bal_ex_mort'] - df['out_prncp']
df.loc[df['other_rev_debt'] < 0, 'other_rev_debt'] = 0
# total mortgage/installment debt (also not Lending Club)
df['other_mort_debt'] = df['tot_cur_bal'] - df['other_rev_debt']
df.loc[df['other_mort_debt'] < 0, 'other_mort_debt'] = 0
# estimated annual debt service requirement on non-Lending-Club revolving debt (at Lending Club int_rate, 5yr amort)