Bug in MCAmericanBasketEngine class

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

Bug in MCAmericanBasketEngine class

Joseph Wang
Can you add the following lines and see if it fixes things....

If it works I'll write a regression test case for it, and check it into CVS.

        std::vector<MultiPath> multipaths(N);
        for (i=0; i<N/2; i++) {
            multipaths[i] = multipathGenerator->next().value;
            multipaths[N/2+i] = multipathGenerator->antithetic().value;
        }
        // Add an extra path if N is odd
        if (N % 2 == 1) {
            multipaths[N-1] = multipathGenerator->next().value;
        }




Reply | Threaded
Open this post in threaded view
|

Re: Bug in MCAmericanBasketEngine class

Luigi Ballabio
On Oct 9, 2005, at 6:12 PM, Joseph Wang wrote:

> Can you add the following lines and see if it fixes things....
>
>        std::vector<MultiPath> multipaths(N);
>        for (i=0; i<N/2; i++) {
>            multipaths[i] = multipathGenerator->next().value;
>            multipaths[N/2+i] = multipathGenerator->antithetic().value;
>        }
>        // Add an extra path if N is odd
>        if (N % 2 == 1) {
>            multipaths[N-1] = multipathGenerator->next().value;
>        }

Isn't it enough to make N even if it's not? At its declaration site,
you can write:

Size N = requiredSamples_ + (requiredSamples_ % 2);

Luigi




Reply | Threaded
Open this post in threaded view
|

Re: Bug in MCAmericanBasketEngine class

Joseph Wang
That would also work....  Do you want to add it or should I.

I've also added a test to the test suite that replacates the crash which
I can check in once the fix is in place.

Also, I've been reading up on Monte Carlo.  Chapter 10 of Peter Jackel's
book Monte Carlo Methods in Finance says that antithetic sampling should
not be used with low-discrepency series (especially Sobol numbers) as it
will case interaction effects given that the quasi-random numbers are
also almost antihetic.

Does this have any impact on the code?


Luigi Ballabio wrote:

>
> On Oct 9, 2005, at 6:12 PM, Joseph Wang wrote:
>
>> Can you add the following lines and see if it fixes things....
>>
>>        std::vector<MultiPath> multipaths(N);
>>        for (i=0; i<N/2; i++) {
>>            multipaths[i] = multipathGenerator->next().value;
>>            multipaths[N/2+i] = multipathGenerator->antithetic().value;
>>        }
>>        // Add an extra path if N is odd
>>        if (N % 2 == 1) {
>>            multipaths[N-1] = multipathGenerator->next().value;
>>        }
>
>
> Isn't it enough to make N even if it's not? At its declaration site,
> you can write:
>
> Size N = requiredSamples_ + (requiredSamples_ % 2);
>
> Luigi
>



Reply | Threaded
Open this post in threaded view
|

Re: Bug in MCAmericanBasketEngine class

Luigi Ballabio
On 10/09/2005 08:28:43 PM, Joseph Wang wrote:
> That would also work....  Do you want to add it or should I.

Please go ahead.

> Also, I've been reading up on Monte Carlo.  Chapter 10 of Peter  
> Jackel's book Monte Carlo Methods in Finance says that antithetic  
> sampling should not be used with low-discrepency series (especially  
> Sobol numbers) as it will case interaction effects given that the  
> quasi-random numbers are also almost antihetic.
> Does this have any impact on the code?

Probably. The antithetic sampling shouldn't be performed no matter  
what---there should be a flag passed to the engine specifying whether  
or not it should be enabled.

Later,
        Luigi

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

Steinbach's Guideline for Systems Programming:
        Never test for an error condition you don't know how to handle.