Boost random library

Hi,

I am trying to use Boost's random generator class in my code using the adaptor pattern.

However, i have the following error message :

1>------ Build started: Project: ex12.2, Configuration: Debug Win32 ------
1>Compiling...
1>PathDependentExoticOption.cpp
1>c:\moondragon\distancelearning\cpp\code\ex12.2\pathdependentexoticoption.cpp(82) : error C3203: 'uniform_int' : unspecialized class template can't be used as a template argument for template parameter 'UniformRandomNumberGenerator', expected a real type
1>c:\moondragon\distancelearning\cpp\code\ex12.2\pathdependentexoticoption.cpp(82) : error C2955: 'boost::uniform_int' : use of class template requires template argument list
1> c:\boost\boost_1_39\boost\random\uniform_int.hpp(39) : see declaration of 'boost::uniform_int'
1>c:\moondragon\distancelearning\cpp\code\ex12.2\pathdependentexoticoption.cpp(82) : error C2990: 'BoostRandom' : non-class template has already been declared as a class template
1> c:\designcpp\include\boostrandom.h(9) : see declaration of 'BoostRandom'
1>c:\moondragon\distancelearning\cpp\code\ex12.2\pathdependentexoticoption.cpp(82) : error C2514: 'BoostRandom' : class has no constructors
1> c:\designcpp\include\boostrandom.h(9) : see declaration of 'BoostRandom'
1>Build log was saved at "file://c:\MoonDragon\DistanceLearning\cpp\code\ex12.2\Debug\BuildLog.htm"
1>ex12.2 - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



The two files involved are bellow.

Thanks in advance for your help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//                      BoostRandom.h

#ifndef BOOST_RANDOM_H
#define BOOST_RANDOM_H
#include <Random2.h>

#include <boost/random/random_number_generator.hpp>

template<class UniformRandomNumberGenerator, class IntType = long> class BoostRandom : public RandomBase  //The adaptor class
{
public:

    BoostRandom(unsigned long Dimensionality, unsigned long Seed=1);

    virtual RandomBase* clone() const;    
    virtual void GetUniforms(MJArray& variates);    
    virtual void Skip(unsigned long numberOfPaths);
    virtual void SetSeed(unsigned long Seed);
    virtual void Reset();
    virtual void ResetDimensionality(unsigned long NewDimensionality);

private:

	boost::random_number_generator <UniformRandomNumberGenerator, IntType> InnerGenerator; //One 'plug' Boost here!
    unsigned long InitialSeed;
    double Reciprocal;

};


template<class UniformRandomNumberGenerator, class IntType> BoostRandom <UniformRandomNumberGenerator , IntType>::BoostRandom(unsigned long Dimensionality, unsigned long Seed)
:    RandomBase(Dimensionality),  InnerGenerator(Seed),  InitialSeed(Seed)
{
	debugFlowTracer flow("BoostRandom::BoostRandom");

    Reciprocal = 1/(1.0+InnerGenerator.Max());
}

template<class UniformRandomNumberGenerator, class IntType> RandomBase* BoostRandom <UniformRandomNumberGenerator , IntType>::clone() const
{
    return new BoostRandom(*this);   
}

template<class UniformRandomNumberGenerator, class IntType> void BoostRandom <UniformRandomNumberGenerator , IntType>::GetUniforms(MJArray& variates)
{
	debugFlowTracer flow("BoostRandom::GetUniforms");

    for (unsigned long j=0; j < GetDimensionality(); j++)
        variates[j] = InnerGenerator.GetOneRandomInteger()*Reciprocal;

}
    
template<class UniformRandomNumberGenerator, class IntType> void BoostRandom <UniformRandomNumberGenerator , IntType>::Skip(unsigned long numberOfPaths)
{
	debugFlowTracer flow("BoostRandom::Skip");

    MJArray tmp(GetDimensionality());
    for (unsigned long j=0; j < numberOfPaths; j++)
        GetUniforms(tmp);
}

template<class UniformRandomNumberGenerator, class IntType> void BoostRandom <UniformRandomNumberGenerator , IntType>::SetSeed(unsigned long Seed)
{
	debugFlowTracer flow("BoostRandom::SetSeed");

    InitialSeed = Seed;
    InnerGenerator.SetSeed(Seed);
}

template<class UniformRandomNumberGenerator, class IntType> void BoostRandom <UniformRandomNumberGenerator , IntType>::Reset()
{
	debugFlowTracer flow("BoostRandom::Reset");

    InnerGenerator.SetSeed(InitialSeed);
}

template<class UniformRandomNumberGenerator, class IntType> void BoostRandom <UniformRandomNumberGenerator , IntType>::ResetDimensionality(unsigned long NewDimensionality)
{
	debugFlowTracer flow("BoostRandom::ResetDimensionality");

    RandomBase::ResetDimensionality(NewDimensionality);
    InnerGenerator.SetSeed(InitialSeed);
}
#endif 




The second file is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//		PathDependentExoticOption.cpp
/*
    uses source files 
    AntiThetic.cpp
    Arrays.cpp,  
    ConvergenceTable.cpp, 
    ExoticBSEngine.cpp
    ExoticEngine
    MCStatistics.cpp
    Normals.cpp
    Parameters.cpp,
    PathDependent.cpp
    PathDependentAsian.cpp
    PayOff3.cpp, 
    PayOffBridge.cpp,
    Random2.cpp,
  */
#include<BoostRandom.h>
#include<MCStatistics.h>
#include<ConvergenceTable.h>
#include<AntiThetic.h>
#include<PathDependentAsian.h>
#include<ExoticBSEngine.h>
#include <FlowTracerManager.h>
#include<iostream>
using namespace std;

int main()
{
	double Expiry;
	double Strike; 
	double Spot; 
	double Vol; 
	double r;
    double d;
	unsigned long NumberOfPaths;
    unsigned NumberOfDates;

	cout << "\nEnter expiry\n";
	cin >> Expiry;


	cout << "\nStrike\n";
	cin >> Strike;


	cout << "\nEnter spot\n";
	cin >> Spot;

	cout << "\nEnter vol\n";
	cin >> Vol;


	cout << "\nr\n";
	cin >> r;

    cout << "\nd\n";
    cin >> d;

    cout << "Number of dates\n";
    cin >> NumberOfDates;

	cout << "\nNumber of paths\n";
	cin >> NumberOfPaths;

    PayOffCall thePayOff(Strike);

    MJArray times(NumberOfDates);

    for (unsigned long i=0; i < NumberOfDates; i++)
        times[i] = (i+1.0)*Expiry/NumberOfDates;

    ParametersConstant VolParam(Vol);
    ParametersConstant rParam(r);
    ParametersConstant dParam(d);

    PathDependentAsian theOption(times, Expiry, thePayOff);

    StatisticsMean gatherer;
    ConvergenceTable gathererTwo(gatherer);

	class BoostRandom <boost::uniform_int, long> generator(NumberOfDates);
    
    AntiThetic GenTwo(generator);

    ExoticBSEngine theEngine(theOption, rParam, dParam, VolParam, GenTwo, Spot);

    theEngine.DoSimulation(gathererTwo, NumberOfPaths);

    vector<vector<double> > results =gathererTwo.GetResultsSoFar();

	cout <<"\nFor the Asian call price the results are \n";
  
    {
		for (unsigned long i=0; i < results.size(); i++)
		{
			for (unsigned long j=0; j < results[i].size(); j++)
				cout << results[i][j] << " ";

			cout << "\n";
		}
	}

    double tmp;
    cin >> tmp;

	return 0;
}

Maybe you need to specify the template argument when using the type as a template argument boost::uniform_int<int>
Hi,

Sorry for the delay.

After the correction based on your advise i have presently the error message below :

1>------ Build started: Project: ex12.2, Configuration: Debug Win32 ------
1>Compiling...
1>PathDependentExoticOption.cpp
1>c:\designcpp\include\boostrandom.h(33) : error C2664: 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>::random_number_generator(boost::uniform_int<int> &)' : cannot convert parameter 1 from 'unsigned long' to 'boost::uniform_int<IntType> &'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> and
1> [
1> IntType=int
1> ]
1> c:\designcpp\include\boostrandom.h(32) : while compiling class template member function 'BoostRandom<UniformRandomNumberGenerator,IntType>::BoostRandom(unsigned long,unsigned long)'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> c:\moondragon\distancelearning\cpp\code\ex12.2\pathdependentexoticoption.cpp(82) : see reference to class template instantiation 'BoostRandom<UniformRandomNumberGenerator,IntType>' being compiled
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>c:\designcpp\include\boostrandom.h(36) : error C2039: 'Max' : is not a member of 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>c:\designcpp\include\boostrandom.h(49) : error C2039: 'GetOneRandomInteger' : is not a member of 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> c:\designcpp\include\boostrandom.h(45) : while compiling class template member function 'void BoostRandom<UniformRandomNumberGenerator,IntType>::GetUniforms(MJArray &)'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>c:\designcpp\include\boostrandom.h(67) : error C2039: 'SetSeed' : is not a member of 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> c:\designcpp\include\boostrandom.h(63) : while compiling class template member function 'void BoostRandom<UniformRandomNumberGenerator,IntType>::SetSeed(unsigned long)'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>c:\designcpp\include\boostrandom.h(74) : error C2039: 'SetSeed' : is not a member of 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> c:\designcpp\include\boostrandom.h(71) : while compiling class template member function 'void BoostRandom<UniformRandomNumberGenerator,IntType>::Reset(void)'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>c:\designcpp\include\boostrandom.h(82) : error C2039: 'SetSeed' : is not a member of 'boost::random_number_generator<UniformRandomNumberGenerator,IntType>'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1> c:\designcpp\include\boostrandom.h(78) : while compiling class template member function 'void BoostRandom<UniformRandomNumberGenerator,IntType>::ResetDimensionality(unsigned long)'
1> with
1> [
1> UniformRandomNumberGenerator=boost::uniform_int<int>,
1> IntType=long
1> ]
1>Build log was saved at "file://c:\MoonDragon\DistanceLearning\cpp\code\ex12.2\Debug\BuildLog.htm"
1>ex12.2 - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Topic archived. No new replies allowed.