Present Value

Overview

The present value is a method for calculating the value of a series of future cash flows. It forms the foundation of asset valuation in general, and particularly the foundation of fixed income valuation.

Present Value Function

Quantlib provides a method called npv for calculating the net present value. The sample code below provides a function that runs the calucation..

def present_value(cash_flows, discount_curve, includeSettlementDateFlows=False, npv_date=None, settlement_date=None): cash_flow_dates = [ql.Date(int(x.split('-')[2]),int(x.split('-')[1]), int(x.split('-')[0])) for x,_ in cash_flows ] cash_flow_amounts = [x for _,x in cash_flows] # Instantiate SimpleCashFlow objects cash_flows = [ ql.SimpleCashFlow(amount, date) for amount, date in zip(cash_flow_amounts, cash_flow_dates) ] if npv_date != None: #iso_string = "2026-08-17" npv_date = ql.Date(npv_date, "%Y-%m-%d") pass if settlement_date != None: settlement_date = ql.Date(settlement_date, "%Y-%m-%d") pass # The boolean includeSettlementDateFlows 'False' indicates we do not include past/expired cash flows if npv_date != None and settlement_date != None: return ql.CashFlows.npv(cash_flows, discount_curve, includeSettlementDateFlows, settlement_date, npv_date) return ql.CashFlows.npv(cash_flows, discount_curve, includeSettlementDateFlows)

The above function is saved in the davinci quantlib wrapper library.

import present_value as py cash_flows = [('2026-10-10', 100.0),('2026-11-04', 100)] value = py.present_value(cash_flows, discount_curve, includeSettlementDateFlows=False):

The quantlib npv function has the following signature

ql.CashFlows.npv(leg, discountCurve, includeSettlementDateFlows, settlementDate, npvDate)