From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Greater than problem, please help
Date: Sat, 21 Apr 2012 15:46:18 -0500
Organization: NNTP Server
Lines: 68
Message-ID: <jmv6ao$dbi$>
References: <jmv550$mi9$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20120216 Thunderbird/3.1.19
X-Notice: Filtered by postfilter v. 0.8.2
Xref: comp.soft-sys.matlab:765452

On 4/21/2012 3:26 PM, Orhan Unal wrote:

> ... The following line
> Tree = S0*up.^((steps:-1:0)').*down.^((0:steps)')
> produces the following results
> Tree =
> 82.4567
> 67.9528
> 56.0000
> 46.1497

> Then the code
> for i=1:steps+1
>   if K-Tree > 0
>     Tree(i) = 1;
>   else
>     Tree(i) = 0;
>   end
> end

This isn't your problem (keep reading), but...

The above "the Matlab way" (tm) is just



> This works fine for all values that AREN'T K=56. But you see, when K=56
> notice how it corresponds to the value 56 in the first Tree results;
> When computing K-Tree, 56-56 should return 0 in the second Tree results
> in that position. However, I get the value 1 and it's seriously
> confusing me because I don't know how to fix it, I've tried so many
> things out and nothing seems to work. Please help me, thanks.

Try the following at the command line and I think you'll see the reason 
for the "problem".


The value that appears to be identically 56 will, indeed show up to be 
just slightly off.  The reason is it was computed w/ a floating point 
expression whereas the integer value you're comparing to to is, indeed, 

You'll need a tolerance on the comparison if it's critical that the 
decision point be there; of course, the actual internally represented 
value that was calculated wasn't _quite_ there so that's a question of 
what should you do w/ the decision at other breakpoints.

Or, perhaps if this is pricing you should round to the nearest 
fractional cent that's traded; I don't know the answer to that.

Look at the following link to get the gist of what's going on in more