8 Replies - 1442 Views - Last Post: 06 February 2005 - 01:35 PM Rate Topic: -----

#1 bryan62  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • 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)?
Was This Post Helpful? 0
  • +
  • -

#3 bryan62  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 abhicj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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....
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 bryan62  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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? ");
String*input =Console::ReadLine();
double price = input ->ToDouble(0);
return price;
}
Double GetStrike()
{
Console::Write(S"Strike? ");
String*input =Console::ReadLine();

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

Double GetVol()
{
Console::Write(S"Vol? ");
String*input =Console::ReadLine();
double vol = input ->ToDouble(0);
return vol;
}
Double GetDiv()
{
Console::Write(S"Div Rate? ");
String*input =Console::ReadLine();
double div = input ->ToDouble(0);
return div;
}
Double GetRate()
{
Console::Write(S"Risk Free Rate? ");
String*input =Console::ReadLine();
double rate = input ->ToDouble(0);
return rate;
}
Double GetT()
{
Console::Write(S"Time to Expiry(in years)? ");
String*input =Console::ReadLine();
double T = input ->ToDouble(0);
return T;
}
int GetN()
{
Console::Write(S"Number of time steps? ");
String*input=Console::ReadLine();
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);
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • 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.
Was This Post Helpful? 0
  • +
  • -

#9 bryan62  Icon User is offline

  • New D.I.C Head

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

Re: I Need Some Help

Posted 06 February 2005 - 01:35 PM

It worked, thank you very much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1