Error about Worst performer calculate

ns=10000;
face=10000;
val_date='2023-09-26';
mid_date= ['2024-03-21';'2024-09-23';'2025-03-21';'2025-09-23';'2026-03-23';'2026-09-18'];
strike=[1.0 0.95 0.9 0.85 0.8 0.75];
c_rate=[0.05 0.1 0.15 0.2 0.25 0.3];
dummy=0.3;
ki=0.5;
ki_YesNO='NO';
ref_S= [9179.5];
S=[6165.71];
r=0.05;
vol=[0.09];
rho=0.37;
temp_ch=datenum(mid_date)'-datenum(val_date);
mid_ch=temp_ch(find(temp_ch>=0));
c_rate=c_rate(find(temp_ch>=0));
strike=strike(find(temp_ch>=0));
N=mid_ch(end);
dt=1/365;
mid_size=length(mid_ch);
payment=zeros(ns,mid_size);
for i =1:ns
for j=1:mid_size
payment(i,j)=face*(1+c_rate(j));
end
end
corr=[1 rho;rho 1];
M=chol(corr);
SP1=zeros(ns,N+1);
SP1(:,1)=S(1);
for i=1:ns
w0=randn(N,2);
w=w0*M;
for j=2:N+1
SP1(i,j)=SP1(i,j-1)*exp((r-vol(1)^2/2)*dt+...
vol(1)*sqrt(dt)*w(j-1,1));
end
end
R1=SP1/ref_S(1);
size(R1)
ans = 1×2
10000 1089
WP=min(R1)
WP = 1×1089
0.6717 0.6600 0.6526 0.6545 0.6506 0.6460 0.6474 0.6454 0.6410 0.6410 0.6384 0.6359 0.6318 0.6294 0.6275 0.6245 0.6229 0.6251 0.6240 0.6211 0.6178 0.6196 0.6184 0.6204 0.6188 0.6188 0.6185 0.6161 0.6152 0.6129
------------------------------------------
The WP's derivation value should be as many as 10000 simulations, but only one line is derived, so the subsequent analysis process cannot be performed. Please help me

5 个评论

You take the columnwise minimum of a 10000x1089 matrix. This gives a 1x1089 vector.
If you take the rowwise minimum (WP = min(R1,[],2)), you will get a 10000x1 vector of values. I don't know if that is what you want.
I want to draw out 10000*1089 vector how can i solve it
I don't understand what you mean.
A 10000*1089 array is a 2-D matrix, not a 1-D vector. I don't know what "draw out" means to you. Do you mean "plot"? Or "extract"? Or something else?
Do you mean draw 1089 lines with 1000 x 1089 matrix?
Basically, you can draw column numbers of lines with matrix data using 'plot(matrixdata)'

请先登录,再进行评论。

回答(1 个)

Hi 형현,
From what I can understand, you expect the Worst performer matrix or WP to be a 10000*1 vector, but you are getting a 1*1089 vector.
In the code that is attached, WP is calculated as min(R1), and R1 is a 10000*1089 matrix. min(R1) calculates the column-wise minimum and hence produces a 1*1089 vector, you might want a row-wise minimum which could be calculated as:
WP = min(R1,[],2);
And the plot function could be leveraged to visualize the same.
I hope this helps.
Regards,
Shivam Lahoti.

类别

在 帮助中心 和 File Exchange 中查找有关 Financial Toolbox 的更多信息

提问:

2023-9-25

Community Treasure Hunt

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

Start Hunting!

Translated by