尝试构建一个二叉树,其中节点显示默认

尝试构建一个二叉树,其中节点显示默认

在此处输入图片描述

我想在 latex 中创建一个类似于上传图像的可违约二项式树。在每个节点上,股票都有可能违约(股票价格降至零)。我在网上查过,似乎无法创建可违约分支到目前为止,这是我拥有的代码,但无法弄清楚如何向二项式模型添加第三个分支

\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,
    ]
    {
          &   & S_{2,2}$ \\
          & S_{1,1}$  &   \\
      S_{0,0}$ &      & S_{2,0}$ \\
          & S_{1,-1}$ &   \\
          &   & S_{2,-2}$ \\
    };
    \draw[->] (tree-3-1) -- (tree-2-2) node [midway,above] {$p (1 - \lambda_t \Delta t)$};
    \draw[->] (tree-3-1) -- (tree-4-2) node [midway,below] {$(1-p) (1 - \lambda_t \Delta t)$};
    \draw[->] (tree-2-2) -- (tree-1-3) node [midway,above] {$p^2 (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-2-2) -- (tree-3-3) node [midway,below] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-4-2) -- (tree-3-3) node [midway,above] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-4-2) -- (tree-5-3) node [midway,below] {$(1-p)^2 (1 - \lambda_t \Delta t)^2$};
  \end{tikzpicture}
\end{document}

答案1

经过一些小小的修正(您想要数学节点)它最终编译成功...但是您的问题是什么?


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

\begin{document}
  \begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of math nodes,
      minimum size=1cm,
      column sep=3.5cm,
      row sep=1cm,
    ]
    {
              &          & S_{2,2} \\
              & S_{1,1}  &   \\
      S_{0,0} &          & S_{2,0} \\
              & S_{1,-1} &   \\
              &          & S_{2,-2} \\
    };
    \draw[->] (tree-3-1) -- (tree-2-2) node [midway,above] {$p (1 - \lambda_t \Delta t)$};
    \draw[->] (tree-3-1) -- (tree-4-2) node [midway,below] {$(1-p) (1 - \lambda_t \Delta t)$};
    \draw[->] (tree-2-2) -- (tree-1-3) node [midway,above] {$p^2 (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-2-2) -- (tree-3-3) node [midway,below] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-4-2) -- (tree-3-3) node [midway,above] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
    \draw[->] (tree-4-2) -- (tree-5-3) node [midway,below] {$(1-p)^2 (1 - \lambda_t \Delta t)^2$};
  \end{tikzpicture}
\end{document}

结果

答案2

我会使用 Forest,但现在不会。如果这是你想要的,我可能会稍后尝试。我不确定这是否是你想要的,因为它看起来像是你已编写代码的一个足够简单的扩展,那么我遗漏了什么?

[由于 Okular 的一个错误,“这是你想要的吗?”有一定的想象力负担。对此表示歉意。]

这是对MS-SPO 的答案

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

\begin{document}
\begin{tikzpicture}[>=stealth,sloped]
  \matrix (tree) [%
    matrix of math nodes,
    minimum size=1cm,
    column sep=3.5cm,
    row sep=1cm,
  ]
  {
            &          & S_{2,2} \\
            & S_{1,1}  &   \\
    S_{0,0} &          & S_{2,0} \\
            & S_{1,-1} &   \\
            &          & S_{2,-2} \\
            & Zero    & Zero \\
  };
  \draw[->] (tree-3-1) -- (tree-2-2) node [midway,above] {$p (1 - \lambda_t \Delta t)$};
  \draw[->] (tree-3-1) -- (tree-4-2) node [midway,below] {$(1-p) (1 - \lambda_t \Delta t)$};
  \draw[->] (tree-2-2) -- (tree-1-3) node [midway,above] {$p^2 (1 - \lambda_t \Delta t)^2$};
  \draw[->] (tree-2-2) -- (tree-3-3) node [midway,below] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
  \draw[->] (tree-4-2) -- (tree-3-3) node [midway,above] {$(1-p)p (1 - \lambda_t \Delta t)^2$};
  \draw[->] (tree-4-2) -- (tree-5-3) node [midway,below] {$(1-p)^2 (1 - \lambda_t \Delta t)^2$};
  \foreach \i/\j in {3-1/6-2,2-2/6-3,4-2/6-3} \draw [dotted,->,gray] (tree-\i) -- (tree-\j);
\end{tikzpicture}
\end{document}

来自社区:

结果

相关内容