Quantlib Present Value
Arguments
import QuantLib as ql
# 1. Set the global evaluation date
calc_date = ql.Date(15, 6, 2026)
ql.Settings.instance().evaluationDate = calc_date
# 2. Define the yield curve (flat rate of 4.5% for this example)
rate = ql.SimpleQuote(0.045)
day_counter = ql.Actual365Fixed()
interest_rate = ql.InterestRate(rate.value(), day_counter, ql.Compounded, ql.Annual)
yield_curve = ql.FlatForward(0, ql.NullCalendar(), ql.QuoteHandle(rate), day_counter)
discount_curve = ql.YieldTermStructureHandle(yield_curve)
# 3. Create a list of cash flows with specific amounts and payment dates
dates = [ql.Date(15, 6, 2027), ql.Date(15, 6, 2028), ql.Date(15, 6, 2029)]
amounts = [100.0, 150.0, 200.0]
leg = [ql.SimpleCashFlow(amount, d) for amount, d in zip(amounts, d)]
# 4. Calculate Net Present Value
include_today = False
npv = ql.CashFlows.npv(leg, discount_curve, include_today)
print(f"The Present Value is: {npv:.4f}")