Financial Calculations & Valuation
Intermediate
Corporate Lease vs Buy (CapEx Loan) NPV & Depreciation Tax Shield Analyzer in Python
Compare after-tax Net Present Value of leasing vs debt-financed purchasing of industrial machinery or commercial assets in Python.
#numpy#pandas
Problem Statement
CFOs and project finance teams deciding between equipment leasing and CapEx purchase must account for full tax deductibility of lease rentals vs WDV depreciation tax shields.
Formula / Core Logic
After-Tax Lease Outflow = Lease_Rental * (1 - Tax_Rate)
Buy Cash Outflow = CapEx - (Depreciation * Tax_Rate) - Salvage_After_Tax
Installation
pip install numpy pandas
lease-vs-buy-equipment-npv-tax-shield-calculator-python.py
import numpy as np
def compare_lease_vs_buy(asset_cost, lease_annual, dep_rate, tax_rate, post_tax_cost_of_debt, years):
# 1. Present Value of Leasing
after_tax_lease = lease_annual * (1 - tax_rate)
pv_lease = sum(after_tax_lease / ((1 + post_tax_cost_of_debt) ** t) for t in range(1, years + 1))
# 2. Present Value of Buying (with WDV Depreciation Tax Shield)
wdv = asset_cost
pv_tax_shields = 0.0
for t in range(1, years + 1):
dep = wdv * dep_rate
tax_shield = dep * tax_rate
pv_tax_shields += tax_shield / ((1 + post_tax_cost_of_debt) ** t)
wdv -= dep
pv_buy = asset_cost - pv_tax_shields
return {'PV_Cost_Lease': round(pv_lease, 2), 'PV_Cost_Buy': round(pv_buy, 2), 'Recommended_Option': 'LEASE' if pv_lease < pv_buy else 'BUY_CAPEX'}
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: Why discount Lease vs Buy cash flows at the Post-Tax Cost of Debt instead of WACC?
Lease obligations and secured equipment loans carry contractual fixed-debt risk rather than equity operating risk.