help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with octave


From: Julien Martin
Subject: Problem with octave
Date: Mon, 30 Aug 2010 17:51:10 +0200

Hello,

I am trying to run an octave file in two ways, none of which works:

-First from the octave prompt as follows:
octave> imfdamput

which results in the following error:
**************************
octave:1> imfdamput
error: `Smax' undefined near line 13 column 10
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   /home/julien/Documents/donnees/finance/octave/imfdamput.m at line 13, column 3
**************************

-Second, running the m file as an executable after uncommenting first line. This results in an empty output...

Can anyone please help?

Thanks,

Julien.


Here is the octave file:

% #! /usr/bin/octave -qf

function put = imfdamput(Smax, dS, T, dT, X, R, SIG);
% put = imfdamput(Smax, dS, T, dT, X, R, SIG);
% Smax : maximum stock price
% dS : increment of stock price
% T : maturity date
% dT : time step
% X : exercise price
% R : risk free interest rate
%
% reference : John C. Hull, Options, Futures, and Other Derivatives
M = ceil(Smax/dS); ds = Smax / M;
N = ceil(T/dT);
dt = T / N;
J=1:M-1;
a=.5*R*dt*J - .5*SIG^2*dt*J.^2;
b=1 + SIG^2*dt*J.^2 + R*dt;
c=-.5*R*dt*J - .5*SIG^2*dt*J.^2;
A = diag(b) + diag(a(2:M-1), -1) + diag(c(1:M-2), 1);
put = zeros(N+1, M+1);
put(N+1, :) = max(X - [0:ds:Smax], 0);
put(:, 1) = X; put(:, M+1) = 0;
for i = N:-1:1
y = put(i+1, 2:M)';
y(1) = y(1) - a(1)*X;
put(i, 2:M) = [A \ y]';
put(i, :) = max(X - [0:ds:Smax], put(i,:));
end

Smax = 150;
dS = 1;
T = 1;
dT = .1;
X = 50;
R = .1;
SIG = .5;

printf("Put: %f\n", imfdamput(Smax, dS, T, dT, X, R, SIG));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]