Effacer les filtres
Effacer les filtres

how to fix "limits are too large error" while running a transformed black-Scholes equation into a heat equation using the explicit method ?....

5 vues (au cours des 30 derniers jours)
Hi, I am trying to run an explicit heat equation . This is the prompt I am trying to solve:
My code works for certain items of an array but not for others as i am getting a limits are too large error.
This is from the following transformation:
My code below is:
S0 = 10:10:100;
K = 50;
r = .05;
T = 2;
sigma = .2;
price = blsprice(S0,K,r,T,sigma)
amax = 10;
amin = -10;
M = [10 100 200 400 800];
N = [10 100 200 400 800];
for k = 1:5
dx = (amax - amin)/(M(k)-1);
dt = T/(N(k)-1);
v = zeros(M(k), N(k));
r= dt/dx^2;
j = r/.5*sigma;
x = linspace(amin,amax,M(k));
v(:,1) = max(exp(.5*(j+1)*x) - exp(.5*(j-1)*x),0);
for n = 2:N(k)
%2 lines below are initial and boundary conditions
v(1,n) = v(1, 1);
v(N(k),n) = v(M(k),1);
%line below is explicit method discretized
v(2:M(k)-1,n) = (1-2*r)*v(2:M(k)-1,n-1)+r*v(1:M(k)-2,n-1)+r*v(3:M(k),n-1);
end
approx = v(2:M(k)-1,n)
end
error = abs(approx - price)
B= table(approx')
G=table(price')
surf(v)
I wanted to see if anybody had done anything close to this or can help on what I have so far. I am trying to understand if the prompt is erroneous or if my boundary conditions are wrong. Thank you

Réponses (0)

Catégories

En savoir plus sur Thermal Analysis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by