Why does DayCounter Business252 blow up the pricing time

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

Why does DayCounter Business252 blow up the pricing time

ravi agrawal-2
Hi,

I wanted to know why is Business252
DayCounter dayCounter252 = Business252(UnitedStates(UnitedStates::NYSE));
is increasing the time taken to price option. Initially without Business252 daycounter it was getting order of 0.4 secs to price options using Finite Differences Method which increased to 10 secs!!
I went to Business252 implementation code but wasn't able to figure out the place which is causing this.
Can anyone share some light on this.

Thanks
Ravi Agrawal


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Why does DayCounter Business252 blow up the pricing time

Luigi Ballabio
On Tue, 2010-02-02 at 11:15 -0600, ravi agrawal wrote:
> I wanted to know why is Business252
> DayCounter dayCounter252 =
> Business252(UnitedStates(UnitedStates::NYSE));
> is increasing the time taken to price option.

Business252 must count the business days between the dates, which can
only be done by iterating over all the dates in between and checking
whether they are holidays (see the Calendar::businessDaysBetween method,
which is called by Business252::Impl::dayCount.)  All other day counters
just count the actual days between the dates (or some approximation
thereof) which can be done very quickly by taking the difference between
the two dates.

Luigi


--

All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore, if
you can't get them together again, there must be a reason. By all
means, do not use a hammer.
-- IBM maintenance manual, 1925



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Why does DayCounter Business252 blow up the pricing time

ravi agrawal-2
But to my surprise pricing 1 week option and 10 year "option" using Business252 was taking nearly same time, so I was thinking is there something more to it.


On Tue, Feb 2, 2010 at 11:52 AM, Luigi Ballabio <[hidden email]> wrote:
On Tue, 2010-02-02 at 11:15 -0600, ravi agrawal wrote:
> I wanted to know why is Business252
> DayCounter dayCounter252 =
> Business252(UnitedStates(UnitedStates::NYSE));
> is increasing the time taken to price option.

Business252 must count the business days between the dates, which can
only be done by iterating over all the dates in between and checking
whether they are holidays (see the Calendar::businessDaysBetween method,
which is called by Business252::Impl::dayCount.)  All other day counters
just count the actual days between the dates (or some approximation
thereof) which can be done very quickly by taking the difference between
the two dates.

Luigi


--

All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore, if
you can't get them together again, there must be a reason. By all
means, do not use a hammer.
-- IBM maintenance manual, 1925




------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Why does DayCounter Business252 blow up thepricing time

Simon Ibbotson
In reply to this post by Luigi Ballabio
Why does it have to be so inefficient? If the time period is greater than even a few days, it would be more efficient to count the number of holidays between the days (and total up the number of weekends) and remove the total from the number of days...

Sent from my BlackBerry® wireless device

-----Original Message-----
From: Luigi Ballabio <[hidden email]>
Date: Tue, 02 Feb 2010 18:52:21
To: ravi agrawal<[hidden email]>
Cc: <[hidden email]>
Subject: Re: [Quantlib-users] Why does DayCounter Business252 blow up the
 pricing time

On Tue, 2010-02-02 at 11:15 -0600, ravi agrawal wrote:
> I wanted to know why is Business252
> DayCounter dayCounter252 =
> Business252(UnitedStates(UnitedStates::NYSE));
> is increasing the time taken to price option.

Business252 must count the business days between the dates, which can
only be done by iterating over all the dates in between and checking
whether they are holidays (see the Calendar::businessDaysBetween method,
which is called by Business252::Impl::dayCount.)  All other day counters
just count the actual days between the dates (or some approximation
thereof) which can be done very quickly by taking the difference between
the two dates.

Luigi


--

All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore, if
you can't get them together again, there must be a reason. By all
means, do not use a hammer.
-- IBM maintenance manual, 1925



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Why does DayCounter Business252 blow up thepricing time

ravi agrawal-2
Even for option which go for a year, if we follow the approach Ibbotson suggested + checks like
Subtracting weekends and holidays lying between particular dates + adding back holidays which fell on weekends. +
What worried me was Business252 calculated the price of the option with time to maturity 7 days and 1 year with nearly same time frame. I would have expected it to vary a lot.

Thanks
Ravi Agrawal

On Tue, Feb 2, 2010 at 10:02 AM, <[hidden email]> wrote:
Why does it have to be so inefficient? If the time period is greater than even a few days, it would be more efficient to count the number of holidays between the days (and total up the number of weekends) and remove the total from the number of days...

Sent from my BlackBerry® wireless device

-----Original Message-----
From: Luigi Ballabio <[hidden email]>
Date: Tue, 02 Feb 2010 18:52:21
To: ravi agrawal<[hidden email]>
Cc: <[hidden email]>
Subject: Re: [Quantlib-users] Why does DayCounter Business252 blow up the
 pricing time

On Tue, 2010-02-02 at 11:15 -0600, ravi agrawal wrote:
> I wanted to know why is Business252
> DayCounter dayCounter252 =
> Business252(UnitedStates(UnitedStates::NYSE));
> is increasing the time taken to price option.

Business252 must count the business days between the dates, which can
only be done by iterating over all the dates in between and checking
whether they are holidays (see the Calendar::businessDaysBetween method,
which is called by Business252::Impl::dayCount.)  All other day counters
just count the actual days between the dates (or some approximation
thereof) which can be done very quickly by taking the difference between
the two dates.

Luigi


--

All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore, if
you can't get them together again, there must be a reason. By all
means, do not use a hammer.
-- IBM maintenance manual, 1925



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Why does DayCounter Business252 blow up thepricing time

Piter Dias-4
In reply to this post by Simon Ibbotson
On Tue, 2 Feb 2010 18:02:51 +0000, [hidden email] wrote:
> Why does it have to be so inefficient? If the time period is greater
than
> even a few days, it would be more efficient to count the number of
holidays
> between the days (and total up the number of weekends) and remove the
total
> from the number of days...

It could be improved for weekends but the way holidays are stored (inside
isBusinessDay calendar method) it is not possible to get them without
checking each date in the interval.
The way holidays are stored must change (somehow) or Calendar classes use
some kind of prepared data (a base date + X calendar days = Y business
days) in order improve performance. I already used the last one in a data
base and performance improvement was huge.

Regards,


-------------------------

Piter Dias
[hidden email]
http://www.piterdias.com


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Why does DayCounter Business252 blow up thepricing time

Piter Dias-4
In reply to this post by ravi agrawal-2

What worried me was Business252 calculated the price of the option with time to maturity 7 days and 1 year with nearly same time frame. I would have expected it to vary a lot.

I made some tests here and the performance changed linearly with time frame, what is expected due to algorithm implemented. Each 1000 days added 0.009s to dayCount call.

Changing the way that holidays are stored may increase the performance, perhaps it may increase memory use and add a setup time. By the way, I wrote the (slow) businessDaysBetween method that is slowing down your project.

Regards,

--




Piter Dias
[hidden email]
http://www.piterdias.com


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Why does DayCounter Business252 blow up thepricing time

Luigi Ballabio
In reply to this post by Simon Ibbotson
On Tue, 2010-02-02 at 18:02 +0000, [hidden email] wrote:
> Why does it have to be so inefficient?

It _doesn't_ have to be, but...

> If the time period is greater than even a few days, it would be more
> efficient to count the number of holidays between the days (and total
> up the number of weekends) and remove the total from the number of
> days...

...as Piter said, the point is to count the number of holidays between
any two days.  Right now they're implemented as rules (i.e., logic such
as 'December 25th each year' or 'the third Monday in January') not a
list of days.  To count them, you have to loop---unless you precalculate
stuff, but it has to be stored cleverly to work for any two days.

Luigi



--

Innovation is hard to schedule.
-- Dan Fylstra



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users