Error about Worst performer calculate
2 views (last 30 days)
Show older comments
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)
WP=min(R1)
------------------------------------------
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 Comments
Image Analyst
on 26 Sep 2023
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?
Hyunuk Ha
on 26 Sep 2023
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)'
Answers (1)
Shivam Lahoti
on 18 Oct 2023
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.
0 Comments
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!