Overview
Tree models are a type of discrete model used to model financial processes. From a conceptual standpoint, they are usually used as a discrete version of more complex continuous models. This means that the pre-requisites to understanding these models is less than the continous versions (which requires knowledge of stochastic calculus.)Tree models can also provide a way to calculate an approximate numerical solution to a financial model when no analytical solution exists.
The tree models in finance should be distinguished from the machine learning tree models. In finance, tree models are used to model a time series, in machine learning a tree is used to partition a feature space.
Binary Tree
The binary tree is the workhorse of the tree models in finance. This is because it is the simplest tree model, but also because it is the tree model that most closely models the brownian motion used in the continuous time models. (that is, derivatives that are theoretically hedgable in a continuous time model is also hedgable with a binary tree, whereas, it may not be hedgable in other tree models.)The binary tree starts at a single node, representing a price or some other variable. Each level of the tree represents a new point in time. At each point in time, the variable being modeled can take one of two values in the next time period.
Risk Neutral Tree
the binomial tree can be used to value plain vanilla options. This is typically done by calculating risk neutral probabilities, and then calculating an expectation{% p = (e^{r \Delta t} - d)/ (u - d) %}
where d is the down factor, and u is the up factor.
let bt = await import('/lib/finance/tree-models/binomial/v1.0.0/binomial-tree.js');
let r = 0.1;
let u = 2;
let d = 0.5;
let t = 1;
let prob = (Math.exp(r*t) - d)/ (u-d)
let tree = bt.binomial(100, 5, u, d, prob);
let sum = 0;
for(let item of tree[tree.length-1]){
sum += item.probability * Math.max(0, item.value - 100);
}