<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A New Kind of Binomial Tree</title>
	<atom:link href="http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/feed" rel="self" type="application/rss+xml" />
	<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm</link>
	<description>Perception and Physics. Science and Spirituality. Life and Work. Money and Quantitative Finance.</description>
	<lastBuildDate>Wed, 26 Jan 2011 15:08:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Manoj</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-175</link>
		<dc:creator>Manoj</dc:creator>
		<pubDate>Tue, 02 Jun 2009 23:23:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-175</guid>
		<description>Thanks for your comment, Chris.

I formatted your code snippet by putting it in pre tags.</description>
		<content:encoded><![CDATA[<p>Thanks for your comment, Chris.</p>
<p>I formatted your code snippet by putting it in pre tags.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Erickson</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-174</link>
		<dc:creator>Chris Erickson</dc:creator>
		<pubDate>Tue, 02 Jun 2009 23:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-174</guid>
		<description>Hmm, how do I format this nicely?
&lt;pre&gt;
optionPrice t s0 k r sigma n = f 0 0 where
    fs = [[f i j &#124; j &lt;- [-i..i] ] &#124; i &lt;- [0..n] ]
    f i j = if i == n
               then max ((s i j) - k) 0
               else max ((s i j) - k)
                           (exp(-r*dt) * (p * (fs!!(i+1)!!(i+j+2)) +
                                 (1-p) * (fs!!(i+1)!!(i+j))))
    s i j = s0 * u**(fromIntegral j)
    u = exp(sigma * sqrt dt)
    d = 1 / u
    dt = t / (fromIntegral n)
    p = (exp(r*dt)-d) / (u-d)
&lt;/pre&gt;
Here I&#039;m creating a list of lists, fs, indexed by i then j, of values of (f i j), then using that list within f itself. Since Haskell is lazy, this doesn&#039;t compute anything until you actually use it, then with how the lists are used it only computes it once for each pair of i and j. I also had to add (i+1) to the places where I&#039;m using j to access the list to avoid an issue with negative indices.</description>
		<content:encoded><![CDATA[<p>Hmm, how do I format this nicely?</p>
<pre>
optionPrice t s0 k r sigma n = f 0 0 where
    fs = [[f i j | j &lt;- [-i..i] ] | i &lt;- [0..n] ]
    f i j = if i == n
               then max ((s i j) - k) 0
               else max ((s i j) - k)
                           (exp(-r*dt) * (p * (fs!!(i+1)!!(i+j+2)) +
                                 (1-p) * (fs!!(i+1)!!(i+j))))
    s i j = s0 * u**(fromIntegral j)
    u = exp(sigma * sqrt dt)
    d = 1 / u
    dt = t / (fromIntegral n)
    p = (exp(r*dt)-d) / (u-d)
</pre>
<p>Here I&#8217;m creating a list of lists, fs, indexed by i then j, of values of (f i j), then using that list within f itself. Since Haskell is lazy, this doesn&#8217;t compute anything until you actually use it, then with how the lists are used it only computes it once for each pair of i and j. I also had to add (i+1) to the places where I&#8217;m using j to access the list to avoid an issue with negative indices.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manoj</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-157</link>
		<dc:creator>Manoj</dc:creator>
		<pubDate>Sat, 23 May 2009 00:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-157</guid>
		<description>Thanks Aswin.

It does look interesting. My next project, after finishing this darned book....</description>
		<content:encoded><![CDATA[<p>Thanks Aswin.</p>
<p>It does look interesting. My next project, after finishing this darned book&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ashwin</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-155</link>
		<dc:creator>ashwin</dc:creator>
		<pubDate>Fri, 22 May 2009 03:22:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-155</guid>
		<description>http://www.cse.chalmers.se/~joels/ - Obsidian : this may be a great way to speed things up and get it into everyday use. The use of GPU/CUDA programming for quant analysis is catching on.</description>
		<content:encoded><![CDATA[<p><a href="http://www.cse.chalmers.se/~joels/" rel="nofollow">http://www.cse.chalmers.se/~joels/</a> &#8211; Obsidian : this may be a great way to speed things up and get it into everyday use. The use of GPU/CUDA programming for quant analysis is catching on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manoj</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-134</link>
		<dc:creator>Manoj</dc:creator>
		<pubDate>Sun, 22 Mar 2009 00:17:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-134</guid>
		<description>Haskell also is quite slow for N &gt; 20. 

I was trying to demonstrate the similarity between the mathematical expression and the code, rather than trying to implement a good Binomial tree algorithm in Haskell.  This point was lost in translation, unfortunately, because my LaTeX plugin didn&#039;t handle the formulas too well. (My own plugin, so I can&#039;t complain!)</description>
		<content:encoded><![CDATA[<p>Haskell also is quite slow for N > 20. </p>
<p>I was trying to demonstrate the similarity between the mathematical expression and the code, rather than trying to implement a good Binomial tree algorithm in Haskell.  This point was lost in translation, unfortunately, because my LaTeX plugin didn&#8217;t handle the formulas too well. (My own plugin, so I can&#8217;t complain!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: riskyrisk</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-133</link>
		<dc:creator>riskyrisk</dc:creator>
		<pubDate>Sat, 21 Mar 2009 19:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-133</guid>
		<description>I&#039;ve posted the question to one of the Erlang forums. Let&#039;s see if we get any feedback.
http://www.trapexit.org/forum/viewtopic.php?p=44469</description>
		<content:encoded><![CDATA[<p>I&#8217;ve posted the question to one of the Erlang forums. Let&#8217;s see if we get any feedback.<br />
<a href="http://www.trapexit.org/forum/viewtopic.php?p=44469" rel="nofollow">http://www.trapexit.org/forum/viewtopic.php?p=44469</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: riskyrisk</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-132</link>
		<dc:creator>riskyrisk</dc:creator>
		<pubDate>Sat, 21 Mar 2009 16:02:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-132</guid>
		<description>Hmm... It&#039;s because it&#039;s not using tail recursion, isn&#039;t it?

Here&#039;s a newer version that has an argument for call or put (CP = 1 is call, CP = -1 is put) and uses logs to speed things up. Still have to rewrite it to include tail recursion(but how?).

-module(crr).
-import(math, [log/1, sqrt/1, exp/1, pow/2]).
-export([optionPrice/7]).

max(X, Y) when X &gt; Y -&gt; X;
max(_X, Y) -&gt; Y.

optionPrice(CP, S, K, T, R, V, N) -&gt;
    Dt = T / N,
    Df = exp(-R * Dt),
    U = exp(V * sqrt(Dt)),
    D = 1 / U,
    Pu = (exp(R * Dt) - D) / (U - D),
    Pd = 1 - Pu,
    S * f(0, 0, CP, K / S , Df, log(U), Pu, Pd, N).

s(J, U) -&gt;
    exp(J * U).

f(N, J, CP, X, _Df, U, _Pu, _Pd, N) -&gt;
    Sij = s(J, U),
    max(CP * (Sij - X), 0);
f(I, J, CP, X, Df, U, Pu, Pd, N) -&gt;
    Sij = s(J, U),
    Vij = Df * (Pu * f(I + 1, J + 1, CP, X, Df, U, Pu, Pd, N) + Pd * f(I + 1, J - 1, CP, X, Df, U, Pu, Pd, N)),
    max(CP * (Sij - X),	Vij).

riskyrisk</description>
		<content:encoded><![CDATA[<p>Hmm&#8230; It&#8217;s because it&#8217;s not using tail recursion, isn&#8217;t it?</p>
<p>Here&#8217;s a newer version that has an argument for call or put (CP = 1 is call, CP = -1 is put) and uses logs to speed things up. Still have to rewrite it to include tail recursion(but how?).</p>
<p>-module(crr).<br />
-import(math, [log/1, sqrt/1, exp/1, pow/2]).<br />
-export([optionPrice/7]).</p>
<p>max(X, Y) when X &gt; Y -&gt; X;<br />
max(_X, Y) -&gt; Y.</p>
<p>optionPrice(CP, S, K, T, R, V, N) -&gt;<br />
    Dt = T / N,<br />
    Df = exp(-R * Dt),<br />
    U = exp(V * sqrt(Dt)),<br />
    D = 1 / U,<br />
    Pu = (exp(R * Dt) &#8211; D) / (U &#8211; D),<br />
    Pd = 1 &#8211; Pu,<br />
    S * f(0, 0, CP, K / S , Df, log(U), Pu, Pd, N).</p>
<p>s(J, U) -&gt;<br />
    exp(J * U).</p>
<p>f(N, J, CP, X, _Df, U, _Pu, _Pd, N) -&gt;<br />
    Sij = s(J, U),<br />
    max(CP * (Sij &#8211; X), 0);<br />
f(I, J, CP, X, Df, U, Pu, Pd, N) -&gt;<br />
    Sij = s(J, U),<br />
    Vij = Df * (Pu * f(I + 1, J + 1, CP, X, Df, U, Pu, Pd, N) + Pd * f(I + 1, J &#8211; 1, CP, X, Df, U, Pu, Pd, N)),<br />
    max(CP * (Sij &#8211; X),	Vij).</p>
<p>riskyrisk</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: riskyrisk</title>
		<link>http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm/comment-page-1#comment-131</link>
		<dc:creator>riskyrisk</dc:creator>
		<pubDate>Sat, 21 Mar 2009 12:46:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.thulasidas.com/?p=1111#comment-131</guid>
		<description>I&#039;ve implemented your code in Erlang. Seems very slow since the recursion means many of the nodes are calculated multiple times. This increases dramatically with an increase in N. Any ideas of how to make it more efficient? Does Haskell make it efficient automatically?


-module(crr).
-import(math, [sqrt/1, exp/1, pow/2]).
-export([optionPrice/6]).

max(X, Y) when X &gt; Y -&gt; X;
max(_X, Y) -&gt; Y.

optionPrice(S, K, T, R, V, N) -&gt;
    Dt = T / N,
    U = exp(V * sqrt(Dt)),
    D = 1 / U,
    P = (exp(R * Dt) - D) / (U - D),
    f(0, 0, S, K, R, Dt, U, P, N).

s(J, S, U) -&gt;
    S * pow(U, J).

f(N, J, S, K, _R, _Dt, U, _P, N) -&gt;
    Sij	= s(J, S, U),
    max(Sij - K, 0);
f(I, J, S, K, R, Dt, U, P, N) -&gt;
    Sij	= s(J, S, U),
    Vij = exp(-R * Dt) * (P * f(I + 1, J + 1, S, K, R, Dt, U, P, N) + (1 - P) * f(I + 1, J - 1, S, K, R, Dt, U, P, N)),
    max(Sij - K, Vij).


calling the function:
(emacs@localhost)13&gt; crr:optionPrice(100,100,1,0.05,0.3,25).
14.341546969779252

riskyrisk</description>
		<content:encoded><![CDATA[<p>I&#8217;ve implemented your code in Erlang. Seems very slow since the recursion means many of the nodes are calculated multiple times. This increases dramatically with an increase in N. Any ideas of how to make it more efficient? Does Haskell make it efficient automatically?</p>
<p>-module(crr).<br />
-import(math, [sqrt/1, exp/1, pow/2]).<br />
-export([optionPrice/6]).</p>
<p>max(X, Y) when X &gt; Y -&gt; X;<br />
max(_X, Y) -&gt; Y.</p>
<p>optionPrice(S, K, T, R, V, N) -&gt;<br />
    Dt = T / N,<br />
    U = exp(V * sqrt(Dt)),<br />
    D = 1 / U,<br />
    P = (exp(R * Dt) &#8211; D) / (U &#8211; D),<br />
    f(0, 0, S, K, R, Dt, U, P, N).</p>
<p>s(J, S, U) -&gt;<br />
    S * pow(U, J).</p>
<p>f(N, J, S, K, _R, _Dt, U, _P, N) -&gt;<br />
    Sij	= s(J, S, U),<br />
    max(Sij &#8211; K, 0);<br />
f(I, J, S, K, R, Dt, U, P, N) -&gt;<br />
    Sij	= s(J, S, U),<br />
    Vij = exp(-R * Dt) * (P * f(I + 1, J + 1, S, K, R, Dt, U, P, N) + (1 &#8211; P) * f(I + 1, J &#8211; 1, S, K, R, Dt, U, P, N)),<br />
    max(Sij &#8211; K, Vij).</p>
<p>calling the function:<br />
(emacs@localhost)13&gt; crr:optionPrice(100,100,1,0.05,0.3,25).<br />
14.341546969779252</p>
<p>riskyrisk</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 4/17 queries in 0.019 seconds using apc
Object Caching 426/432 objects using apc

Served from: www.thulasidas.com @ 2012-02-09 06:09:07 -->
