Changing Settings::instance().evaluationDate() and impact on Instruments.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing Settings::instance().evaluationDate() and impact on Instruments.

Lluis Pujol Bajador

Hi,

I need to estimate the value of a portfolio of existing swaps in future dates. For example the value in 1 YR, 2YR, .....20YR time. At this moment I don't care about the implied curve for 1YR, 2YR, etc... I am happy to use existing curve and just change the evaluation date.

I though that If I setup the current portfolio of Swaps I would only need to change Settings::instance().evaluationDate() and get the new PV for each swap. But I findout that I still get the PV of cash flows that have already matured. (¿?).

I paste an example in Python (just a prove of concept)  that setups a vanilla swap and gets NPV at inception and move 1YR and 2YR the evaluation date. It creates and excel file with the NPV and cashflows for both legs for each valuation date. (attached the excel file).

  • Why do still have cashflows in 2011 if we have moved forward 2 YR?
  • What is really changing when the evaluation date is changed?.

Thanks in advance for your helps and sorry if they are quite basic questions.

Lluís.

***************************************************

The initial valuation date is 13 - October - 2010

I've previously created a deposwapcurve with depoSwapCurve = PiecewiseLogLinearDiscount( ValueDate, helpers, ActualActual())

# swaps to be priced

swapEngine = DiscountingSwapEngine(discountTermStructure)

nominal = 10000000
length = 10
maturity = calendar.advance(ValueDate,length,Years)
payFixed = True

fixedLegFrequency = Annual
fixedLegTenor = Period(1,Years)
fixedLegAdjustment = ModifiedFollowing
fixedLegDayCounter = Actual365Fixed()
fixedRate = 0.05

floatingLegFrequency = Semiannual
floatingLegTenor = Period(6,Months)
spread = 0.0
fixingDays = 2
index = Euribor6M(forecastTermStructure)
index.addFixing(Date(11,October,2010),0.01204)
floatingLegAdjustment = ModifiedFollowing
floatingLegDayCounter = index.dayCounter()

fixedSchedule = Schedule(ValueDate, maturity,
                         fixedLegTenor, calendar,
                         fixedLegAdjustment, fixedLegAdjustment,
                         DateGeneration.Forward, False)
floatingSchedule = Schedule(ValueDate, maturity,
                            floatingLegTenor, calendar,
                            floatingLegAdjustment, floatingLegAdjustment,
                            DateGeneration.Forward, False)

spot = VanillaSwap(VanillaSwap.Payer, nominal,
                   fixedSchedule, fixedRate, fixedLegDayCounter,
                   floatingSchedule, index, spread,
                   floatingLegDayCounter)
spot.setPricingEngine(swapEngine)

# price on the bootstrapped curves

(......)

def report(swap, name):
    print format % (name, formatPrice(swap.NPV(),2),formatPrice(swap.fixedLegNPV(),2),
                    formatPrice(swap.floatingLegNPV(),2),formatRate(swap.fairSpread(),4),
                    formatRate(swap.fairRate(),4))

discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)

report(spot,'depo-fut-swap')


w = xlwt.Workbook()
ws = w.add_sheet('CashFlows0')

styleNum = xlwt.easyxf(num_format_str='#,##0.00')
styleDate = xlwt.easyxf(num_format_str='DD/MM/YYYY')
styleHeader = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')

NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())

ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0, 4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)

fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()

for i in range(len(fixedleg)):
 ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,1,fixedleg[i].amount(),styleNum)
 ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
 ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)

for i in range(len(floatingleg)):
 ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,6,floatingleg[i].amount(),styleNum)
 ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
 ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)

ws.write(1, 4, spot.NPV(),styleNum)

# move forward 1 year

Settings.instance().evaluationDate = calendar.advance(ValueDate,1,Years)
(....)

discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)
report(spot,'depo-swap')

NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())

ws = w.add_sheet('CashFlows1')

ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0,4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)

fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()

for i in range(len(fixedleg)):
 ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,1,fixedleg[i].amount(),styleNum)
 ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
 ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)

for i in range(len(floatingleg)):
 ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,6,floatingleg[i].amount(),styleNum)
 ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
 ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)
ws.write(1, 4, spot.NPV(),styleNum)

# move 2 year the time

Settings.instance().evaluationDate = calendar.advance(Settings.instance().evaluationDate,1,Years)
(...)

discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)
report(spot,'depo-swap')

NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())

ws = w.add_sheet('CashFlows2')

ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0,4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)


fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()

for i in range(len(fixedleg)):
 ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,1,fixedleg[i].amount(),styleNum)
 ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
 ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)

for i in range(len(floatingleg)):
 ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
 ws.write(i+1,6,floatingleg[i].amount(),styleNum)
 ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
 ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)

ws.write(1, 4, spot.NPV(),styleNum)

w.save(Foutput)

*************************************************


 


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

SwapOutput.xls (18K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Changing Settings::instance().evaluationDate() and impact on Instruments.

Luigi Ballabio
On Wed, 2010-11-24 at 14:35 +0100, Lluis Pujol Bajador wrote:

> I need to estimate the value of a portfolio of existing swaps
> in future dates. For example the value in 1 YR, 2YR, .....20YR time.
> At this moment I don't care about the implied curve for 1YR, 2YR,
> etc... I am happy to use existing curve and just change the evaluation
> date.
>
> I though that If I setup the current portfolio of Swaps I would only
> need to change Settings::instance().evaluationDate() and get the new
> PV for each swap. But I findout that I still get the PV of cash flows
> that have already matured. (¿?).

Your problem is the creation of the discount curve:

> I've previously created a deposwapcurve with depoSwapCurve =
> PiecewiseLogLinearDiscount( ValueDate, helpers, ActualActual())

If you create it with an explicit ValueDate, that date will remain the
date to which the cash flows are discounted.  If you create the curve
with a number of business days (probably 0) and a calendar instead, the
reference date of the discount curve will move with the evaluation date
and the cashflows will be filtered accordingly.

See chapter 3 at <http://sites.google.com/site/luigiballabio/qlbook> for
more details.

Luigi



--

An ideal world is left as an exercise to the reader.
-- Paul Graham



------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Changing Settings::instance().evaluationDate() and impact on Instruments.

Henner Heck

Hello,

i want to make sure that i understood the mentioned behavior of the curve  
correctly.
When creating it with "number of business days" and changing the  
evaluation date
to a future future date, will the curve's shape remain the same (Behavior  
A),
or will the curve be "forwarded" 2 years (Behavior B)?

Example for "evaluationDate_New = evaluationDate_Old +2Years":

Behavior A:
The discount factors d4_Old and d4_New for a cash flow 4 years after the  
evaluation date
are the same before and after the date change.

Behavior B:
The discount factor d4_New for a cash flow 4 years after the evaluation  
date fulfills
the following equation:
d4_New == d6_Old / d2_Old

If it is one of these behaviors, which one?

And if it is not B, how can i achieve behavior B?
(Should i open a new thread for this question?)

Best Regards,
Henner Heck




Am 24.11.2010, 15:58 Uhr, schrieb Luigi Ballabio  
<[hidden email]>:

> On Wed, 2010-11-24 at 14:35 +0100, Lluis Pujol Bajador wrote:
>> I need to estimate the value of a portfolio of existing swaps
>> in future dates. For example the value in 1 YR, 2YR, .....20YR time.
>> At this moment I don't care about the implied curve for 1YR, 2YR,
>> etc... I am happy to use existing curve and just change the evaluation
>> date.
>>
>> I though that If I setup the current portfolio of Swaps I would only
>> need to change Settings::instance().evaluationDate() and get the new
>> PV for each swap. But I findout that I still get the PV of cash flows
>> that have already matured. (¿?).
>
> Your problem is the creation of the discount curve:
>
>> I've previously created a deposwapcurve with depoSwapCurve =
>> PiecewiseLogLinearDiscount( ValueDate, helpers, ActualActual())
>
> If you create it with an explicit ValueDate, that date will remain the
> date to which the cash flows are discounted.  If you create the curve
> with a number of business days (probably 0) and a calendar instead, the
> reference date of the discount curve will move with the evaluation date
> and the cashflows will be filtered accordingly.
>
> See chapter 3 at <http://sites.google.com/site/luigiballabio/qlbook> for
> more details.
>
> Luigi
>
>
>


--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Changing Settings::instance().evaluationDate() and impact on Instruments.

Luigi Ballabio
On Mon, 2010-12-06 at 15:53 +0100, Henner Heck wrote:

> i want to make sure that i understood the mentioned behavior of the
> curve correctly. When creating it with "number of business days" and
> changing the evaluation date to a future future date, will the curve's
> shape remain the same (Behavior A), or will the curve be "forwarded" 2
> years (Behavior B)?
>
> Example for "evaluationDate_New = evaluationDate_Old +2Years":
>
> Behavior A:
> The discount factors d4_Old and d4_New for a cash flow 4 years after the  
> evaluation date are the same before and after the date change.
>
> Behavior B:
> The discount factor d4_New for a cash flow 4 years after the evaluation  
> date fulfills the following equation:
> d4_New == d6_Old / d2_Old
>
> If it is one of these behaviors, which one?
> And if it is not B, how can i achieve behavior B?

It's A (more or less; the curve shape might change slightly due to
holidays.)  discount(evaluationDate + 4*Years) should stay the same when
evaluationDate moves.  The curve will assume the deposit and swap rates
used for bootstrapping apply from the new evaluation date, and will
rebuild itself accordingly.

Behavior B can be achieved by means of the ImpliedTermStructure class
(<ql/termstructures/yield/impliedtermstructure.hpp>.)

Luigi


--

The surest way to make a monkey of a man is to quote him.
-- Robert Benchley



------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:

WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users