Finance program (New edit)

2 次查看(过去 30 天)
Gabriel
Gabriel 2024-1-26
编辑: Rik 2024-1-26
Hi there. I'm really sorry for my previous question. As i said yesterday i need some help for an assignement. We are requested to submit a program that allow to calculate Delta with the Monte carlo simulationm using the Base method and Common random method (I'm not sure if these are the right translation in English). I already write the program
S0 = 100;
K = 100;
r = 0.05;
T = 1;
sigma = 0.80;
N = 10.000
N = 10
H = 0.09
H = 0.0900
D_Base = zeros(1,N);
D_Var = zeros(1,N);
Z_common = randn(1, N);
for n = 1:N
% Base method
St_base = S0 * exp((r - 0.5 * sigma^2) * T + sigma * sqrt(T) * randn(1, n));
payoff_base = max(St_base - K, 0);
delta_base(n) = mean(payoff_base) / (S0 * H);
% Common random method
St_variabili_aleatorie = S0 * exp((r - 0.5 * sigma^2) * T + sigma * sqrt(T) * Z_common(1:n));
payoff_variabili_aleatorie = max(St_variabili_aleatorie - K, 0);
% H
incremento_S = S0 * H;
incremento_payoff = max(S0 + incremento_S - K, 0) - max(S0 - K, 0);
rapporto_incrementale = incremento_payoff / incremento_S;
delta_variabili_aleatorie(n) = mean(payoff_variabili_aleatorie) / (S0 * H) * rapporto_incrementale;
end
figure;
plot(1:N, D_Base, 'b', 'LineWidth', 1, 'DisplayName', 'Metodo Base');
hold on;
plot(1:N, D_Var, 'r', 'LineWidth', 1, 'DisplayName', 'Variabili Aleatorie Comuni');
xlabel('Numerosità del Campione (n)');
ylabel('Delta');
title('Calcolo del Delta mediante Metodo Monte Carlo');
legend('show');
grid on;
hold off;
  1 个评论
Rik
Rik 2024-1-26
Have a read here and here. It will greatly improve your chances of getting an answer. You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.
After adding an f (changing 'or' to 'for' to fix the syntax) this code runs to completion. You forgot to ask an actual question. And just a remark: you can edit your question, so there is no need to delete and repost.

请先登录,再进行评论。

回答(1 个)

Karl
Karl 2024-1-26
编辑:Rik 2024-1-26
In the for loop, I think that you need to change delta_base(n) to D_Base(n) and delta_variabili_aleatorie(n) to D_Var(n). This will at least result in the values plotted not being zero everywhere.
S0 = 100;
K = 100;
r = 0.05;
T = 1;
sigma = 0.80;
N = 10.000;
H = 0.09;
D_Base = zeros(1,N);
D_Var = zeros(1,N);
Z_common = randn(1, N);
for n = 1:N
% Base method
St_base = S0 * exp((r - 0.5 * sigma^2) * T + sigma * sqrt(T) * randn(1, n));
payoff_base = max(St_base - K, 0);
D_Base(n) = mean(payoff_base) / (S0 * H);
% Common random method
St_variabili_aleatorie = S0 * exp((r - 0.5 * sigma^2) * T + sigma * sqrt(T) * Z_common(1:n));
payoff_variabili_aleatorie = max(St_variabili_aleatorie - K, 0);
% H
incremento_S = S0 * H;
incremento_payoff = max(S0 + incremento_S - K, 0) - max(S0 - K, 0);
rapporto_incrementale = incremento_payoff / incremento_S;
D_Var(n) = mean(payoff_variabili_aleatorie) / (S0 * H) * rapporto_incrementale;
end
figure;
plot(1:N, D_Base, 'b', 'LineWidth', 1, 'DisplayName', 'Metodo Base');
hold on;
plot(1:N, D_Var, 'r', 'LineWidth', 1, 'DisplayName', 'Variabili Aleatorie Comuni');
xlabel('Numerosità del Campione (n)');
ylabel('Delta');
title('Calcolo del Delta mediante Metodo Monte Carlo');
legend('show');
grid on;
hold off;

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by