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.
Discount Curve
In order to calculate the present value of a set of cash flows, you need a
discount curve
that specifies the prices of future cash flows.
The quantlib wrapper provides methods for constructing a term structure from a set of observed contracts.
See
term strcutures
data = {"date": "2026-08-10", "1M": 3.79, "1.5M": 3.8, "2M": 3.84, "3M": 3.89, "4M": 3.91, "6M": 4.0, "1Y": 4.04, "2Y": 4.25, "3Y": 4.31, "5Y": 4.41, "7Y": 4.56, "10Y": 4.72, "20Y": 5.25, "30Y": 5.25}
data2 = []
for key in data:
if key != 'date':
item = [key, data[key]]
data2.append(item)
pass
data3 =dt.treasury_term_data(data2)
curve = ts.BootstrappedCurve(type=ts.BootstrapTypes.PiecewiseLogLinearDiscount,day_count=dt.treasury.DAY_COUNT, data=data3)
Cash Flows
The present value function takes a list of cash flow objects, as defined in the
contracts.py script. The following code shows how to take a list of date, value pairs and converts
it into a list of the appropriate cash flow objects.
import contracts as ct
cash_flows = [('2026-10-10', 100.0),('2026-11-04', 100)]
cash_flows2 = [ct.CashFlow(x[0], x[1]) for x in cash_flows]
If you have constructed a Contract object, specifying a fixed income contract, you can
calculate the cash flows from the contract itself using the cash_flows function.
(see
contracts)
import contracts as ct
schedule = ct.Schedule(start_date='2000-01-01',
end_date='2030-01-01',
frequency= ct.Frequency.Annual,
calendar= cl.Calendar.USGovernmentBond,
convention=ct.Convention.Following,
dateroll=ct.DateRoll.Forward)
bond = ct.FixedRateBond(settlement_days=2,face_value=10000,
day_count=ct.DayCount.Actual360,
coupon=0.05,schedule=schedule)
flows = ct.cash_flows(bond)
Calculating the Present Value
The
valuation.py
script includes a function, present_value (see
present value script
for a listing)
import valuation as vl
pv = vl.present_value(cash_flows=flows,discount_curve=curve)
Present Value of a Cash Flow
When discounting a cash flow without using a curve, you need to be able to calculate the
difference in time between todays date, and the date of the cash flow. In particular,
the cash flow will have day count convention assigned to it to interpret what the cash flow
means. The term_structure.py library contains a year_fraction function (wrapper around quantlib)
which will compute the year fraction given the inputted convention.
fraction = ct.year_fraction("2026-08-10",'2027-01-01', ct.DayCount.Actual365Fixed)
rate = 0.05
amount = 100
pv = math.exp(-1*fraction*rate) * amount