[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Output of values
From: |
herthaner9 |
Subject: |
Output of values |
Date: |
Mon, 18 Apr 2011 07:17:40 -0700 (PDT) |
Dear community,
I am not at all familiar with the use of any programming language but need
to work with octave for my thesis. I have a question concerning the output
of a programming code that I work with to obtain the value of a financial
derivative. The code I use is the following:
%Program to implement Implicit Finite Differencing
%Basic Set up
s0 = 100;
strike = 100;
sigma = 0.30;
rf = 0.10;
T = 1;
n = 30;
m = 12;
h = T/m;
k = 0.10;
S = zeros(n+1,1);
Y = zeros(n+1,1);
Y(n/2+1) = log(s0);
for i=(n/2):-1:1;
Y(i) = Y(i+1) - k;
end;
for i=(n/2)+2:(n+1);
Y(i) = Y(i-1) + k;
end;
S = exp(Y);
%Create TriDiagonal Matrix
q = zeros(n+1,n+1);
p1 = -0.5*sigma^2*h/k^2 - (rf-0.5*sigma^2)*h/(2*k);
p2 = sigma^2*h/k^2 + rf*h + 1;
p3 = -0.5*sigma^2*h/k^2 + (rf-0.5*sigma^2)*h/(2*k);
q(1,1) = p1+p2; q(1,2) = p1;
q(n+1,n) = p3; q(n+1,n+1) = p2;
for i=2:n;
q(i,i-1) = p3;
q(i,i) = p2;
q(i,i+1) = p1;
end;
qinv = inverse(q);
%Backward recursion phase
F = zeros(n+1,m+1);
F(:,m+1) = max(0,strike-S);
for t=12:-1:1;
F(:,t) = qinv*F(:,t+1);
end;
%Plot the put option price as a function of stock price and time
t = [0:(1/12):1];
mesh(S,t,F’);
title(’European Put Option Function’);
xlabel(’Stock Price’);
ylabel(’Time’);
Thus, I know how to create a 3D-plot of the development of the derivative's
value based on the value of the underlying and time to maturity.
However, how can I get Octave to create and .txt output file or any readable
file? I would like the values of F' easily identifiable.
Please do not direct me to any manual. I have checked the internet and even
the smallest advancement is beyond my level of knowledge. I just want to
know what exactly i have to type to create a .txt-file with values of F.
Thanks you very much!
--
View this message in context:
http://octave.1599824.n4.nabble.com/Output-of-values-tp3457686p3457686.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Output of values,
herthaner9 <=