Click here to Skip to main content
15,913,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Online c/c++ question sites ? Pin
vikas amin8-Jan-06 8:01
vikas amin8-Jan-06 8:01 
QuestionCTreeCtrl::GetCheck() Pin
LiYS7-Jan-06 21:03
LiYS7-Jan-06 21:03 
Questionquestion about classes without data Pin
neodeaths7-Jan-06 20:10
neodeaths7-Jan-06 20:10 
AnswerRe: question about classes without data Pin
Prakash Nadar7-Jan-06 21:12
Prakash Nadar7-Jan-06 21:12 
GeneralRe: question about classes without data Pin
vikas amin7-Jan-06 22:28
vikas amin7-Jan-06 22:28 
GeneralRe: question about classes without data Pin
Prakash Nadar7-Jan-06 22:31
Prakash Nadar7-Jan-06 22:31 
GeneralRe: question about classes without data Pin
vikas amin7-Jan-06 23:02
vikas amin7-Jan-06 23:02 
AnswerRe: question about classes without data Pin
Prakash Nadar7-Jan-06 22:32
Prakash Nadar7-Jan-06 22:32 
QuestionBFFM_SETSELECTION question Pin
nm_1147-Jan-06 19:51
nm_1147-Jan-06 19:51 
AnswerRe: BFFM_SETSELECTION question Pin
Prakash Nadar7-Jan-06 21:16
Prakash Nadar7-Jan-06 21:16 
GeneralRe: BFFM_SETSELECTION question Pin
nm_1148-Jan-06 6:28
nm_1148-Jan-06 6:28 
GeneralRe: BFFM_SETSELECTION question Pin
Prakash Nadar8-Jan-06 14:58
Prakash Nadar8-Jan-06 14:58 
GeneralRe: BFFM_SETSELECTION question Pin
nm_1148-Jan-06 17:01
nm_1148-Jan-06 17:01 
GeneralRe: BFFM_SETSELECTION question Pin
Prakash Nadar8-Jan-06 17:36
Prakash Nadar8-Jan-06 17:36 
GeneralRe: BFFM_SETSELECTION question Pin
nm_1148-Jan-06 18:40
nm_1148-Jan-06 18:40 
Questionquestions about pointers Pin
neodeaths7-Jan-06 19:28
neodeaths7-Jan-06 19:28 
AnswerRe: questions about pointers Pin
Prakash Nadar7-Jan-06 20:58
Prakash Nadar7-Jan-06 20:58 
AnswerRe: questions about pointers Pin
vikas amin7-Jan-06 21:52
vikas amin7-Jan-06 21:52 
GeneralRe: questions about pointers Pin
Prakash Nadar7-Jan-06 22:01
Prakash Nadar7-Jan-06 22:01 
QuestionWhy the application could not run at Windows XP? Pin
rushing7-Jan-06 17:22
rushing7-Jan-06 17:22 
AnswerRe: Why the application could not run at Windows XP? Pin
Prakash Nadar7-Jan-06 21:44
Prakash Nadar7-Jan-06 21:44 
QuestionGDI+ Visual C++ wrapper class operators missing? Pin
bob169727-Jan-06 15:03
bob169727-Jan-06 15:03 
Questionask one question in VC .NET Pin
Pierre,Hsieh7-Jan-06 13:51
Pierre,Hsieh7-Jan-06 13:51 
I want to build a win32 console program in VC .Net. I wrote one function in random1.h and random1.cpp, Then, I wrote my main program in SimMCMain.cpp which call this function from random1.h and random1.cpp. It's no problem in VC++ 6.0, but it always has problem when linking in VC.Net. Can anyone give me some suggestion? Thanks


****random1.h***
#ifndef RANDOM1_H
#define RANDOM1_H

double GetOneGaussianBySummation();
double GetOneGaussianByBoxMuller();

#endif


****random1.cpp****
#include <cstdlib>
#include <cmath>

// the basic math functions should be in namespace
// std but aren't in VCPP6
#if !defined(_MSC_VER)
using namespace std;
#endif

double GetOneGaussianBySummation()
{
double result=0;

for (unsigned long j=0; j < 12; j++)
result += rand()/static_cast<double>(RAND_MAX);

result -= 6.0;

return result;
}

double GetOneGaussianByBoxMuller()
{
double result;

double x;
double y;

double sizeSquared;
do
{
x = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
y = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
sizeSquared = x*x + y*y;
}
while
( sizeSquared >= 1.0);

result = x*sqrt(-2*log(sizeSquared)/sizeSquared);

return result;
}


****SimMCMain.cpp ****
// requires Random1.cpp
#include <Random1.h>
#include <iostream>
#include <cmath>
using namespace std;

double SimpleMonteCarlo1(double Expiry,
double Strike,
double Spot,
double Vol,
double r,
unsigned long NumberOfPaths)
{
double variance = Vol*Vol*Expiry;
double rootVariance = sqrt(variance);
double itoCorrection = -0.5*variance;

double movedSpot = Spot*exp(r*Expiry +itoCorrection);
double thisSpot;
double runningSum=0;

for (unsigned long i=0; i < NumberOfPaths; i++)
{
double thisGaussian = GetOneGaussianByBoxMuller();
thisSpot = movedSpot*exp( rootVariance*thisGaussian);
double thisPayoff = thisSpot - Strike;
thisPayoff = thisPayoff >0 ? thisPayoff : 0;
runningSum += thisPayoff;
}

double mean = runningSum / NumberOfPaths;
mean *= exp(-r*Expiry);
return mean;
}

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

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

cout << "\nEnter strike\n";
cin >> Strike;

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

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

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

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

double result = SimpleMonteCarlo1(Expiry,
Strike,
Spot,
Vol,
r,
NumberOfPaths);

cout <<"the price is " << result << "\n";

double tmp;
cin >> tmp;

return 0;
}

AnswerRe: ask one question in VC .NET Pin
PJ Arends7-Jan-06 14:02
professionalPJ Arends7-Jan-06 14:02 
GeneralRe: ask one question in VC .NET Pin
Pierre,Hsieh7-Jan-06 14:14
Pierre,Hsieh7-Jan-06 14:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.