Skip to content

Instantly share code, notes, and snippets.

@alastairparagas
Created September 3, 2022 01:01
Show Gist options
  • Save alastairparagas/16fca23021c0c3bc69f735b335c4a42b to your computer and use it in GitHub Desktop.
Save alastairparagas/16fca23021c0c3bc69f735b335c4a42b to your computer and use it in GitHub Desktop.
Car purchase: Auto Loan vs Cash Purchase - Capital Allocation
# Auto loan cost comparison
# When debt can be obtained at low interest rates, using cheap debt
# and investing the cash that would have been used otherwise) can be
# more tactical, than just deploying cash where cheap debt can suffice.
import math
auto_rate_table = [
0.0219, 0.0429, # Old vs New Rates, Credit Union 1
0.0289, 0.0319, # Old vs New Rates, Credit Uni$on 2
0.0449, 0.0524 # Old vs New Rates, National Bank
]
def auto_loan_cost(auto_cost, months, compound_rate=0.03):
# 10-year Treasury yield is currently at 3.2%~. Assuming this holds,
# reinvesting interest coupons from US Treasury bonds ("risk-free" investment
# issued by US government, which also issues US dollars), we can get a 3% CAGR~
fig, fig_ax1 = plt.subplots()
num_months = np.arange(months) + 1
for interest_rate in auto_rate_table:
# Auto loan is simple, not compounded interest (interest calculated monthly)
# auto_loan_interest[x] = total paid interest up to that point, on month x
auto_loan_interest = np.cumsum(numpy_financial.ipmt(
rate=interest_rate/12, per=num_months, nper=months, pv=-1*auto_cost,
))
# Option A: Don't buy the car in cash. Instead, invest the cash that would
# have been used for car purchase (preventing capital from being locked in)
# Net profit after taking into account the downsides of auto loan:
# * Monthly payment interest could have been invested over time
# * Principal of debt owed against bank
option_a = numpy_financial.fv(
compound_rate/12, nper=num_months,
pmt=0, pv=-1*auto_cost
) - (
auto_loan_interest * np.full(
months, 1+compound_rate/12
) ** np.arange(months)
) - auto_cost
fig_ax1.plot(
num_months, option_a, '--',
label='{0}% interest'.format(np.round(interest_rate*100, 2))
)
# Option B: Buy the car in cash outright, no investable money as our capital
# was locked in a cash-based car purchase
fig_ax1.plot(num_months, np.zeros(months), '-', label='Cash Purchase')
fig_ax1.set_xlabel('Months')
fig_ax1.set_ylabel('Net Profit, $')
fig_ax1.set_title('Car Purchase: Auto Loan vs Cash\n3% CAGR on investments')
fig_ax1.legend()
fig_ax1.yaxis.set_major_formatter(ticker.FormatStrFormatter('$%.0f'))
auto_loan_cost(15000, 72)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment