For loops into for loops
Author Message For loops into for loops

I've got big problems with a for loop into another for loop.
I report below the piece of code.

---------------------
sgenrand(rand() %(RAND_MAX+1)); // Random seed of the pseudorandom sequence
for (int i=0;  i< no_steps; ++i)
{
double y = genrand1(); // random numbers
S_t = S_t * exp(R + SD * cndev(y));
prices[i]=S_t;   // The array

};

//..... some manipulations
double price = sum_c_max* (exp (-r*time));  // The result
---------------------

I'd like to calculate "double price" n times with different random numbers
in order to obtain the average of such values.
I thought that i needed to put this process into another for loop.
But i don't know how to do that.
I did as follows, but that gives wrong results:

for (int j=0;  j< no_paths; ++j)
{
sgenrand(rand() %(RAND_MAX+1));

for (int i=0;  i< no_steps; ++i)
{

double y = genrand1();
S_t = S_t * exp(R + SD * cndev(y));
prices[i]=S_t;

};

m = *max_element(prices.begin(),prices.end()); // the max value of the
array
tx = prices.back(); // the last value
if (m > bar)
sum_c_max  += max(0.0, tx - X) ;

Quote:
}

double price = sum_c_max * exp (-r*time) / no_paths;

Could anyone help me?

MAX
--

Mon, 16 Dec 2002 03:00:00 GMT

 Page 1 of 1 [ 1 post ]

Relevant Pages