Graphics, Figures & TablesDraw Binomial option pricing tree/lattice

Information and discussion about graphics, figures & tables in LaTeX documents.
knutk
Posts: 2
Joined: Fri Feb 26, 2010 5:01 pm

Draw Binomial option pricing tree/lattice

Post by knutk »

Hi,

Im trying to draw a binomial tree with latex and the tikz package, I found an example and have tried to modify it to my needs, but haven't been successful. I have 2 problems;
  • 1. I want the tree to be recombining, such that the arrow going up from B, and down from C, ends up in the same node, namely E.
    2. I also want the arrows in the tree to have the same slope/angel.
Attached is a figure and the code I have used. Appreciate any help!

Code: Select all

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=4cm, sibling distance=3.5cm,->]
\tikzstyle{level 2}=[level distance=4cm, sibling distance=2cm,->]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=2em, text centered]
\tikzstyle{end} = []

% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels. 
\begin{tikzpicture}[grow=right, sloped]
\node[bag] {$\$ A$}
    child {
        node[bag] {B}        
            child {
                node[end, label=right:
                    {D}] {}
                edge from parent
                node[above] {}
                node[below]  {$(1-p)^2$}
            }
            child {
                node[end, label=right:
                    {E}] {}
                edge from parent
                node[above] {}
                node[below]  {$(1-p)p$}
            }
            edge from parent 
            node[above] {}
            node[below]  {$(1-p)$}
    }
    child {
        node[bag] {C}        
        child {
                node[end, label=right:
                    {E}] {}
                edge from parent
                node[above] {$(1-p)p$}
                node[below]  {}
            }
            child {
                node[end, label=right:
                    {F}] {}
                edge from parent
                node[above] {$P^2$}
                node[below]  {}
            }
        edge from parent         
            node[above] {$P$}
            node[below]  {}
    };
\end{tikzpicture}
Attachments
Option lattice.png
Option lattice.png (18.17 KiB) Viewed 31526 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Draw Binomial option pricing tree/lattice

Post by frabjous »

What you describe I think goes against the expected structure of trees. I'd just do it without using a tree structure.

Here's it with the locations hard-coded. With some study of the tikz manual, I'm sure it could be done with relative locations instead. Too lazy to figure it out myself.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\begin{document}
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=2em, text centered]
\tikzstyle{end} = []
\begin{tikzpicture}[sloped]
  \node (a) at ( 0,0) [bag] {$\$ A$};
  \node (b) at ( 4,-1.5) [bag] {B};
  \node (c) at ( 4,1.5) [bag] {C};
  \node (d) at ( 8,-3) [bag] {D};
  \node (e) at ( 8,0) [bag] {E};
  \node (f) at ( 8,3) [bag] {F};
  \draw [->] (a) to node [below] {$(1-p)$} (b);
  \draw [->] (a) to node [above] {$P$} (c);
  \draw [->] (c) to node [below] {$P^2$} (f);
  \draw [->] (c) to node [above] {$(1-p)p$} (e);
  \draw [->] (b) to node [below] {$(1-p)p$} (e);
  \draw [->] (b) to node [above] {$(1-p)^2$} (d);
\end{tikzpicture}
\end{document}
lattice.png
lattice.png (7.48 KiB) Viewed 31519 times
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Draw Binomial option pricing tree/lattice

Post by localghost »

There is an alternative solution using the »matrix« library of the pgf/tikZ package.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
  \begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=3.5cm,
      row sep=1cm,
    ]
    {
          &   & F \\
          & C &   \\
      \$A &   & E \\
          & B &   \\
          &   & D \\
    };
    \draw[->] (tree-3-1) -- (tree-2-2) node [midway,above] {$P$};
    \draw[->] (tree-3-1) -- (tree-4-2) node [midway,below] {$(1-p)$};
    \draw[->] (tree-2-2) -- (tree-1-3) node [midway,above] {$P^2$};
    \draw[->] (tree-2-2) -- (tree-3-3) node [midway,below] {$(1-p)p$};
    \draw[->] (tree-4-2) -- (tree-3-3) node [midway,above] {$(1-p)p$};
    \draw[->] (tree-4-2) -- (tree-5-3) node [midway,below] {$(1-p)^2$};
  \end{tikzpicture}
\end{document}

Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
knutk
Posts: 2
Joined: Fri Feb 26, 2010 5:01 pm

Re: Draw Binomial option pricing tree/lattice

Post by knutk »

Thank you both for the help. I went with the matrix solution. :)

Best
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

Draw Binomial option pricing tree/lattice

Post by casperyc »

Hi there,

Is there a way to input 'eqnarray*' in that?


I have tried to use

Code: Select all

\begin{tikzpicture}[sloped]
	\node (a) at ( 0,0) [bag] {
	\begin{eqnarray*}
	c_0 &=& 2.72610 \\
	\o_0 &=& 0.32588 \\
	\phi_0 &=& -10.30910
	\end{eqnarray*}
	};
	\node (b) at ( 4,-1.5) [bag] {49.5764};
	\node (c) at ( 4,1.5) [bag] {32.4358};
	\node (d) at ( 8,-3) [bag] {61.44549};
	\node (e) at ( 8,0) [bag] {40.20051};
	\node (f) at ( 8,3) [bag] {26.30105};
	\draw [->] (a) to (b);
	\draw [->] (a) to (c);
	\draw [->] (c) to (e);
	\draw [->] (c) to (f);
	\draw [->] (b) to (d);
	\draw [->] (b) to (e);
\end{tikzpicture}
My aim is to draw the 'tree' in the attachment
Attachments
Pages from MATH3022Solns5.jpg
Pages from MATH3022Solns5.jpg (32.52 KiB) Viewed 31413 times
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Draw Binomial option pricing tree/lattice

Post by localghost »

Please do not hijack threads that are marked as solved with the green checkmark (see Board Rules). Next time please open a new topic and add a link to the related one.

At first you should learn why not to use the eqnarray environment any more [1]. At second you should know that a displayed math environment can't work. So try to insert an in-line equation in conjunction with the aligned environment from the amsmath package.

Code: Select all

\(
  \begin{aligned}
    c_0 &= 2.72610 \\
    \phi_0 &= 0.32588 \\
    \psi_0 &= -10.30910
  \end{aligned}
\)
Your code sample won't work because you haven't declared the node style bag as frabjous did in his example.

[1] The PracTeX Journal - TeX Users Group | Lars Madsen: Avoid eqnarray!


Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
feanor22
Posts: 32
Joined: Mon Oct 13, 2008 3:01 pm

Re: Draw Binomial option pricing tree/lattice

Post by feanor22 »

Hi

I have tried all examples and most of them worked, but the matrix approach didn't work...
Any ideas why??

Thanks
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Draw Binomial option pricing tree/lattice

Post by Johannes_B »

Would you be able to post a minimal example, so we don't have to read this very old thread once again? Opening a new thread might also be a good idea (and linking here).
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
feanor22
Posts: 32
Joined: Mon Oct 13, 2008 3:01 pm

Draw Binomial option pricing tree/lattice

Post by feanor22 »

Dear All

I have tried the examples on this page in a article class file but if I try to include the code in a beamer slide I get 100 errors.
Any ideas why?
Thanks in advance.

Code: Select all

\documentclass[xcolor=pdflatex,dvipsnames,table]{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\mode<presentation>
\usetheme{JuanLesPins}
\setbeamercovered{transparent=30}
\title[Investment Science ]{ Investment Science  \\  Introduction to Binomial Trees }
\author[ Anonymous]
{ Investment Science}
\institute{ Blah University }
\date{today}
\begin{document}
\frame{\maketitle}
\begin{frame}
  \begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=3.5cm,
      row sep=1cm,
    ]
    {
          &   & F \\
          & C &   \\
      \$A &   & E \\
          & B &   \\
          &   & D \\
    };
    \draw[->] (tree-3-1) -- (tree-2-2) node [midway,above] {$p$};
    \draw[->] (tree-3-1) -- (tree-4-2) node [midway,below] {$(1-p)$};
    \draw[->] (tree-2-2) -- (tree-1-3) node [midway,above] {$p^2$};
    \draw[->] (tree-2-2) -- (tree-3-3) node [midway,below] {$(1-p)p$};
    \draw[->] (tree-4-2) -- (tree-3-3) node [midway,above] {$(1-p)p$};
    \draw[->] (tree-4-2) -- (tree-5-3) node [midway,below] {$(1-p)^2$};
  \end{tikzpicture}
  \end{frame}
\end{document}
Last edited by Stefan Kottwitz on Thu Jul 31, 2014 12:29 pm, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Draw Binomial option pricing tree/lattice

Post by Johannes_B »

The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply