def makeSchedule(self, p, r, n): table = (x for x in amortization_schedule(int(p), (int(r) / 12) / 100, int(n))) print( tabulate(table, headers=[ "Number", "Amount", "Interest", "Principal", "Balance" ], floatfmt=",.2f", numalign="right"))
def main(): # pragma: no cover import argparse from tabulate import tabulate parser = argparse.ArgumentParser( description= 'Python library for calculating amortizations and generating amortization schedules' ) # required parameters required = parser.add_argument_group('required arguments') required.add_argument('-P', '--principal', dest='principal', type=float, required=True, help='Principal amount') required.add_argument('-n', '--period', dest='period', type=int, required=True, help='Total number of periods') required.add_argument('-r', '--interest-rate', dest='interest_rate', type=float, required=True, help='Interest rate per period') # optional parameters parser.add_argument('-s', '--schedule', dest='schedule', default=False, action='store_true', help='Generate amortization schedule') arguments = parser.parse_args() if arguments.schedule: table = (x for x in amortization_schedule( arguments.principal, arguments.interest_rate, arguments.period)) print( tabulate(table, headers=[ "Number", "Amount", "Interest", "Principal", "Balance" ], floatfmt=",.2f", numalign="right")) else: amount = calculate_amortization_amount(arguments.principal, arguments.interest_rate, arguments.period) print("Amortization amount: {:,.2f}".format(amount))
def test_amortization_schedule() -> None: principal: float = 150000 period = 36 interest_rate = 0.1 expected = ( (1, 4840.08, 1250.00, 3590.08, 146409.92), (2, 4840.08, 1220.08, 3620.00, 142789.92), (3, 4840.08, 1189.92, 3650.16, 139139.76), (4, 4840.08, 1159.50, 3680.58, 135459.18), (5, 4840.08, 1128.83, 3711.25, 131747.93), (6, 4840.08, 1097.90, 3742.18, 128005.75), (7, 4840.08, 1066.71, 3773.37, 124232.38), (8, 4840.08, 1035.27, 3804.81, 120427.57), (9, 4840.08, 1003.56, 3836.52, 116591.05), (10, 4840.08, 971.59, 3868.49, 112722.56), (11, 4840.08, 939.35, 3900.73, 108821.83), (12, 4840.08, 906.85, 3933.23, 104888.60), (13, 4840.08, 874.07, 3966.01, 100922.59), (14, 4840.08, 841.02, 3999.06, 96923.53), (15, 4840.08, 807.70, 4032.38, 92891.15), (16, 4840.08, 774.09, 4065.99, 88825.16), (17, 4840.08, 740.21, 4099.87, 84725.29), (18, 4840.08, 706.04, 4134.04, 80591.25), (19, 4840.08, 671.59, 4168.49, 76422.76), (20, 4840.08, 636.86, 4203.22, 72219.54), (21, 4840.08, 601.83, 4238.25, 67981.29), (22, 4840.08, 566.51, 4273.57, 63707.72), (23, 4840.08, 530.90, 4309.18, 59398.54), (24, 4840.08, 494.99, 4345.09, 55053.45), (25, 4840.08, 458.78, 4381.30, 50672.15), (26, 4840.08, 422.27, 4417.81, 46254.34), (27, 4840.08, 385.45, 4454.63, 41799.71), (28, 4840.08, 348.33, 4491.75, 37307.96), (29, 4840.08, 310.90, 4529.18, 32778.78), (30, 4840.08, 273.16, 4566.92, 28211.86), (31, 4840.08, 235.10, 4604.98, 23606.88), (32, 4840.08, 196.72, 4643.36, 18963.52), (33, 4840.08, 158.03, 4682.05, 14281.47), (34, 4840.08, 119.01, 4721.07, 9560.40), (35, 4840.08, 79.67, 4760.41, 4799.99), (36, 4839.99, 40.00, 4799.99, 0.00), ) result = amortization_schedule(principal, interest_rate, period) for e, r in zip(expected, result): assert pytest.approx(e) == r
def loandata(request): if request.method=='GET': return render(request,'loandata.html') p=request.POST['loan_amount'] r=request.POST['interest_rate'] t=request.POST['loan_period'] p=float(p) r=float(r) t=float(t) m=(p*(r/12)*(math.pow(1+r/12,12*t)))/(math.pow(1+r/12,12*t)-1) #print(str(round(m,2))) month=12*t month=int(month) stbalance=p endbalance=p data = {"sn": [], "pa": [], "m": [],"iap": [], "lob": []} for number, amount, interest, principal, balance in amortization_schedule(p, r, month): print(number,round(amount,2),round(interest,2), round(principal,2), round(balance,2)) data["sn"].append(str(number)) data["pa"].append(str(round(amount,2))) data["m"].append(str(round(principal,2))) data["iap"].append(str(round(interest,2))) data["lob"].append(str(round(balance,2))) #print(data) csv_file = pd.DataFrame(data) #result = json.dumps(data) #context = Context(data) #print(context) #print(csv_file) for index, row in csv_file.iterrows(): _,created = loan.objects.update_or_create( sn=row['sn'], pa=row['pa'], pap=row['m'], iap=row['iap'], lob=row['lob'], ) csvinfo = loan.objects.filter().order_by('-id')[:month][::-1] return render(request, 'loaddata.html', {'data': csvinfo})
def post(self, request): form = CarCalculatorForm(request.POST) if form.is_valid(): form.save() car_price = form.cleaned_data["car_price"] tax_rate = float(form.cleaned_data["tax_rate"]) downpayment = form.cleaned_data["down_payment"] loan_term = form.cleaned_data["loan_term_in_years"] apr = float(form.cleaned_data["interest_rate"]) trade_value = form.cleaned_data["trade_in_value"] # if use if 'calc' in request.POST: loan_amount = int(((tax_rate*0.01) * (car_price)) + car_price) - (downpayment + trade_value) interest = ((apr * 0.01)/12) total_interest_amount = "{:.0f}".format((interest) * (loan_amount)) monthly = ((loan_amount * interest)*((1 + interest)**(12*loan_term)))/ (((1 + interest)**(12*loan_term)) -1) monthly_payment = "{:.2f}".format(monthly) table = (amortization_schedule(loan_amount, interest, loan_term*12)) print( tabulate( table, headers=["Payments", "Amount", "Interest", "Principal", "Balance"], floatfmt=",.2f", numalign="right" ) ) # form = CarCalculatorForm else: def sendform(self, request): getdata = self.get_context_data(post) args= { 'form': form, 'loan_amount': loan_amount, 'monthly_payment': monthly_payment, 'interest': interest, 'total_interest_amount': total_interest_amount, 'table': table} return render(request, 'index.html', args)
def test_amortization_schedule(): principal = 150000 period = 36 interest_rate = 0.1 amortization_amount = calculate_amortization_amount( principal, interest_rate, period) number = 1 balance = principal for n, a, i, p, b in amortization_schedule(principal, interest_rate, period): interest = balance * interest_rate principal = amortization_amount - interest balance -= principal assert number == n assert amortization_amount == a assert interest == i assert principal == p assert balance == b number += 1
print('I don' 't know your name') #Suitecase example suitcase_weight_float = float( input('Please enter suitcase weight in pounds: ')) if suitcase_weight_float >= 50: print('There is an extra $25 dollars charge') else: print('There is no extra charge') # Creating an amortization schedule using Python # download through pip install amortization before running code from amortization.schedule import amortization_schedule for number, amount, interest, principal, balance in amortization_schedule( 250000, 0.1, 36): print(number, amount, interest, principal, balance) #Creating an amortization schedule using a table from Tabulate #pip install tabulate before running code in python from amortization.schedule import amortization_schedule from tabulate import tabulate table = (x for x in amortization_schedule(250000, 0.1, 36)) print( tabulate(table, headers=["Number", "Amount", "Interest", "Principal", "Balance"], floatfmt=",.2f", numalign="right"))
# importing amortization import amortization # importing tabulate ( library to pretty-print data from python from amortization.schedule import amortization_schedule from tabulate import tabulate # known values principal = 1333 interest = 3.15 months = 12 table = (x for x in amortization_schedule(principal, interest / 100, months)) print( tabulate(table, headers=["Number", "Amount", "Interest", "Principal", "Balance"], floatfmt=",.2f", numalign="right"))
def createAmortizationGenerator(self): schedule = amortization_schedule(self.principal, (self.monthlyInterestRate / 12) / 100, self.numberOfMonths) for i in schedule: yield i
def main(): # pragma: no cover import argparse from tabulate import tabulate parser = argparse.ArgumentParser( description= "Python library for calculating amortizations and generating amortization schedules" ) # required parameters required = parser.add_argument_group("required arguments") required.add_argument( "-P", "--principal", dest="principal", type=float, required=True, help="Principal amount", ) required.add_argument( "-n", "--period", dest="period", type=int, required=True, help="Total number of periods", ) required.add_argument( "-r", "--interest-rate", dest="interest_rate", type=float, required=True, help="Interest rate per period", ) # optional parameters parser.add_argument( "-s", "--schedule", dest="schedule", default=False, action="store_true", help="Generate amortization schedule", ) arguments = parser.parse_args() if arguments.schedule: table = (x for x in amortization_schedule( arguments.principal, arguments.interest_rate, arguments.period)) print( tabulate( table, headers=[ "Number", "Amount", "Interest", "Principal", "Balance" ], floatfmt=",.2f", numalign="right", )) else: amount = calculate_amortization_amount(arguments.principal, arguments.interest_rate, arguments.period) print("Amortization amount: {:,.2f}".format(amount))
def main() -> None: # pragma: no cover import argparse from tabulate import tabulate parser = argparse.ArgumentParser( description= "Python library for calculating amortizations and generating amortization schedules" ) # required parameters required = parser.add_argument_group("required arguments") required.add_argument( "-P", "--principal", dest="principal", type=float, required=True, help="Principal amount", ) required.add_argument( "-r", "--interest-rate", dest="interest_rate", type=float, required=True, help="Interest rate per period", ) # optional parameters parser.add_argument( "-s", "--schedule", dest="schedule", default=False, action="store_true", help="Generate amortization schedule", ) mutually_exclusive = parser.add_mutually_exclusive_group(required=True) mutually_exclusive.add_argument( "-n", "--period", dest="period", type=int, help="Total number of periods", ) mutually_exclusive.add_argument( "-a", "--amount", dest="amount", type=float, help="Amortization amount per period", ) arguments = parser.parse_args() if arguments.schedule: if arguments.period is None: parser.error("-s/--schedule requires -n/--period") total_paid = total_interest = total_principal = 0.0 table: List[Any] = [] for row in amortization_schedule(arguments.principal, arguments.interest_rate, arguments.period): table.append(row) total_paid += row[1] total_interest += row[2] total_principal += row[3] table.append(("Totals", total_paid, total_interest, total_principal)) print( tabulate( table, headers=[ "Number", "Amount", "Interest", "Principal", "Balance" ], floatfmt=",.2f", numalign="right", )) elif arguments.amount: period = calculate_amortization_period(arguments.principal, arguments.interest_rate, arguments.amount) print("Amortization period: {}".format(period)) else: amount = calculate_amortization_amount(arguments.principal, arguments.interest_rate, arguments.period) print("Amortization amount: {:,.2f}".format(amount))
# importing amortization import amortization # importing tabulate ( library to pretty-print data from python from amortization.amount import calculate_amortization_amount # Example --> the percent needs to be in decimal form and the time in months! # amount = calculate_amortization_amount(1500, 3.5/100, 42) # print(amount) # printing the amortization schedule example! # from amortization.schedule import amortization_schedule # for number,amount,interest,principal,balance in amortization_schedule(1500, 3.5/100, 24): # print(number, amount, interest, principal, balance) from amortization.schedule import amortization_schedule from tabulate import tabulate table = (x for x in amortization_schedule(1500, 3.5 / 100, 24)) print( tabulate(table, headers=["Number", "Amount", "Interest", "Principal", "Balance"], floatfmt=",.2f", numalign="right"))