## AntiThetic::Skip

This forum is to discuss the book "C++ design patterns and derivatives pricing."

### AntiThetic::Skip

Hi, I have a question about the AntiThetic Skip member function. I'm unsure if it is working properly or if my understanding is flawed. Here's the code for reference:
Code: Select all
`void AntiThetic::Skip(unsigned long numberOfPaths){    if (numberOfPaths ==0)        return;    if (OddEven)    {        OddEven = false;        numberOfPaths--;    }    InnerGenerator->Skip(numberOfPaths  / 2);    if (numberOfPaths % 2)    {        MJArray tmp(GetDimensionality());        GetUniforms(tmp);    }}`

First, I am assuming that when skipping numberOfPaths paths, this means we skip numberOfPaths/2 (+1 if numberOfPaths odd) new variates from the inner generator, and numberOfPaths/2 antithetic samples.

Now consider a sample case:
OddEven = true - next sample should be a new variate from InnerGenerator, and
numberOfPaths = 4

The Skip function will:
1. Set OddEven = false
2. Set numberOfPaths = 3
3. Skip 1 variate in the InnerGenerator
4. Call GetUniforms(tmp), essentially just setting OddEven = true
5. return

On the next call we get a new variate, which is fine. Except that the InnerGenerator has only skipped 1 path, instead of the needed 2.

I have similar troubles using different combinations of OddEven and numberOfPaths.

There's also a possible bug?
Suppose the user decides to skip an odd number of paths immediately after creating an AntiThetic object. In this case the Skip function will:
1. Set OddEven = false
2. Make numberOfPaths even
3. Skip numberOfPaths/2 paths in the InnerGenerator
4. return

So OddEven is left false, but NextVariates has not been set to anything. The next call to GetUniforms will return rubbish.

sham

Posts: 4
Joined: Thu May 19, 2011 2:47 am

### Re: AntiThetic::Skip

I think there is a bug here.
mj

Posts: 1380
Joined: Fri Jul 27, 2007 7:21 am

### Re: AntiThetic::Skip

If the first few lines are just changed to:

Code: Select all
`if (!OddEven)    {        OddEven = true;        numberOfPaths--;    }`

Then I think it's okay.
sham

Posts: 4
Joined: Thu May 19, 2011 2:47 am