Click here to Skip to main content
15,888,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: ask one question in VC .NET Pin
PJ Arends7-Jan-06 14:44
professionalPJ Arends7-Jan-06 14:44 
GeneralRe: ask one question in VC .NET Pin
Pierre,Hsieh7-Jan-06 15:03
Pierre,Hsieh7-Jan-06 15:03 
QuestionRe: ask one question in VC .NET Pin
David Crow7-Jan-06 17:15
David Crow7-Jan-06 17:15 
QuestionSimulating mouse clicks Pin
Still learning how to code7-Jan-06 11:46
Still learning how to code7-Jan-06 11:46 
AnswerRe: Simulating mouse clicks Pin
vipinasda7-Jan-06 12:04
vipinasda7-Jan-06 12:04 
GeneralRe: Simulating mouse clicks Pin
Still learning how to code7-Jan-06 21:15
Still learning how to code7-Jan-06 21:15 
AnswerRe: Simulating mouse clicks Pin
#realJSOP8-Jan-06 3:00
mve#realJSOP8-Jan-06 3:00 
GeneralRe: Simulating mouse clicks Pin
Still learning how to code8-Jan-06 5:41
Still learning how to code8-Jan-06 5:41 
AnswerRe: Simulating mouse clicks Pin
Stephen Hewitt9-Jan-06 11:47
Stephen Hewitt9-Jan-06 11:47 
Question[Message Deleted] Pin
S.C.Wong7-Jan-06 6:08
S.C.Wong7-Jan-06 6:08 
AnswerRe: How to add an ActiveX control in another ActiveX control? Pin
Prakash Nadar7-Jan-06 18:05
Prakash Nadar7-Jan-06 18:05 
Questionhow to pass a class ,object to a function by using pointers? Pin
neodeaths7-Jan-06 4:32
neodeaths7-Jan-06 4:32 
AnswerRe: how to pass a class ,object to a function by using pointers? Pin
Prakash Nadar7-Jan-06 4:46
Prakash Nadar7-Jan-06 4:46 
GeneralRe: how to pass a class ,object to a function by using pointers? Pin
neodeaths7-Jan-06 4:56
neodeaths7-Jan-06 4:56 
GeneralRe: how to pass a class ,object to a function by using pointers? Pin
Prakash Nadar7-Jan-06 5:09
Prakash Nadar7-Jan-06 5:09 

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.