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


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


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

Could anyone help me?


Mon, 16 Dec 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. For loops into for loops

2. hate the do-while loop (Re: ugly loop; hate the ! operator)

3. Loop or Loops in "C"

4. (Newbie) My Loop Isn't Looping - Aargh!

5. SEMA - WHILE loop in a FOR loop !

6. wanted - C and/or Fortran source for 24-loop Livermore Loops

7. My Loop Now Loops! Thanks!

8. process loops but 'context' doesn't show me where it loops

9. Loop of loops. Any nice solution?

10. For loop design ( Brief Lesson )

11. For loop design part two

12. For loop Design


Powered by phpBB® Forum Software