Integral3 with Error using - Matrix dimensions must agree.
Afficher commentaires plus anciens
I tried to use the numerical triple integral to price the basket option, however this error message keeps popping up and I cannot locate the misused "-"
S1_0=100; S2_0=85; S3_0=75;
T = 2;
a = [1/3 1/3 1/3].';
K = 85;
r = ones(3,1)*0.05; % interest rate
sigma = [0.2 0.15 0.28]';
sigma_sqr = (sigma.^2);
sigma_cov = kron(sigma.',sigma);
rho = [1 -0.2 -0.3; -0.2 1 0.25; -0.3 0.25 1];
sigma_cov = sigma_cov.* rho;
sigma_cov_T= sigma_cov*T;
sigma_cov_T_inv = (sigma_cov*T)^(-1);
sqrt_det_2pi_Sigma_T= (det(2*pi*sigma_cov_T))^(1/2);
payoff = @ (x1, x2, x3) max(a(1)*S1_0*exp(x1) + a(2)*S2_0*exp(x2) + a(3)*S3_0*exp(x3) - K, 0);
normal_density_3d =@(x1,x2,x3) 1/sqrt_det_2pi_Sigma_T*...
exp((-1/2).*(([x1 ;x2; x3]-((r-(1/2)*sigma_sqr)*T))'...
* sigma_cov_T_inv...
*([x1 ;x2; x3]-(r-(1/2)*sigma_sqr)*T)));
integrand = @(x1, x2, x3) payoff(x1, x2, x3) .* ...
normal_density_3d(x1,x2,x3);
price = exp(-r*T)*integral3(integrand,-3,3,-3,3,-3,3);
Error using -
Matrix dimensions must agree.
Error in
@(x1,x2,x3)1/sqrt_det_2pi_Sigma_T*exp((-1/2).*(([x1;x2;x3]-((r-(1/2)*sigma_sqr)*T))'*sigma_cov_T_inv*([x1;x2;x3]-(r-(1/2)*sigma_sqr)*T)))
Error in @(x1,x2,x3)payoff(x1,x2,x3).*normal_density_3d(x1,x2,x3)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!