InverseCumulativeRsg

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

InverseCumulativeRsg

andrea loddo-2
Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol , invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the dimension of the Array, is correctly set to 3 but apparently just one normal random number is generated. Is there any way to generate as many numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.

-------------------------------------------------------------------------
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: InverseCumulativeRsg

Luigi Ballabio
On Thu, 2007-05-31 at 13:12 +0100, Andrea Loddo wrote:

> What I need a random sequence generator that I instantiate in this
> way:
>
> Size dimension = 3;
> SobolRsg sobol ( dimension , 0 ) ;
> InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
> InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG
> ( sobol , invCumNorm ) ;
>
> Everything works perfectly. The only thing I don't get is the concept
> of dimensionality. I would expect the member
>
> x_.value
>
> of myRSG to be an Array of 3 elements.

Correct.

>  The member n_,  which should be the dimension of the Array, is
> correctly set to 3...

So far, so good...

>  but apparently just one normal random number is generated.

The three components of the array should hold three random numbers. What
goes wrong?

Later,
        Luigi


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

Perfection is reached, not when there is no longer anything to add, but
when there is no longer anything to take away.
-- Antoine de Saint-Exupery



-------------------------------------------------------------------------
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: InverseCumulativeRsg

DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI
In reply to this post by andrea loddo-2

 

 

Hi Andrea,

 

Here is a sample code which produces the “expected” results

 

typedef InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> SobolGenerator;

typedef SobolGenerator::sample_type SobolGeneratorSampleType;

typedef SobolGeneratorSampleType::value_type SobolGeneratorValueType;

 

void main() {

    Size dimension = 3;

    SobolRsg sobol (dimension , 0) ;

    InverseCumulativeNormal invCumNorm (0 , 1) ;

    SobolGenerator myRSG (sobol, invCumNorm);

    for (Size i=0; i< 50; ++i) {

        const SobolGeneratorSampleType& sample = myRSG.nextSequence();

        const SobolGeneratorValueType& values = sample.value;

        copy(values.begin(), values.end(), ostream_iterator<Real>( cout, "\t" ) );

        cout << "\n";

    }

}

 

hope this help,

François

 

 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 2:12 PM
To: [hidden email]
Subject: [Quantlib-users] InverseCumulativeRsg

 

Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol , invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the dimension of the Array, is correctly set to 3 but apparently just one normal random number is generated. Is there any way to generate as many numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.


-------------------------------------------------------------------------
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: InverseCumulativeRsg

andrea loddo-2
Thanks guys, everything works perfectly. :)

 Just one consideration regarding low discrepancy sequences.  If I run  your code, Francois,
as well as mine, the first sequence I get is just a series of zeros. Then the sequences start to have some variability.  But still each one of them looks everything but "random". This is due to the nature of low discrepancy sequences.

 So, let's suppose that I have to price a contingent claim, such as a plain Vanilla call option. In this case the dimension will be simply the number of time steps from the settlement date to the maturity date. Is then reasonable to have one entire path where the generated sample is either a series of zeros or it has very low variability?

Regards,
Andrea.

On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI <[hidden email]> wrote:

 

 

Hi Andrea,

 

Here is a sample code which produces the "expected" results

 

typedef InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> SobolGenerator;

typedef SobolGenerator::sample_type SobolGeneratorSampleType;

typedef SobolGeneratorSampleType::value_type SobolGeneratorValueType;

 

void main() {

    Size dimension = 3;

    SobolRsg sobol (dimension , 0) ;

    InverseCumulativeNormal invCumNorm (0 , 1) ;

    SobolGenerator myRSG (sobol, invCumNorm);

    for (Size i=0; i< 50; ++i) {

        const SobolGeneratorSampleType& sample = myRSG.nextSequence();

        const SobolGeneratorValueType& values = sample.value;

        copy(values.begin(), values.end(), ostream_iterator<Real>( cout, "\t" ) );

        cout << "\n";

    }

}

 

hope this help,

François

 

 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 2:12 PM
To: [hidden email]
Subject: [Quantlib-users] InverseCumulativeRsg

 

Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol , invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the dimension of the Array, is correctly set to 3 but apparently just one normal random number is generated. Is there any way to generate as many numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.



-------------------------------------------------------------------------
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: InverseCumulativeRsg

DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI
In reply to this post by andrea loddo-2

>But still each one of them looks everything but "random". This is due to the nature of low discrepancy sequences.

True

 

> Is then reasonable to have one entire path where the generated sample is either a series of zeros or it has very low variability?

 

Sure it is ! Using a Sobol generator will provide you with a sample which will be statistically as close as possible to the multivariate normal law. Here is the way I have understood it the first time. Read Wilmott forum or a good book like Glasserman, or Joshi’s ones for a much more detailed and clearer explanation.

Consider an example in dimension 1, say an exotic European option which has a non analytically tractable payoff. If you want to compute its value using a MC method you have to simulate a one dimensional normal law. In some way, this expectation computation can be viewed as an integral with respect to a normal measure. Alternatively it can also be viewed it as an integral with respect to the Lebesgue measure on the [0, 1] segment if one uses the following change of variable:

Y ->InverseCummulativeNormal(x).

[O,1] -> R

Then your problem is equivalent to a simple numerical integration problem. If you decide to compute this integral using a growing sequence of evaluation points then you will naturally find the Sobol sequence in one dimension …

Hope this help,

François

 

PS:

 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 4:41 PM
To: [hidden email]
Subject: Re: [Quantlib-users] InverseCumulativeRsg

 

Thanks guys, everything works perfectly. :)

 Just one consideration regarding low discrepancy sequences.  If I run  your code, Francois,
as well as mine, the first sequence I get is just a series of zeros. Then the sequences start to have some variability.  But still each one of them looks everything but "random". This is due to the nature of low discrepancy sequences.

 So, let's suppose that I have to price a contingent claim, such as a plain Vanilla call option. In this case the dimension will be simply the number of time steps from the settlement date to the maturity date. Is then reasonable to have one entire path where the generated sample is either a series of zeros or it has very low variability?

Regards,
Andrea.

On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI <[hidden email]> wrote:

 

 

Hi Andrea,

 

Here is a sample code which produces the "expected" results

 

typedef InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> SobolGenerator;

typedef SobolGenerator::sample_type SobolGeneratorSampleType;

typedef SobolGeneratorSampleType::value_type SobolGeneratorValueType;

 

void main() {

    Size dimension = 3;

    SobolRsg sobol (dimension , 0) ;

    InverseCumulativeNormal invCumNorm (0 , 1) ;

    SobolGenerator myRSG (sobol, invCumNorm);

    for (Size i=0; i< 50; ++i) {

        const SobolGeneratorSampleType& sample = myRSG.nextSequence();

        const SobolGeneratorValueType& values = sample.value;

        copy(values.begin(), values.end(), ostream_iterator<Real>( cout, "\t" ) );

        cout << "\n";

    }

}

 

hope this help,

François

 

 

-----Original Message-----
From: [hidden email][mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 2:12 PM
To: [hidden email]
Subject: [Quantlib-users] InverseCumulativeRsg

 

Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol , invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the dimension of the Array, is correctly set to 3 but apparently just one normal random number is generated. Is there any way to generate as many numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.

 


-------------------------------------------------------------------------
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: InverseCumulativeRsg

andrea loddo-2
Sure it does! I will spend some quality time reading carefully what you have just suggested me.

Thanks very much.

Andrea


On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI <[hidden email]> wrote:

>But still each one of them looks everything but "random". This is due to the nature of low discrepancy sequences.

True

 

> Is then reasonable to have one entire path where the generated sample is either a series of zeros or it has very low variability?

 

Sure it is ! Using a Sobol generator will provide you with a sample which will be statistically as close as possible to the multivariate normal law. Here is the way I have understood it the first time. Read Wilmott forum or a good book like Glasserman, or Joshi's ones for a much more detailed and clearer explanation.

Consider an example in dimension 1, say an exotic European option which has a non analytically tractable payoff. If you want to compute its value using a MC method you have to simulate a one dimensional normal law. In some way, this expectation computation can be viewed as an integral with respect to a normal measure. Alternatively it can also be viewed it as an integral with respect to the Lebesgue measure on the [0, 1] segment if one uses the following change of variable:

Y ->InverseCummulativeNormal(x).

[O,1] -> R

Then your problem is equivalent to a simple numerical integration problem. If you decide to compute this integral using a growing sequence of evaluation points then you will naturally find the Sobol sequence in one dimension …

Hope this help,

François

 

PS:

 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 4:41 PM
To: [hidden email]

Subject: Re: [Quantlib-users] InverseCumulativeRsg

 

Thanks guys, everything works perfectly. :)

 Just one consideration regarding low discrepancy sequences.  If I run  your code, Francois,
as well as mine, the first sequence I get is just a series of zeros. Then the sequences start to have some variability.  But still each one of them looks everything but "random". This is due to the nature of low discrepancy sequences.

 So, let's suppose that I have to price a contingent claim, such as a plain Vanilla call option. In this case the dimension will be simply the number of time steps from the settlement date to the maturity date. Is then reasonable to have one entire path where the generated sample is either a series of zeros or it has very low variability?

Regards,
Andrea.

On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI <[hidden email]> wrote:

 

 

Hi Andrea,

 

Here is a sample code which produces the "expected" results

 

typedef InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> SobolGenerator;

typedef SobolGenerator::sample_type SobolGeneratorSampleType;

typedef SobolGeneratorSampleType::value_type SobolGeneratorValueType;

 

void main() {

    Size dimension = 3;

    SobolRsg sobol (dimension , 0) ;

    InverseCumulativeNormal invCumNorm (0 , 1) ;

    SobolGenerator myRSG (sobol, invCumNorm);

    for (Size i=0; i< 50; ++i) {

        const SobolGeneratorSampleType& sample = myRSG.nextSequence();

        const SobolGeneratorValueType& values = sample.value;

        copy(values.begin(), values.end(), ostream_iterator<Real>( cout, "\t" ) );

        cout << "\n";

    }

}

 

hope this help,

François

 

 

-----Original Message-----
From: [hidden email][mailto:[hidden email]] On Behalf Of Andrea Loddo
Sent:
Thursday, May 31, 2007 2:12 PM
To: [hidden email]
Subject: [Quantlib-users] InverseCumulativeRsg

 

Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol , invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the dimension of the Array, is correctly set to 3 but apparently just one normal random number is generated. Is there any way to generate as many numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.

 



-------------------------------------------------------------------------
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: InverseCumulativeRsg

Giuseppe Castellacci
Just as a footnote to Francois's explanation,

the inverse (possibly quasi-inverse if F is not
continuous) invF of any distribution F transforms uniform
variates into variates that are distributed as the
original distribution F. Therefore, an array of numbers close to zero
corresponds to F-distributed variates in the far left tail of the
distribution.
Obviously, invF amplifies the dispersion of the uniform
variates in the same way that d(invF) stretches the length
of subintervals of [0,1], so that numbers that seem nearly identical become
more "random" after application of invF.

In dimension n, one can first generate an n-vector with
F-distributed components by taking invF n times.
Then one must come up with a dependence structure.
(This is pretty hard in general and theoretically related
to copulas. In some cases, such as Student t, one can
reduce random variate generation to a multi-normal one together
with some other scalar variate generation, chi^2 in the Student
t case)
In the multi-normal case one can simply multiply
the vector by a Cholesky decomposition of the
target covariance matrix. (One of the reasons why Gaussian
processes are so popular!)

Hope this helps!



Giuseppe



----- Original Message -----
From: Andrea Loddo
To: [hidden email]
Sent: Thursday, May 31, 2007 2:06 PM
Subject: Re: [Quantlib-users] InverseCumulativeRsg


Sure it does! I will spend some quality time reading carefully what you
have just suggested me.

Thanks very much.

Andrea



On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI
<[hidden email]> wrote:
>But still each one of them looks everything but "random". This is due to
>the nature of low discrepancy sequences.
True

> Is then reasonable to have one entire path where the generated sample is
> either a series of zeros or it has very low variability?

Sure it is ! Using a Sobol generator will provide you with a sample which
will be statistically as close as possible to the multivariate normal law.
Here is the way I have understood it the first time. Read Wilmott forum or
a good book like Glasserman, or Joshi's ones for a much more detailed and
clearer explanation.
Consider an example in dimension 1, say an exotic European option which has
a non analytically tractable payoff. If you want to compute its value using
a MC method you have to simulate a one dimensional normal law. In some way,
this expectation computation can be viewed as an integral with respect to a
normal measure. Alternatively it can also be viewed it as an integral with
respect to the Lebesgue measure on the [0, 1] segment if one uses the
following change of variable:
Y ->InverseCummulativeNormal(x).
[O,1] -> R
Then your problem is equivalent to a simple numerical integration problem.
If you decide to compute this integral using a growing sequence of
evaluation points then you will naturally find the Sobol sequence in one
dimension …
Hope this help,
François

PS:

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Andrea
Loddo
Sent: Thursday, May 31, 2007 4:41 PM
To: [hidden email]

Subject: Re: [Quantlib-users] InverseCumulativeRsg

Thanks guys, everything works perfectly. :)

 Just one consideration regarding low discrepancy sequences.  If I run
your code, Francois,
as well as mine, the first sequence I get is just a series of zeros. Then
the sequences start to have some variability.  But still each one of them
looks everything but "random". This is due to the nature of low discrepancy
sequences.

 So, let's suppose that I have to price a contingent claim, such as a plain
Vanilla call option. In this case the dimension will be simply the number
of time steps from the settlement date to the maturity date. Is then
reasonable to have one entire path where the generated sample is either a
series of zeros or it has very low variability?

Regards,
Andrea.
On 5/31/07, DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI
<[hidden email] > wrote:


Hi Andrea,

Here is a sample code which produces the "expected" results

typedef InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal>
SobolGenerator;
typedef SobolGenerator::sample_type SobolGeneratorSampleType;
typedef SobolGeneratorSampleType::value_type SobolGeneratorValueType;

void main() {
    Size dimension = 3;
    SobolRsg sobol (dimension , 0) ;
    InverseCumulativeNormal invCumNorm (0 , 1) ;
    SobolGenerator myRSG (sobol, invCumNorm);
    for (Size i=0; i< 50; ++i) {
        const SobolGeneratorSampleType& sample = myRSG.nextSequence();
        const SobolGeneratorValueType& values = sample.value;
        copy(values.begin(), values.end(), ostream_iterator<Real>( cout,
"\t" ) );
        cout << "\n";
    }
}

hope this help,
François


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Andrea
Loddo
Sent: Thursday, May 31, 2007 2:12 PM
To: [hidden email]
Subject: [Quantlib-users] InverseCumulativeRsg

Hi all,

What I need a random sequence generator that I instantiate in this way:

Size dimension = 3;
SobolRsg sobol ( dimension , 0 ) ;
InverseCumulativeNormal invCumNorm ( 0 , 1 ) ;
InverseCumulativeRsg<SobolRsg , InverseCumulativeNormal> myRSG ( sobol ,
invCumNorm ) ;

Everything works perfectly. The only thing I don't get is the concept of
dimensionality. I would expect the member

x_.value

of myRSG to be an Array of 3 elements. The member n_,  which should be the
dimension of the Array, is correctly set to 3 but apparently just one
normal random number is generated. Is there any way to generate as many
numbers as I need through the parameter dimension?

Any help will be appreciated.

Andrea.






-------------------------------------------------------------------------
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 


-------------------------------------------------------------------------
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