Skip to content

Commit

Permalink
Merge pull request #4 from b3mery/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
b3mery authored Aug 21, 2022
2 parents 96e9236 + 2a9abe9 commit 643136f
Show file tree
Hide file tree
Showing 9 changed files with 7,689 additions and 86 deletions.
19 changes: 15 additions & 4 deletions AmortaPy/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@


def generate_amortization_schedule(nominal_annual_interest_rate:float,
loan_amount:int|float,
years:int|float,
repayment_frequency:str|int|float|None = None) -> Amortization:
return Amortization(nominal_annual_interest_rate, loan_amount, years, repayment_frequency)
principal_amount:int|float,
years:int|float,
repayment_frequency:str|int|float|None = None) -> Amortization:
"""Configure Amortization Schedule
Args:
nominal_annual_interest_rate (float): nominal annual interest rate EG: `3.94%` = `0.0394`
principal_amount (int | float): The principal amount `515000` or `515000.00`
years (int | float): The amortization years eg `30` or `30.0`
repayment_frequency (str | int | float | None, optional): repayment frequency, `monthly`|`12`, or `fortnightly`|`26`, or `weekly`|`52`. Defaults to None.
If None configured default will be used.
Returns:
Amortization: Instantiated Amortization instance
"""
return Amortization(nominal_annual_interest_rate, principal_amount, years, repayment_frequency)
4 changes: 2 additions & 2 deletions AmortaPy/core/_amortization.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ def _generate_amortization_schedule(self):
pd.DataFrame: The Loan Amortization Schedule of repayments in order of repayment
"""
df = generate_amortization_table(
self.principal_amount,
self._nominal_interest_rate_per_period(self.nominal_annual_interest_rate, self.repayment_frequency_periods),
self.principal_amount,
self.n_periods
)
self._df = df
Expand Down Expand Up @@ -384,7 +384,7 @@ def _repr_html_(self):
report = f"""
{style_sheet}
<h1>Amortization Schedule</h1>
<table>
<table class='amort-summary'>
<tr>
<th>Principal Borrowed</th>
<th>Years</th>
Expand Down
22 changes: 11 additions & 11 deletions AmortaPy/core/_amortization_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ def calculate_principal_and_interest_payment(total_period_payment:int|float,
calculate_interest_payment(outstanding_loan_amount, nominal_interest_rate_per_period)
)

def generate_amortization_table(loan_amount:int|float,
nominal_interest_rate_per_period:float,
number_of_periods:int|float,
total_payment_per_period: int|float|None=None,
additional_payment_per_period: int|float|None=None ) -> pd.DataFrame:
def generate_amortization_table(nominal_interest_rate_per_period:float,
principal_amount:int|float,
number_of_periods:int|float,
total_payment_per_period: int|float|None=None,
additional_payment_per_period: int|float|None=None ) -> pd.DataFrame:
"""Generate a Amortization Repaymet table as a `pandas.DataFrame`
Args:
* loan_amount (int | float): The amount borrowed `545000.00`\n
* nominal_interest_rate_per_period (float): The quote annual interest rate `3.85%` would be passed as `0.0385`\n
* number_of_periods (int | float): Number of periods over the life of the loan. EG: `30 years` paid `monthly` = `30*12` \n
* nominal_interest_rate_per_period (float): The quote annual interest rate `3.85%` devided by the repayment frequency. Monthly would be passed as `0.0385/12`
* principal_amount (int | float): The principal amount borrowed `545000.00`
* number_of_periods (int | float): Number of periods over the life of the loan. EG: `30 years` paid `monthly` = `30*12`
* total_payment_per_period (int | float | None, optional): Optional total payment per period `PMT` you intend to make. Defaults to None. Func will calculate the payment by default.
If `total_payment_per_period` is passed it will need to be >= the expected minium `PMT`, if it is not, the calculated minium PMT will be used.\n
If `total_payment_per_period` is passed it will need to be >= the expected minium `PMT`, if it is not, the calculated minium PMT will be used.
* additional_payment_per_period (int | float | None, optional): Optional additional payment per period you intend to make, will be added to `total_payment_per_period`. Defaults to None.
Returns:
pd.DataFrame: Amortization Repayment Schedule Table
"""
# Evaluate the Params
expected_total_period_payment = calculate_total_period_payment(loan_amount, nominal_interest_rate_per_period, number_of_periods)
expected_total_period_payment = calculate_total_period_payment(principal_amount, nominal_interest_rate_per_period, number_of_periods)

if total_payment_per_period is None or total_payment_per_period < expected_total_period_payment:
total_payment_per_period = expected_total_period_payment
Expand All @@ -105,7 +105,7 @@ def generate_amortization_table(loan_amount:int|float,
}

# Iterate through periods until the peirods are complete or the loan is $0.00
opening_loan_balance = loan_amount
opening_loan_balance = principal_amount
for period in range(1, number_of_periods+1):
principal, interest = calculate_principal_and_interest_payment(total_payment_per_period, opening_loan_balance, nominal_interest_rate_per_period)
closing_loan_balance = opening_loan_balance - principal
Expand Down
8 changes: 5 additions & 3 deletions AmortaPy/templates/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
td:hover {
.amort-summary td:hover {
background-color: #428cd1;
}
th{
font-size: large;
.amort-summary th {
font-weight: 600;
font-family: Arial, Helvetica, sans-serif;
color: azure;
}
24 changes: 11 additions & 13 deletions Docs/Amortization_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <style> td:hover {\n",
" <style> .amort-summary td:hover {\n",
" background-color: #428cd1;\n",
" }\n",
"th{\n",
" font-size: large;\n",
".amort-summary th {\n",
" font-weight: 600;\n",
" font-family: Arial, Helvetica, sans-serif;\n",
" color: azure;\n",
" word-wrap: break-word;\n",
"} </style>\n",
" <h1>Amortization Schedule</h1>\n",
" <table>\n",
" <table class='amort-summary'>\n",
" <tr>\n",
" <th>Principal Borrowed</th>\n",
" <th>Years</th>\n",
Expand Down Expand Up @@ -74,16 +77,16 @@
" Principal Borrowed: $515,000.00\n",
" Years: 30\n",
" Annual Interest Rate: 3.94%\n",
" Forecasted Total Interest: $363,147.47'\n",
" Forecasted Total Interest: $363,147.47\n",
" Repayment Frequency: Weekly - 1,560 Periods \n",
" Minimum Repayments Per Peirod: $562.92'\n",
" Minimum Repayments Per Peirod: $562.92\n",
" Effective Annual Interest Rate (EAR) 4.02% \n",
" Total Interest / Total Principal: 70.51%\n",
" --------------------------------------------------------------------\n",
" "
]
},
"execution_count": 3,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -226,11 +229,6 @@
"```\n",
"<img src=\"./Period_Payments_Over_Time.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 643136f

Please sign in to comment.