Re: eval date-problem solved

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/eval-date-problem-solved-tp1121p1126.html


> 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