# I Need Some Help

Page 1 of 1

## 8 Replies - 1896 Views - Last Post: 06 February 2005 - 01:35 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=10222&amp;s=422f0efb0cb5e26b4d82dbc5546ba072&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bryan62

Reputation: 0
• Posts: 12
• Joined: 30-January 05

# I Need Some Help

Posted 30 January 2005 - 07:47 PM

Hey everybody,
I'm trying to write a trinomial tree option pricer for European style kickout options. I'm in the process of teaching myself C++. My problem is that part of my code assigns the variables pu,pm,pd values(these are the up, middle and down risk-neutral probabilities for the tree), but when I use a formula to assign the values it disregards the first part of the eqn. Here is what it looks like:
```double pd;       	 //down probability
double pu;       	 //up probability
double pm;       	 //middle probability
double S[250][250];     	 //stock price at node i,j
double c[250][250];     	 //option price at node i,j
double up = 0.0;     	 //up movement
double down = 0.0;     	 //down movement
double dt = T/N;     	 //time step
double drift= rate - div - .5*vol*vol;  //drift

pu = (1/3) + (drift/vol)*pow(dt/6,.5);
pd =(1/3) - (drift/vol)*pow(dt/6,.5);
pm = (1/3);
```

Is This A Good Question/Topic? 0

## Replies To: I Need Some Help

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: I Need Some Help

Posted 30 January 2005 - 09:05 PM

Which part of the equation is it ignoring? the (1/3)?

### #3 bryan62

Reputation: 0
• Posts: 12
• Joined: 30-January 05

## Re: I Need Some Help

Posted 05 February 2005 - 06:58 PM

Its not calculate the values of the probabilities pu, pd and pm

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: I Need Some Help

Posted 05 February 2005 - 07:28 PM

Can you post a little more of the code? Right now I'd have to say that it's not calculating the values of the equations because you have not defined drift, rate, vol, or dt, or defined them with values that have not been defined.

### #5 abhicj

Reputation: 1
• Posts: 7
• Joined: 03-February 05

## Re: I Need Some Help

Posted 06 February 2005 - 03:01 AM

Yeah...what is pow()...a functn?
post more code....
also maybe..try putting brackets explicitly and the compile....

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: I Need Some Help

Posted 06 February 2005 - 08:16 AM

pow() is a function, of course...it's defined in the math.h library, commonly used for manipulations. It generally takes 2 parameters in the form pow(x,y) and returns a double that is the result of x raised to the power of y.

### #7 bryan62

Reputation: 0
• Posts: 12
• Joined: 30-January 05

## Re: I Need Some Help

Posted 06 February 2005 - 11:17 AM

ok,here's some more code. I use other functions that let the user define drift, vol, rate etc. and I double checked the numbers that it is assigning the probability and it is calculating the (drift/vol)*pow(dt/6,.5) part correctly, it is entirely missing the 1/3 part. Here is the code and the code of the functions that assign values for drift, etc. thanks for the help.
Bryan
[/CODE]
Double GetPrice()
{
Console::Write(S"Price today? ");
double price = input ->ToDouble(0);
return price;
}
Double GetStrike()
{
Console::Write(S"Strike? ");

double strike = input ->ToDouble(0);
return strike;
}

Double GetVol()
{
Console::Write(S"Vol? ");
double vol = input ->ToDouble(0);
return vol;
}
Double GetDiv()
{
Console::Write(S"Div Rate? ");
double div = input ->ToDouble(0);
return div;
}
Double GetRate()
{
Console::Write(S"Risk Free Rate? ");
double rate = input ->ToDouble(0);
return rate;
}
Double GetT()
{
Console::Write(S"Time to Expiry(in years)? ");
double T = input ->ToDouble(0);
return T;
}
int GetN()
{
Console::Write(S"Number of time steps? ");
int N=input->ToInt32(0);
return N;
}
/***************************************************************************
buildtrinomialtree : builds a CRR trinomial tree to price American options
[in] double price :initial price of asset
double strike :strike price
double vol :volatility
double div :dividend yield
double rate :risk-free rate
double T :time to maturity
int N :number of time steps
char type :type of option
[out] double :price of option
****************************************************************************/

double buildtrinomialtreeCRRAmerican()
{
double price = GetPrice();
double strike =GetStrike();
double vol =GetVol();
double div =GetDiv();
double rate =GetRate();
double T=GetT();
int type=GetType();
int N=GetN();
//int H=GetH();
int i,j;
//double pd; //down probability
//double pu; //up probability
//double pm; //middle probability
double S[250][250]; //stock price at node i,j
double c[250][250]; //option price at node i,j
double up = 0.0; //up movement
double down = 0.0; //down movement
double dt = T/N; //time step
double drift= rate - div - .5*vol*vol; //drift

double pu = (1/3)+(drift/vol)*pow(dt/6,.5);
double pd =(1/3) - (drift/vol)*pow(dt/6,.5);
double pm = (1/3);

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: I Need Some Help

Posted 06 February 2005 - 12:12 PM

You're using double variable types...try the following:
``` double pu = (1.0/3.0)+(drift/vol)*pow(dt/6,.5);
double pd =(1.0/3.0) - (drift/vol)*pow(dt/6,.5);
double pm = (1.0/3.0);

```

As an FYI, you are using C++ within the .NET framework...not everything will conform to C++ standards, just in case you have to write C++ outside of .NET...the .NET framework contains several methods and objects that do not exist outside of it.

### #9 bryan62

Reputation: 0
• Posts: 12
• Joined: 30-January 05

## Re: I Need Some Help

Posted 06 February 2005 - 01:35 PM

It worked, thank you very much.