| delorie.com/archives/browse.cgi | search |
| From: | "godsofmetal" <godsofmetal AT tiscalinet DOT it> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | For loops. |
| Date: | Thu, 29 Jun 2000 10:27:18 +0200 |
| Organization: | Tiscali Spa |
| Lines: | 50 |
| Message-ID: | <8jf17o$j2a$1@lacerta.tiscalinet.it> |
| NNTP-Posting-Host: | mi3-645.dialup.tiscalinet.it |
| X-Trace: | lacerta.tiscalinet.it 962267192 19530 62.11.62.5 (29 Jun 2000 08:26:32 GMT) |
| X-Complaints-To: | newsadmin AT tiscali DOT it |
| NNTP-Posting-Date: | 29 Jun 2000 08:26:32 GMT |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2014.211 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2014.211 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
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) ;
}
double price = sum_c_max * exp (-r*time) / no_paths;
Could anyone help me?
MAX
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |