I need quick answer for this

When & is used in this way SimpleMonetCarlo(const PayOff& thePayOff) what does it mean.

Also like this Numeric CND(const Numeric& d)
Take the address of.
http://www.cplusplus.com/doc/tutorial/pointers/


edit: I misread those as function calls, not function headers.
Last edited on
Contrary to what AbstractionAnon just said, the apersand & is used in the context to make thePayOff a reference to objects of type PayOff const and similarly for d being a reference to objects of type Numeric const

To avoid confusion with pointers, I generally don't tend to use & to take address of - I use std::addressof
Last edited on
@ LB (9988), thank you very muck for your help. I appreciate
@LB need your help once again. I came across this below in my C++ pattern and design with Joshi what does it mean:

double thisSpot;
double thisPayoff = thePayOff(thisSpot);
There is not enough context for me to know what that means.
Here is the complete program:

#include "JoshiOption.hpp" //JoshiOption.cpp
#include "Fns.hpp"
#include <minmax.h>
#include <cmath>
using namespace std;
PayOff::PayOff(double Strike_, OptionType TheOptionsType_)
:
Strike(Strike_), TheOptionsType(TheOptionsType_)
{
}

double PayOff::operator ()(double spot) const
{
switch (TheOptionsType)
{
case call :
return max(spot-Strike,0.0);
case put:
return max(Strike-spot,0.0);
default:
throw("unknown option type found.");

double SimpleMonteCarlo2(const PayOff& thePayOff, double Expiry, 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 = thePayOff(thisSpot);
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *=exp(-r*Expiry);
return mean;
}

thePayOff is a PayOff instance, and the PayOff class has a definition for double operator()(double) meaning that you can treat thePayOff as if it were a function that took a double and returned a double.
Last edited on
thanks once again
Topic archived. No new replies allowed.