Example of valuation of amortizing interest rate swap in Python with quantlib module
for quantlib excel version see Amortizing interest rate swap valuation excel quantlib addin
First , Install QuantLib package for python (use guide here )
to run the program just copy paste it into iPython editor and press enter
#example amortizing swap valuation
#http://www.pricederivatives.com
from QuantLib import *
import numpy as np
from math import *
todaysDate=Date(31,12,2013)
startDate=todaysDate
Settings.instance().evaluationDate=todaysDate;
crvToday=FlatForward(todaysDate,0.0121,Actual360())
forecastTermStructure = RelinkableYieldTermStructureHandle()
index = Euribor(Period("6m"),forecastTermStructure)
maturity = Date(31,12,2018);
schedule = Schedule(startDate, maturity,Period("6m"),TARGET(),ModifiedFollowing,ModifiedFollowing,DateGeneration.Forward, False)
nominals=[100.0]*10
couponRates=[0.05]*10
floatingleg=IborLeg(nominals,schedule,index,Actual360())
fixedleg=FixedRateLeg(schedule,Actual360(),nominals,couponRates)
firstPeriodDayCount = DayCounter())
index.addFixing(index.fixingDate(schedule[0]),0)
swap1=Swap(floatingleg,fixedleg)
discountTermStructure = RelinkableYieldTermStructureHandle()
swapEngine = DiscountingSwapEngine(discountTermStructure)
swap1.setPricingEngine(swapEngine)
discountTermStructure.linkTo(crvToday)
forecastTermStructure.linkTo(crvToday)
npv=swap1.NPV()
print npv
![[<<] PriceDerivatives blog](http://www.pricederivatives.com/en/wp-content/uploads/2014/03/cropped-pricederivatives-blog-logo-Copy3.png)