Ejemplo n.º 1
0
def calc_parameter(ask_reply, input_string):
    """ calc_parameter is a calculator to calculate the final goal based on ino given by users.
    
    Parameters
    ---------
    Param1 : Dictionary
        The dictionary stores the float provided by user as value,  stores corresponding terms as the key.
        
    Param2 : String
        The string is the specified goal for caculation. 
        The string implies what the dictionary would be since each value is dependent to the remaining values. 
        
    Returns
    ------
    Return1 : Float
        The final result of requested value after caculation.
    """
    user_fin_dict = ask_reply

    try:
        if (ask_reply['input_string']) == 'present value':
            output = abs(
                npf.pv(user_fin_dict["required rate per year"],
                       user_fin_dict["required time period"],
                       0 - user_fin_dict["payment"],
                       user_fin_dict["future value"]))
        elif (ask_reply['input_string']) == "future value":
            output = abs(
                npf.fv(user_fin_dict["required rate per year"],
                       user_fin_dict["required time period"],
                       0 - user_fin_dict["payment"],
                       0 - user_fin_dict["present value"]))
        elif (ask_reply['input_string']) == "payment":
            output = abs(
                npf.pmt(user_fin_dict["required rate per year"],
                        user_fin_dict["required time period"],
                        0 - user_fin_dict["present value"],
                        user_fin_dict["future value"]))
        elif (ask_reply['input_string']) == "required rate per year":
            output = abs(
                npf.rate(user_fin_dict["required time period"],
                         0 - user_fin_dict["payment"],
                         0 - user_fin_dict["present value"],
                         user_fin_dict["future value"]))
        elif (ask_reply['input_string']) == "required time period":
            output = abs(
                npf.nper(user_fin_dict["required rate per year"],
                         0 - user_fin_dict["payment"],
                         0 - user_fin_dict["present value"],
                         user_fin_dict["future value"]))
        else:
            output = random.choice(unknown_input_reply)
        return output

    except KeyError:
        print("I'm dead because of you !")
        print("You should never have encountered this. What did you do?")
        return None
    def test_broadcast(self):
        assert_almost_equal(npf.nper(0.075, -2000, 0, 100000., [0, 1]),
                            [21.5449442, 20.76156441], 4)

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

        assert_almost_equal(npf.ppmt(0.1 / 12, list(range(5)), 24, 2000, 0,
                                     [0, 0, 1, 'end', 'begin']),
                            [numpy.nan, -75.62318601, -75.62318601,
                             -76.88882405, -76.88882405], 4)
Ejemplo n.º 3
0
    def get_nper_loans(self) -> int:
        _nper = ceil(
            nper(
                self.rate / (100 * self.freq),
                -self.reg_pmt,
                self.loan,
                when=self.pmt_when,
            ))

        self.num_of_years = round(_nper / self.freq, 2)
        self.periods = self.get_periods()
        self.periods_a = self.get_periods_a()
        self.periods_m = self.get_periods_m()

        return _nper
    def get_nper_retirements(self) -> int:
        _nper = ceil(
            nper(
                self.rate / (100 * self.freq),
                -self.reg_wdr,
                self.ret_fund,
                when=self.wdr_when,
            )
        )

        self.num_of_years = round(_nper / self.freq, 2)
        self.periods = self.get_periods()
        self.periods_a = self.get_periods_a()
        self.periods_m = self.get_periods_m()

        return _nper
    def get_nper_savings(self) -> int:
        _nper = ceil(
            nper(
                self.rate / (100 * self.freq),
                -self.reg_dep,
                -self.ini_dep,
                self.fin_bal,
                self.dep_when,
            ))

        self.num_of_years = round(_nper / self.freq, 2)
        self.periods = self.get_periods()
        self.periods_a = self.get_periods_a()
        self.periods_m = self.get_periods_m()

        return _nper
Ejemplo n.º 6
0
    def test_broadcast(self):
        assert_almost_equal(npf.nper(0.075, -2000, 0, 100000., [0, 1]),
                            [21.5449442, 20.76156441], 4)

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

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

        assert_almost_equal(
            npf.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)
Ejemplo n.º 7
0
    def test_when(self):
        # begin
        assert_equal(npf.rate(10, 20, -3500, 10000, 1),
                     npf.rate(10, 20, -3500, 10000, 'begin'))
        # end
        assert_equal(npf.rate(10, 20, -3500, 10000),
                     npf.rate(10, 20, -3500, 10000, 'end'))
        assert_equal(npf.rate(10, 20, -3500, 10000, 0),
                     npf.rate(10, 20, -3500, 10000, 'end'))

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

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

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

        # begin
        assert_equal(npf.nper(0.075, -2000, 0, 100000., 1),
                     npf.nper(0.075, -2000, 0, 100000., 'begin'))
        # end
        assert_equal(npf.nper(0.075, -2000, 0, 100000.),
                     npf.nper(0.075, -2000, 0, 100000., 'end'))
        assert_equal(npf.nper(0.075, -2000, 0, 100000., 0),
                     npf.nper(0.075, -2000, 0, 100000., 'end'))
ppmt = npf.ppmt(rate=rate / 12, per=per, nper=nper * 12, pv=pv, fv=fv)
'''ipmt:每期支付金额之利息'''
ipmt = npf.ipmt(rate=rate / 12, per=per, nper=nper * 12, pv=pv, fv=fv)
print(
    f'年利率{rate * 100}%,贷款总额¥{abs(pv)}元,{nper}年还清,每月还款¥{abs(pmt):.2f}元,第{per}期本金:¥{abs(ppmt):.2f}元,第{per}期利息:¥{abs(ipmt):.2f}元。'
)
'''nper:分期数'''
rate = 0.075
pmt = -8055.93
pv = 1000000
fv = 0
#  rate:年利率
#  pmt:每期还款金额(负值)
#  pv:贷款总额(正值)
#  fv:期末剩余贷款金额(正值)
nper = npf.nper(rate=rate / 12, pmt=pmt, pv=pv, fv=fv)
print(
    f'年利率{rate * 100}%,贷款总额¥{abs(pv)}元,每月还款¥{abs(pmt)},需要还款{nper / 12:.2f}年,共{nper:.2f}期。还款总金额:¥{-pmt * nper:.2f}元。'
)
'''rate:计算利率'''
nper = 240
pmt = -8055.93
pv = 1000000
fv = 0
#  nper:还款期数
#  pmt:每期还款金额(负值)
#  pv:贷款总额(正值)
#  fv:期末剩余贷款金额(正值)
rate = npf.rate(nper=nper,
                pmt=pmt,
                pv=pv,
Ejemplo n.º 9
0
 def test_broadcast(self):
     assert_almost_equal(npf.nper(0.075, -2000, 0, 100000., [0, 1]),
                         [21.5449442, 20.76156441], 4)
Ejemplo n.º 10
0
 def test_no_interest(self):
     assert_(npf.nper(0, -100, 1000) == 10)
Ejemplo n.º 11
0
 def test_infinite_payments(self):
     with numpy.errstate(divide='raise'):
         result = npf.nper(0, -0.0, 1000)
     assert_(result == numpy.inf)
Ejemplo n.º 12
0
 def test_gh_18(self):
     with numpy.errstate(divide='raise'):
         assert_allclose(
             npf.nper(0.1, 0, -500, 1500),
             11.52670461,  # Computed using Google Sheet's NPER
         )
Ejemplo n.º 13
0
 def test_basic_values(self):
     assert_allclose(
         npf.nper([0, 0.075], -2000, 0, 100000),
         [50, 21.544944],  # Computed using Google Sheet's NPER
         rtol=1e-5,
     )
Ejemplo n.º 14
0
 def test_nper2(self):
     assert_almost_equal(npf.nper(0.0, -2000, 0, 100000.), 50.0, 1)
Ejemplo n.º 15
0
def payments_remaining(int_rate,payment,princ):
	return np.ceil(npf.nper(int_rate/12,payment,princ))
Ejemplo n.º 16
0
 def get_n(self):
     return fin.nper(self.rate, self.pmt, self.pv, self.fv, self.when)[0]
Ejemplo n.º 17
0
print(
    "#**********************#FINANCIAL FUNCTIONS#**************************#")
#FINANCIAL FUNCTIONS
import numpy_financial as npf
npf.fv(8 / 12, 10 * 12, -400, 400)
period = np.arange(1 * 12) + 1
principle = 3000.00
ipmt = npf.ipmt(0.0925 / 12, period, 1 * 12, principle)
ppmt = npf.ipmt(0.0925 / 12, period, 1 * 12, principle)

for payment in period:
    index = payment - 1
    principle = principle + ppmt[index]
print(
    f"{payment} {np.round(ppmt[index],2)} {np.round(ipmt[index],2)} {np.round(principle,2)}"
)

np.round(npf.nper(0.0925 / 12, -150, 3000.00), 2)
npf.npv(0.08, [-1500, 4000, 5000, 6000, 7000])

print(
    "#**********************#COMPARISON FUNCTIONS#**************************#")
#COMPARISON FUNCTIONS
carr_1 = np.array([2, 3])
carr_2 = np.array([3, 2])
np.greater(carr_1, carr_2)
np.greater_equal(carr_1, carr_2)
np.less(carr_1, carr_2)
np.less_equal(carr_1, carr_2)
np.not_equal(carr_1, carr_2)
np.equal(carr_1, carr_2)
Ejemplo n.º 18
0
 def test_nper(self):
     assert_almost_equal(npf.nper(0.075, -2000, 0, 100000.), 21.54, 2)