API Reference¶
Loan¶
Base Loan class supporting various mortgage types.
Parameters¶
principal : float Original loan amount. term_months : int Loan term in months. rate : float Nominal annual interest rate (APR). origination_date : datetime.date Date the loan originated. loan_type : str, optional Type of loan: 'fixed', 'arm', 'fha', 'heloc', 'va', 'usda'. Default is 'fixed'. compounding : str, optional Interest compounding method (e.g., '30E/360', 'A/365F'). Default is '30E/360'. pmi : bool, optional Whether the loan includes Private Mortgage Insurance. Default is False. draw_period_months : int, optional Number of months for interest-only draw period (HELOCs). repayment_term_months : int, optional Repayment phase after draw period (HELOCs). extra_payment_amount : float or Decimal, optional Fixed recurring extra payment amount. extra_payment_frequency : str, optional Frequency of extra payments ('monthly', 'biweekly').
Source code in mortgagemodeler/loan.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
apply_extra_payment(amount, frequency)
¶
Set up recurring extra payments.
Parameters¶
amount : float Extra payment amount to apply. frequency : str Payment frequency, e.g., 'monthly', 'biweekly'.
Source code in mortgagemodeler/loan.py
172 173 174 175 176 177 178 179 180 181 182 183 | |
from_arm_type(arm_type, principal, term, rate, origination_date)
classmethod
¶
Construct an ARM loan from a hybrid ARM string (e.g., '5/6').
Parameters¶
arm_type : str Format is '{fixed_period}/{adjustment_freq}' in years/months.
Source code in mortgagemodeler/loan.py
95 96 97 98 99 100 101 102 103 104 105 106 107 | |
from_fha(principal, term, rate, origination_date)
classmethod
¶
Construct an FHA loan object.
Source code in mortgagemodeler/loan.py
80 81 82 83 | |
from_usda(principal, term, rate, origination_date)
classmethod
¶
Construct a USDA loan object.
Source code in mortgagemodeler/loan.py
90 91 92 93 | |
from_va(principal, term, rate, origination_date)
classmethod
¶
Construct a VA loan object.
Source code in mortgagemodeler/loan.py
85 86 87 88 | |
recast(lump_sum, recast_date)
¶
Apply a lump-sum principal reduction and update loan balance.
Parameters¶
lump_sum : float Amount to reduce from principal. recast_date : date Date the recast is executed.
Source code in mortgagemodeler/loan.py
158 159 160 161 162 163 164 165 166 167 168 169 170 | |
refinance(new_rate, refinance_date, new_term=None, fees=0.0)
¶
Creates a new Loan object simulating a refinance at a given date.
Parameters¶
new_rate : float New interest rate. refinance_date : date Date of refinance (must match amortizer schedule). new_term : int, optional Optional new loan term in months. fees : float, optional Optional closing costs added to balance.
Returns¶
Loan New refinanced Loan object.
Source code in mortgagemodeler/loan.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
set_indexed_rate(index_name, margin, caps=(2, 1, 5))
¶
Configure index-based rate adjustment (for ARMs or HELOCs).
Parameters¶
index_name : str Name of the index (e.g., 'SOFR', 'PRIME'). margin : float Rate margin added to index. caps : tuple Tuple of (initial cap, periodic cap, lifetime cap).
Source code in mortgagemodeler/loan.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
to_dict()
¶
Return core loan parameters as dictionary (for CLI or plotting use).
Source code in mortgagemodeler/loan.py
185 186 187 188 189 190 191 192 193 | |
LoanAmortizer¶
LoanAmortizer builds an amortization schedule for various loan types including: - Fixed Rate Loans - Adjustable Rate Mortgages (ARMs) - FHA Loans with MIP - VA and USDA Loans with Guarantee Fees - HELOCs with draw and repayment phases
It supports: - Custom forward rate schedules - Insurance premiums (PMI, MIP, USDA annual fee) - Decimal-based precision for all financial calculations
Parameters¶
loan : Loan An instance of the Loan class with fully defined parameters. custom_rate_schedule : dict, optional A dictionary mapping date strings ("YYYY-MM-DD") to interest rate overrides.
Source code in mortgagemodeler/amortizer.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
to_csv(filepath)
¶
Writes the amortization schedule to a CSV file.
Parameters¶
filepath : str Destination file path.
Source code in mortgagemodeler/amortizer.py
153 154 155 156 157 158 159 160 161 162 | |
to_dataframe()
¶
Returns the amortization schedule as a pandas DataFrame.
Returns¶
pd.DataFrame Tabular amortization schedule.
Source code in mortgagemodeler/amortizer.py
142 143 144 145 146 147 148 149 150 151 | |
RateReader¶
Utility class to read and serve forward interest rates from macroeconomic projections. Supports Prime, LIBOR, SOFR, MTA, CMT, and fallback to FRED codes.
Source code in utils/rates.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
__init__(filepath=None)
¶
Initialize the rate reader.
Parameters¶
filepath : str, optional Path to the rate projection file. If not provided, defaults to 'data/macroeconforward.txt'.
Source code in utils/rates.py
24 25 26 27 28 29 30 31 32 33 34 | |
get_rate(index, date_str)
¶
Retrieve the forward rate for a specific index and date.
Parameters¶
index : str The macroeconomic index (e.g., 'PRIME', 'LIBOR12'). date_str : str Date string in format 'YYYY-MM-DD'.
Returns¶
float Forward interest rate.
Source code in utils/rates.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Utility Functions¶
Effective APR¶
Estimate Effective APR using cost-adjusted loan proceeds and IRR method.
Parameters¶
principal : float Loan amount. rate : float Nominal APR. term_months : int Loan term in months. points : float Discount points as percent of loan (e.g., 1.0 for 1 point). fees : float Closing costs not rolled into the loan.
Returns¶
float Effective APR expressed as annual percent.
Source code in utils/effective_apr.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Breakeven Analysis¶
Compute breakeven month when refinancing pays off via cumulative monthly savings.
Parameters¶
refi_df : pd.DataFrame Amortization table for refinanced loan. base_df : pd.DataFrame Amortization table for original loan. refi_costs : float Closing/refinance costs incurred upfront.
Returns¶
dict Contains breakeven month and cumulative savings profile.
Source code in utils/breakeven.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
Plotting¶
Plot the amortization schedule: balances and payment components.
Parameters¶
df : pd.DataFrame Output from LoanAmortizer.to_dataframe() title : str Title for the plot. save_path : str or None If provided, saves the plot to file.
Source code in utils/plotting.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Compare two amortization schedules by summarizing key outcome metrics.
Source code in utils/exta_payment_compare.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |