function [S, up, down, p0, p1] = binomialTree(T, S0, r, sigma, N)
% Octave/Matlab function to model the price of asset S with initial
% price S0 out to time T in N steps using the Black-Scholes model.
%
% Inputs:
% T = expiration time
% S0 = spot stock price
% r = risk-free yield
% sigma = volatility; must be >0
% N = height of the binomial tree; must have 01
down = 1/up; % down factor, must be <1
p0 = (R - down) / (up - down); % risk-neutral up probability
p1 = 1 - p0; % risk-neutral down probability
% NOTE: for p0,p1 to be in the interval (0,1), it must be that
% down