Quantcast

QuantLib Python - pricing a ForwardRateAgreement

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

QuantLib Python - pricing a ForwardRateAgreement

tarpanelli@libero.it
Hello,
I have just installed QUantLib-Python 1.8 and I am trying to price a very simple FRA contract but I am not able to retrieve the NPV.(): actually the only number I get as NPV is zero which it is not possible. I am sure I am missing something.
Could you please advice where I am doing a mistake; here below the code.
Thank you for the help
Best regards,
P

nowdate=QuantLib.Date(23,QuantLib.March,2017)
basis=QuantLib.Actual360()
calendar=QuantLib.TARGET()
yc=impYieldCurve(nowdate,calendar,basis)
r=0.02
yc.flatCurve(r)
flatcurve=yc.yieldcurve
maturitydate=QuantLib.Date(3,QuantLib.July,2017)
expirydate=QuantLib.Date(3,QuantLib.October,2017)
euribor3m=QuantLib.Euribor3M()
euribor3m.addFixing(QuantLib.Date(21,QuantLib.March,2017),0.02)
instr=QuantLib.ForwardRateAgreement(nowdate,maturitydate,QuantLib.Position.Long,0.023,1000000.0,euribor3m,flatcurve)
qlpv=instr.NPV()
print(qlpv)

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: QuantLib Python - pricing a ForwardRateAgreement

giambologna
This post was updated on .
I think the issue is that you didn't link Libor object to your curve.
Try this:

import QuantLib
nowdate=QuantLib.Date(23,QuantLib.March,2017)
QuantLib.Settings.instance().evaluationDate = nowdate
print "evaluation date: {0}".format(QuantLib.Settings.instance().evaluationDate)

basis=QuantLib.Actual360()
calendar=QuantLib.TARGET()
r = 0.02
rate = QuantLib.SimpleQuote(r)
rate_handle = QuantLib.QuoteHandle(rate)
dc = QuantLib.Actual365Fixed()
flatcurve=QuantLib.FlatForward(nowdate, rate_handle, dc)
curvehandle = QuantLib.RelinkableYieldTermStructureHandle()
curvehandle.linkTo(flatcurve)

maturitydate=QuantLib.Date(3,QuantLib.July,2017)
expirydate=QuantLib.Date(3,QuantLib.October,2017)
euribor3m=QuantLib.Euribor3M(curvehandle)
euribor3m.addFixing(QuantLib.Date(21,QuantLib.March,2017),0.02)

instr=QuantLib.ForwardRateAgreement(maturitydate,expirydate,QuantLib.Position.Long,0.023,1000000.0,euribor3m,curvehandle)

print "is expired?  {0}".format(instr.isExpired())

#the following two lines might be redundant
dse = QuantLib.DiscountingSwapEngine(curvehandle)
instr.setPricingEngine(dse)

qlpv=instr.NPV()
fwd = instr.forwardRate()

print(qlpv)
Loading...