eval date-problem solved

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

eval date-problem solved

JURAJ HUSKA
I finally solved the problem I had with evaluation date slowing down calculations, although don't quite have an explanation why my solution works.

Here is the solution in words: I had to dispose of SwapRateHelper object immediately after I added it to the instruments RateHelperVector and also had to dispose of the constructed termstructure and instruments vector. See the code below. Interestingly, just disposing of the instruments vector (that is, not disposing separately of SwapRateHelpers) didn't do the job. Anyone a take on this?


Date referenceDate = new Date((int)dtEffectiveDate.ToOADate());                   
                NQuantLib.Settings.instance().setEvaluationDate( referenceDate );

                int settlementDays = 0;//settle is already accounted for above in setting effective date       

                #region XIBOR index

                Currency currency = new USDCurrency();
                // Setup the XIBOR index.
                Xibor index = new Xibor(
                    "dummy",
                    new Period( xiborFrequency ),
                    settlementDays,
                    currency,
                    calendar,
                    xiborConvention,
                    xiborDayCounter
                    );

                #endregion




                for(int i=0;i<30;i++)
                {
                    Quote quote = new SimpleQuote( Convert.ToDouble(dfData[i]/100) );
                    QuoteHandle quoteHandle = new QuoteHandle( quote );
                    NQuantLib.Period period = new Period(i+1, NQuantLib.TimeUnit.Years );


                    RateHelper swapRateHelper = new SwapRateHelper(
                        Convert.ToDouble(dfData[i]/100),
                        period,
                        0,
                        calendar,
                        fixedLegFrequency,
                        fixedLegConvention,
                        fixedLegDayCounter,
                        index
                        );

                    instruments.Add(swapRateHelper);

                    //testing only - works!!!
                    swapRateHelper.Dispose();
                    quoteHandle.Dispose();
                    quote.Dispose();
                    period.Dispose();
   
                }
                index.Dispose();
               

               
               
                decimal[] DiscountFactors = new decimal[30];
                try
                {
                    YieldTermStructure termStructure = new PiecewiseFlatForward(
                        referenceDate,
                        instruments,
                        dayCounter
                        );                       

                    for(int i=0;i<30;i++)
                    {
                        Date date = new Date((int)dtEffectiveDate.AddYears(i+1).ToOADate());
                        DiscountFactors[i] = Convert.ToDecimal(termStructure.discount(date,true));
                    }
                   
                    termStructure.Dispose();
                    instruments.Dispose();
                }
                catch
                {   
                    //and reset the discount factors to zero
                    for(int i=0;i<30;i++)
                    {
                        DiscountFactors[i] = 0;
                    }
                }       

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Luigi Ballabio
On Fri, 2007-07-06 at 16:34 -0500, JURAJ HUSKA wrote:

> I finally solved the problem I had with evaluation date slowing down
> calculations, although don't quite have an explanation why my solution
> works.
>
> Here is the solution in words: I had to dispose of SwapRateHelper
> object immediately after I added it to the instruments
> RateHelperVector and also had to dispose of the constructed
> termstructure and instruments vector. See the code below.
> Interestingly, just disposing of the instruments vector (that is, not
> disposing separately of SwapRateHelpers) didn't do the job. Anyone a
> take on this?

I guess the objects remained alive even though they had gone out of
scope. How does garbage collection in C# work?

Luigi


--

Discontent is the first necessity of progress.
-- Thomas A. Edison



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

JURAJ HUSKA
http://www.csharphelp.com/archives2/archive297.html

Unfortunately, it isn't as deterministic as in C++, which could have been part of the problem, the other one is me not being (ever remotely close to) an expert in either of the languages...

On 7/9/07, Luigi Ballabio <[hidden email]> wrote:
On Fri, 2007-07-06 at 16:34 -0500, JURAJ HUSKA wrote:

> I finally solved the problem I had with evaluation date slowing down
> calculations, although don't quite have an explanation why my solution
> works.
>
> Here is the solution in words: I had to dispose of SwapRateHelper
> object immediately after I added it to the instruments
> RateHelperVector and also had to dispose of the constructed
> termstructure and instruments vector. See the code below.
> Interestingly, just disposing of the instruments vector (that is, not
> disposing separately of SwapRateHelpers) didn't do the job. Anyone a
> take on this?

I guess the objects remained alive even though they had gone out of
scope. How does garbage collection in C# work?

Luigi


--

Discontent is the first necessity of progress.
-- Thomas A. Edison




-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Toyin Akin

Hi,

The C# solution to the problem posed before looks really wierd...

If you look at the following snippet...

########################################################
for(int i=0;i<30;i++)
                {
                    Quote quote = new SimpleQuote(
Convert.ToDouble(dfData[i]/100) );
                    QuoteHandle quoteHandle = new QuoteHandle( quote );
                    NQuantLib.Period period = new Period(i+1,
NQuantLib.TimeUnit.Years );


                    RateHelper swapRateHelper = new SwapRateHelper(
                        Convert.ToDouble(dfData[i]/100),
                        period,
                        0,
                        calendar,
                        fixedLegFrequency,
                        fixedLegConvention,
                        fixedLegDayCounter,
                        index
                        );

                    instruments.Add(swapRateHelper);

                    //testing only - works!!!
                    swapRateHelper.Dispose();
                    quoteHandle.Dispose();
                    quote.Dispose();
                    period.Dispose();

                }
                index.Dispose();
########################################################

A swapRateHelper object is added into the  instruments array, then on the
next line, it is disposed of. Well the disposed swapRateHelper object still
points to the reference stored within the array and in effect, you are also
disposing the object within the array (the swapRateHelper object has not
been assigned to another object yet).

This is true for the quote object as well.

Then this instrument array is passed to the yieldcurve and the curve then
works!!

I would run this under a debugger mate...

The only thing I can think of, is that a deep copy is being performed. If
so, the .NET version of any QuantLib code would be really slow because of
all the deep copying being performed all over the place. I cannot believe
that this is the case.

I agree that .NET garbage collection may not be that efficient within
scenarios where you are creating/deleting large amounts of objects in a very
short periofd of time.

You could, at the end of the loop, force .NET to a garbage collect. The
thing is though, if you look at the code snippet above, every object created
within the loop should still be present in memory because they are all
required for the construction of the yieldcurve latter on.

It's only when the yieldcurve is not needed that everything should be
disposed of.

The solution posed above, I would not trust at all because this kind of
logic will get you in trouble when you start mixing swig generated C#
classes and native .NET classes. You have to know when to call Dispose() and
if delivering a solution/Library to another team, they would have to have a
very detailed, inner workings, of the delivered library.

As to why the said code is acting strangly without the Dispose() call is
strange indeed.

I would suggest running the code under a debugger, tracing from the C# code
to the C++ layer.

Maybe my analysis is flawed, but if the logic above resembled a C++ snippet
where dispose are calls to delete, you will see the problem.

As a side note, calling Dispose really just calls code implemented within
the Dispose() function implemeted within the generated C# class. The
implementation of this code is generated by swig, thus you may need to look
at it...

Best Regards,
Toyin Akin
CapeTools QuantTools.
www.QuantTools.com

>From: "JURAJ HUSKA" <[hidden email]>
>To: "Luigi Ballabio" <[hidden email]>
>CC: [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Mon, 9 Jul 2007 08:51:14 -0500
>
>http://www.csharphelp.com/archives2/archive297.html
>
>Unfortunately, it isn't as deterministic as in C++, which could have been
>part of the problem, the other one is me not being (ever remotely close to)
>an expert in either of the languages...
>
>On 7/9/07, Luigi Ballabio <[hidden email]> wrote:
>>
>>On Fri, 2007-07-06 at 16:34 -0500, JURAJ HUSKA wrote:
>> > I finally solved the problem I had with evaluation date slowing down
>> > calculations, although don't quite have an explanation why my solution
>> > works.
>> >
>> > Here is the solution in words: I had to dispose of SwapRateHelper
>> > object immediately after I added it to the instruments
>> > RateHelperVector and also had to dispose of the constructed
>> > termstructure and instruments vector. See the code below.
>> > Interestingly, just disposing of the instruments vector (that is, not
>> > disposing separately of SwapRateHelpers) didn't do the job. Anyone a
>> > take on this?
>>
>>I guess the objects remained alive even though they had gone out of
>>scope. How does garbage collection in C# work?
>>
>>Luigi
>>
>>
>>--
>>
>>Discontent is the first necessity of progress.
>>-- Thomas A. Edison
>>
>>
>>


>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
>http://sourceforge.net/powerbar/db2/


>_______________________________________________
>QuantLib-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/quantlib-users

_________________________________________________________________
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

JURAJ HUSKA
Hi,

thank you for you insights, I myself am aware of the weirdness of the proposed "solution", actually it took me almost a day before I tried that obviously very illogical "method" (I guess there are other more logical ways of going about this).

All I needed was to generate discount factor curves from swap rates using historical swap rates.
I myself would suspect the generated curves are right, however, I computed the same curves using a commercial software package and the results (discount factors) coincided to 5 decimal places.

Actually, I did run the code under  a debugger and it got hung up each time the eval date was reset, in fact, the time to complete the call to the swig generated dll

"[DllImport("NQuantLibc", EntryPoint="CSharp_Settings_setEvaluationDate")]
  public static extern void Settings_setEvaluationDate(HandleRef jarg1, HandleRef jarg2);"

took each time about twice as long as the previous time(!), which made the whole computation useless after a few iterations...

Interestingly, the same calculation, with swap rates replaced by bond data (using BondRateHelper), went through smoothly (I  didn't have to do any "dispose" gymnastics at all).

I would like to understand what exatly is going on but I am afraid I don't have time to do that right now.


best,

Juraj


On 7/9/07, Toyin Akin <[hidden email]> wrote:

Hi,

The C# solution to the problem posed before looks really wierd...

If you look at the following snippet...

########################################################
for(int i=0;i<30;i++)
                {
                    Quote quote = new SimpleQuote(
Convert.ToDouble(dfData[i]/100) );
                    QuoteHandle quoteHandle = new QuoteHandle( quote );
                    NQuantLib.Period period = new Period(i+1,
NQuantLib.TimeUnit.Years );


                    RateHelper swapRateHelper = new SwapRateHelper(
                        Convert.ToDouble(dfData[i]/100),
                        period,
                        0,
                        calendar,
                        fixedLegFrequency,
                        fixedLegConvention,
                        fixedLegDayCounter,
                        index
                        );

                    instruments.Add(swapRateHelper);

                    //testing only - works!!!
                    swapRateHelper.Dispose();
                    quoteHandle.Dispose ();
                    quote.Dispose();
                    period.Dispose();

                }
                index.Dispose();
########################################################

A swapRateHelper object is added into the  instruments array, then on the
next line, it is disposed of. Well the disposed swapRateHelper object still
points to the reference stored within the array and in effect, you are also
disposing the object within the array (the swapRateHelper object has not
been assigned to another object yet).

This is true for the quote object as well.

Then this instrument array is passed to the yieldcurve and the curve then
works!!

I would run this under a debugger mate...

The only thing I can think of, is that a deep copy is being performed. If
so, the .NET version of any QuantLib code would be really slow because of
all the deep copying being performed all over the place. I cannot believe
that this is the case.

I agree that .NET garbage collection may not be that efficient within
scenarios where you are creating/deleting large amounts of objects in a very
short periofd of time.

You could, at the end of the loop, force .NET to a garbage collect. The
thing is though, if you look at the code snippet above, every object created
within the loop should still be present in memory because they are all
required for the construction of the yieldcurve latter on.

It's only when the yieldcurve is not needed that everything should be
disposed of.

The solution posed above, I would not trust at all because this kind of
logic will get you in trouble when you start mixing swig generated C#
classes and native .NET classes. You have to know when to call Dispose() and
if delivering a solution/Library to another team, they would have to have a
very detailed, inner workings, of the delivered library.

As to why the said code is acting strangly without the Dispose() call is
strange indeed.

I would suggest running the code under a debugger, tracing from the C# code
to the C++ layer.

Maybe my analysis is flawed, but if the logic above resembled a C++ snippet
where dispose are calls to delete, you will see the problem.

As a side note, calling Dispose really just calls code implemented within
the Dispose() function implemeted within the generated C# class. The
implementation of this code is generated by swig, thus you may need to look
at it...

Best Regards,
Toyin Akin
CapeTools QuantTools.
www.QuantTools.com

>From: "JURAJ HUSKA" < [hidden email]>
>To: "Luigi Ballabio" <[hidden email]>
>CC: [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Mon, 9 Jul 2007 08:51:14 -0500
>
> http://www.csharphelp.com/archives2/archive297.html
>
>Unfortunately, it isn't as deterministic as in C++, which could have been
>part of the problem, the other one is me not being (ever remotely close to)
>an expert in either of the languages...
>
>On 7/9/07, Luigi Ballabio <[hidden email]> wrote:
>>
>>On Fri, 2007-07-06 at 16:34 -0500, JURAJ HUSKA wrote:
>> > I finally solved the problem I had with evaluation date slowing down
>> > calculations, although don't quite have an explanation why my solution
>> > works.
>> >
>> > Here is the solution in words: I had to dispose of SwapRateHelper

>> > object immediately after I added it to the instruments
>> > RateHelperVector and also had to dispose of the constructed
>> > termstructure and instruments vector. See the code below.
>> > Interestingly, just disposing of the instruments vector (that is, not
>> > disposing separately of SwapRateHelpers) didn't do the job. Anyone a
>> > take on this?
>>
>>I guess the objects remained alive even though they had gone out of
>>scope. How does garbage collection in C# work?
>>
>>Luigi
>>
>>
>>--
>>
>>Discontent is the first necessity of progress.
>>-- Thomas A. Edison
>>
>>
>>


>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/


>_______________________________________________
>QuantLib-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/quantlib-users

_________________________________________________________________
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Luigi Ballabio

> On 7/9/07, Toyin Akin <[hidden email]> wrote:
>        
>         Hi,
>        
>         The C# solution to the problem posed before looks really
>         wierd...
>        
>         If you look at the following snippet...
>        
>         ########################################################
>         for(int i=0;i<30;i++)
>                         {
>                             Quote quote = new SimpleQuote(
>         Convert.ToDouble(dfData[i]/100) );
>                             QuoteHandle quoteHandle = new
>         QuoteHandle( quote );
>                             NQuantLib.Period period = new Period(i+1,
>         NQuantLib.TimeUnit.Years );
>        
>        
>                             RateHelper swapRateHelper = new
>         SwapRateHelper(
>                                 Convert.ToDouble(dfData[i]/100),
>                                 period,
>                                 0,
>                                 calendar,
>                                 fixedLegFrequency,
>                                 fixedLegConvention,
>                                 fixedLegDayCounter,
>                                 index
>                                 );
>        
>                             instruments.Add(swapRateHelper);
>        
>                             //testing only - works!!!
>                             swapRateHelper.Dispose();
>                             quoteHandle.Dispose ();
>                             quote.Dispose();
>                             period.Dispose();
>        
>                         }
>                         index.Dispose();
>         ########################################################
>        
>         A swapRateHelper object is added into the  instruments array,
>         then on the next line, it is disposed of. Well the disposed
>         swapRateHelper object still points to the reference stored
>         within the array and in effect, you are also disposing the
>         object within the array (the swapRateHelper object has not
>         been assigned to another object yet).

Not really. In the bindings, the RateHelper hides what in fact is a
shared_ptr<RateHelper>. When you add the helper to the array, you're
making a copy of the pointer. When you dispose of the original helper,
you're deleting the first pointer; but since you've made another copy
and shared_ptr is reference-counted, the actual RateHelper is still very
much alive.

Luigi


--

Vin: It's like this fellow I knew in El Paso. One day, he just took
all his clothes off and jumped in a mess of cactus. I asked him that
same question, "Why?"
Calvera: And?
Vin: He said, "It seemed like a good idea at the time."
-- The Magnificent Seven



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Toyin Akin
Hi Luigi,

Okay, so you are saying that Dispose() really plays with smart_pointers
rather than the actual data,

But it doesn't explain the fact that Dispose() needs to be called and only
in certain cases.

According to Juraj, this was needed in this case but not when he swaped
SwapHelper for BondHelper.

Dispose() should not really be called unless you are closing non .NET
resources. Resources not under the control of .NET such as files opened by
non .NET code and you need to close these ASAP, you don't have time to wait
for the garbage collector to act.

One may state the fact that the resource in this case are C++ objects,
however if as you state these are resources to smart pointers, then I don't
think this qualifies. Regular .NET objects fall under this category of
reference counted objects.

I cannot believe not deleting a few memory pointers (in this particular
example) will cause the slow down in computation here. Within the loop, if
.NET delays the deletion of the pointers until after the loop, then in
theory you would have 4*30 (roughly within this example) pointers (memory
addresses) left to be deleted at the end of the loop. But these pointers
only occupy addresses and not actual data (as you stated). This is not a lot
of memory.

And this surely cannot be the reason why the computation speed is affected.

Calling Dispose() in this manner is not natural. You have to call Dispose()
not to delete the object, but to decrement the reference count on the object
explicitly. What happens if you call Dispose() but you have not added the
object to any collection? Will the object be deleted?

It's almost like going back to the old days of when you have to call delete
yourself on newed objects but the twist in this case is that you may be
either deleting the object within the C++ layer or decrementing the
reference count.

You really need to carefully construct your program because this is not the
natural way of coding .NET applications.

If, as Juraj suggested, it works well with BondHelpers but not with
SwapHelpers, then this suggests to me a possible bug with the way
SwapHelpers are wrapped.

Having said all this, I am not a swig expert (I didn't know about the
Dispose() managing references) and thus there may be other magic at work
here and everything stated may be easily explained by some swig guru...

Best Regards,
Toyin Akin,
CapeTools QuantTools
www.QuantTools.com

>From: Luigi Ballabio <[hidden email]>
>To: JURAJ HUSKA <[hidden email]>
>CC: Toyin Akin
><[hidden email]>,[hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Tue, 10 Jul 2007 09:04:22 +0200
>
>
> > On 7/9/07, Toyin Akin <[hidden email]> wrote:
> >
> >         Hi,
> >
> >         The C# solution to the problem posed before looks really
> >         wierd...
> >
> >         If you look at the following snippet...
> >
> >         ########################################################
> >         for(int i=0;i<30;i++)
> >                         {
> >                             Quote quote = new SimpleQuote(
> >         Convert.ToDouble(dfData[i]/100) );
> >                             QuoteHandle quoteHandle = new
> >         QuoteHandle( quote );
> >                             NQuantLib.Period period = new Period(i+1,
> >         NQuantLib.TimeUnit.Years );
> >
> >
> >                             RateHelper swapRateHelper = new
> >         SwapRateHelper(
> >                                 Convert.ToDouble(dfData[i]/100),
> >                                 period,
> >                                 0,
> >                                 calendar,
> >                                 fixedLegFrequency,
> >                                 fixedLegConvention,
> >                                 fixedLegDayCounter,
> >                                 index
> >                                 );
> >
> >                             instruments.Add(swapRateHelper);
> >
> >                             //testing only - works!!!
> >                             swapRateHelper.Dispose();
> >                             quoteHandle.Dispose ();
> >                             quote.Dispose();
> >                             period.Dispose();
> >
> >                         }
> >                         index.Dispose();
> >         ########################################################
> >
> >         A swapRateHelper object is added into the  instruments array,
> >         then on the next line, it is disposed of. Well the disposed
> >         swapRateHelper object still points to the reference stored
> >         within the array and in effect, you are also disposing the
> >         object within the array (the swapRateHelper object has not
> >         been assigned to another object yet).
>
>Not really. In the bindings, the RateHelper hides what in fact is a
>shared_ptr<RateHelper>. When you add the helper to the array, you're
>making a copy of the pointer. When you dispose of the original helper,
>you're deleting the first pointer; but since you've made another copy
>and shared_ptr is reference-counted, the actual RateHelper is still very
>much alive.
>
>Luigi
>
>
>--
>
>Vin: It's like this fellow I knew in El Paso. One day, he just took
>all his clothes off and jumped in a mess of cactus. I asked him that
>same question, "Why?"
>Calvera: And?
>Vin: He said, "It seemed like a good idea at the time."
>-- The Magnificent Seven
>
>
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
>http://sourceforge.net/powerbar/db2/
>_______________________________________________
>QuantLib-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/quantlib-users

_________________________________________________________________
The next generation of Hotmail is here! http://www.newhotmail.co.uk/


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Luigi Ballabio
On Tue, 2007-07-10 at 09:31 +0100, Toyin Akin wrote:
> Okay, so you are saying that Dispose() really plays with smart_pointers
> rather than the actual data,
>
> But it doesn't explain the fact that Dispose() needs to be called and only
> in certain cases.

True.

> I cannot believe not deleting a few memory pointers (in this particular
> example) will cause the slow down in computation here. Within the loop, if
> .NET delays the deletion of the pointers until after the loop, then in
> theory you would have 4*30 (roughly within this example) pointers (memory
> addresses) left to be deleted at the end of the loop. But these pointers
> only occupy addresses and not actual data (as you stated). This is not a lot
> of memory.
>
> And this surely cannot be the reason why the computation speed is affected.

No, it cannot. The only thing that I can think of is that when the
evaluation date is reset, notifications are sent to all alive helpers
which recalculate their relevant dates and in turn notify the
corresponding yield curves. I'm not sure how much time it takes to do
that.

Luigi


--

Hanlon's Razor:
Never attribute to malice that which is adequately explained
by stupidity.



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Toyin Akin
Hi,

If the latter point is true, then this issue would/should also be present
within the c++ layer. Might be interesting to write the c++ version of this
example to compare...

Toyin Akin,
CapeTools QuantTools
www.QuantTools.com

>From: Luigi Ballabio <[hidden email]>
>To: Toyin Akin <[hidden email]>
>CC: [hidden email], [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Tue, 10 Jul 2007 10:48:28 +0200
>
>On Tue, 2007-07-10 at 09:31 +0100, Toyin Akin wrote:
> > Okay, so you are saying that Dispose() really plays with smart_pointers
> > rather than the actual data,
> >
> > But it doesn't explain the fact that Dispose() needs to be called and
>only
> > in certain cases.
>
>True.
>
> > I cannot believe not deleting a few memory pointers (in this particular
> > example) will cause the slow down in computation here. Within the loop,
>if
> > .NET delays the deletion of the pointers until after the loop, then in
> > theory you would have 4*30 (roughly within this example) pointers
>(memory
> > addresses) left to be deleted at the end of the loop. But these pointers
> > only occupy addresses and not actual data (as you stated). This is not a
>lot
> > of memory.
> >
> > And this surely cannot be the reason why the computation speed is
>affected.
>
>No, it cannot. The only thing that I can think of is that when the
>evaluation date is reset, notifications are sent to all alive helpers
>which recalculate their relevant dates and in turn notify the
>corresponding yield curves. I'm not sure how much time it takes to do
>that.
>
>Luigi
>
>
>--
>
>Hanlon's Razor:
>Never attribute to malice that which is adequately explained
>by stupidity.
>
>

_________________________________________________________________
Tell MSN about your most memorable emails!  http://www.emailbritain.co.uk/


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Luigi Ballabio
On Tue, 2007-07-10 at 10:07 +0100, Toyin Akin wrote:
> If the latter point is true, then this issue would/should also be present
> within the c++ layer. Might be interesting to write the c++ version of this
> example to compare...

Yes, I though about this. However, in the C++ version the helpers would
be automatically deleted as soon as the corresponding curve goes out of
scope at the end of the loop. Therefore, they would no longer be around
to receive notifications when the evaluation date is changed at the
beginning of the next loop. If one wanted to see the effect, one would
have to store them somewhere so that they're kept alive.

Luigi


--

The rule on staying alive as a forecaster is to give 'em a number or
give 'em a date, but never give 'em both at once.
-- Jane Bryant Quinn



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Toyin Akin
Hi,

Yes you're right.

I reckon you might have it there with the notification logic.

But if that is the case, if you write significant amount of code based on
the C# wrapper, you are likely to encounter various places where the logic
will slow down based on unneeded notifications.

Geez, It just goes to show that the garbage collection methodology doesn't
play at all well with notification messages where you have this sort of
Observer pattern. At least with the QuantLib C# wrapper anyway

I wonder how regular .NET objects work written with the Observer pattern,
where notifications are generated within a loop?

Maybe it would be possible to expose a method from the C# generated classes
to unregister itself.
However, I think that unlike the Dispose() method, this may act on all
referenced objects (the one within the array as well as itself in our loop
example).

If this is indeed true, it's hard to see an elegant solution to this.
Besides turning off notification altogether.

Toyin Akin
CapeTools QuantTools
www.QuantTools.com

>From: Luigi Ballabio <[hidden email]>
>To: Toyin Akin <[hidden email]>
>CC: [hidden email], [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Tue, 10 Jul 2007 11:33:03 +0200
>
>On Tue, 2007-07-10 at 10:07 +0100, Toyin Akin wrote:
> > If the latter point is true, then this issue would/should also be
>present
> > within the c++ layer. Might be interesting to write the c++ version of
>this
> > example to compare...
>
>Yes, I though about this. However, in the C++ version the helpers would
>be automatically deleted as soon as the corresponding curve goes out of
>scope at the end of the loop. Therefore, they would no longer be around
>to receive notifications when the evaluation date is changed at the
>beginning of the next loop. If one wanted to see the effect, one would
>have to store them somewhere so that they're kept alive.
>
>Luigi
>
>
>--
>
>The rule on staying alive as a forecaster is to give 'em a number or
>give 'em a date, but never give 'em both at once.
>-- Jane Bryant Quinn
>
>

_________________________________________________________________
Watch all 9 Live Earth concerts live on MSN.  http://liveearth.uk.msn.com


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

JURAJ HUSKA
HI,

I just tried to run the function in which I compute the yieldcurves and removed the part where I dispose of the SwapRateHelper, instead I forced garbage collection right after I run the function

GC.Collect ();
GC.WaitForPendingFinalizers();


which also fixes the problem. I am being told this isn't a great solution either as those two lines of code could affect other running processes.In any case, it seems to come down to some garbage collection issues.

Juraj


On 7/10/07, Toyin Akin <[hidden email]> wrote:
Hi,

Yes you're right.

I reckon you might have it there with the notification logic.

But if that is the case, if you write significant amount of code based on
the C# wrapper, you are likely to encounter various places where the logic
will slow down based on unneeded notifications.

Geez, It just goes to show that the garbage collection methodology doesn't
play at all well with notification messages where you have this sort of
Observer pattern. At least with the QuantLib C# wrapper anyway

I wonder how regular .NET objects work written with the Observer pattern,
where notifications are generated within a loop?

Maybe it would be possible to expose a method from the C# generated classes
to unregister itself.
However, I think that unlike the Dispose() method, this may act on all
referenced objects (the one within the array as well as itself in our loop
example).

If this is indeed true, it's hard to see an elegant solution to this.
Besides turning off notification altogether.

Toyin Akin
CapeTools QuantTools
www.QuantTools.com

>From: Luigi Ballabio <[hidden email]>
>To: Toyin Akin <[hidden email]>
>CC: [hidden email], [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Tue, 10 Jul 2007 11:33:03 +0200
>
>On Tue, 2007-07-10 at 10:07 +0100, Toyin Akin wrote:
> > If the latter point is true, then this issue would/should also be
>present
> > within the c++ layer. Might be interesting to write the c++ version of
>this
> > example to compare...
>
>Yes, I though about this. However, in the C++ version the helpers would
>be automatically deleted as soon as the corresponding curve goes out of
>scope at the end of the loop. Therefore, they would no longer be around
>to receive notifications when the evaluation date is changed at the
>beginning of the next loop. If one wanted to see the effect, one would
>have to store them somewhere so that they're kept alive.
>
>Luigi
>
>
>--
>
>The rule on staying alive as a forecaster is to give 'em a number or
>give 'em a date, but never give 'em both at once.
>-- Jane Bryant Quinn
>
>

_________________________________________________________________
Watch all 9 Live Earth concerts live on MSN.   http://liveearth.uk.msn.com



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: eval date-problem solved

Toyin Akin

Hi,

Yes it's generally not a good idea to mess with the garbage collection
internal calculation policy.

This is definatly pointing to notification problems within .NET. The same
will be true under java as this also uses the garbage collection scheme.

Best Regards,
Toyin Akin,
CapeTools QuantTools,
www.QuantTools.com

>From: "JURAJ HUSKA" <[hidden email]>
>To: "Toyin Akin" <[hidden email]>
>CC: [hidden email]
>Subject: Re: [Quantlib-users] eval date-problem solved
>Date: Tue, 10 Jul 2007 10:52:04 -0500
>
>HI,
>
>I just tried to run the function in which I compute the yieldcurves and
>removed the part where I dispose of the SwapRateHelper, instead I forced
>garbage collection right after I run the function
>
>GC.Collect();
>GC.WaitForPendingFinalizers();
>
>
>which also fixes the problem. I am being told this isn't a great solution
>either as those two lines of code could affect other running
>processes.Inany case, it seems to come down to some garbage collection
>issues.
>
>Juraj
>
>
>On 7/10/07, Toyin Akin <[hidden email]> wrote:
>>
>>Hi,
>>
>>Yes you're right.
>>
>>I reckon you might have it there with the notification logic.
>>
>>But if that is the case, if you write significant amount of code based on
>>the C# wrapper, you are likely to encounter various places where the logic
>>will slow down based on unneeded notifications.
>>
>>Geez, It just goes to show that the garbage collection methodology doesn't
>>play at all well with notification messages where you have this sort of
>>Observer pattern. At least with the QuantLib C# wrapper anyway
>>
>>I wonder how regular .NET objects work written with the Observer pattern,
>>where notifications are generated within a loop?
>>
>>Maybe it would be possible to expose a method from the C# generated
>>classes
>>to unregister itself.
>>However, I think that unlike the Dispose() method, this may act on all
>>referenced objects (the one within the array as well as itself in our loop
>>example).
>>
>>If this is indeed true, it's hard to see an elegant solution to this.
>>Besides turning off notification altogether.
>>
>>Toyin Akin
>>CapeTools QuantTools
>>www.QuantTools.com
>>
>> >From: Luigi Ballabio <[hidden email]>
>> >To: Toyin Akin <[hidden email]>
>> >CC: [hidden email], [hidden email]
>> >Subject: Re: [Quantlib-users] eval date-problem solved
>> >Date: Tue, 10 Jul 2007 11:33:03 +0200
>> >
>> >On Tue, 2007-07-10 at 10:07 +0100, Toyin Akin wrote:
>> > > If the latter point is true, then this issue would/should also be
>> >present
>> > > within the c++ layer. Might be interesting to write the c++ version
>>of
>> >this
>> > > example to compare...
>> >
>> >Yes, I though about this. However, in the C++ version the helpers would
>> >be automatically deleted as soon as the corresponding curve goes out of
>> >scope at the end of the loop. Therefore, they would no longer be around
>> >to receive notifications when the evaluation date is changed at the
>> >beginning of the next loop. If one wanted to see the effect, one would
>> >have to store them somewhere so that they're kept alive.
>> >
>> >Luigi
>> >
>> >
>> >--
>> >
>> >The rule on staying alive as a forecaster is to give 'em a number or
>> >give 'em a date, but never give 'em both at once.
>> >-- Jane Bryant Quinn
>> >
>> >
>>
>>_________________________________________________________________
>>Watch all 9 Live Earth concerts live on MSN.  http://liveearth.uk.msn.com
>>
>>

_________________________________________________________________
The next generation of Hotmail is here! http://www.newhotmail.co.uk


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users