# Prevent Octave from thinking that this
# is a function file:
1;
S = 50;
up = .10;
down = 0.03;
B = 1;
r = 0.06;
T = 1;
K = 50;
function retval = f(x, strike)
retval = max(x - strike, 0);
endfunction
m = [S * (1 - down), B * exp(r * T); S * (1 + up), B * exp(r * T)];
payoff = [f(S * (1 - down), K); f(S * (1 + up), K)];
portfolio = m \ payoff;
value = transpose(portfolio) * [S; B];
disp("portfolio: phi ="), portfolio(1), disp("psi ="), portfolio(2)
disp("derivative value:"), value
## Octave is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public
## License as published by the Free Software Foundation;
## either version 3 of the License, or (at your option) any
## later version.
##
## Octave is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public
## License along with Octave; see the file COPYING. If not,
## see .
## NAME: singleperiod.m
##
## USAGE: within octave, at interactive prompt
## singleperiod
## REQUIRED ARGUMENTS: none
##
## OPTIONS: none
## DESCRIPTION: Set up and solve for the replicating portfolio
## and the value of the corresponding derivative security in a
## single period binomial model.
## DIAGNOSTICS: none
## CONFIGURATION AND ENVIRONMENT: octave
## DEPENDENCIES: none
## INCOMPATIBILITIES: none known
## PROVENANCE: version 1.0 by sdunbar as of Thu Dec 10, 2015 8:58 AM
## BUGS AND LIMITATIONS: A limitation is that all parameters must be
## entered directly into the script.
## FEATURES AND POTENTIAL IMPROVEMENTS: Make the script interactive so
## that parameters can be entered from a command line, perhaps as a function,
## or through a GUI.
## AUTHOR: Steve Dunbar
## VERSION: Version 1.0 as of Thu Dec 10, 2015 9:00 AM
## KEYWORDS: single period biomial model, derivative security, replicating portfolio