I have this code to calculate Value-at-Risk with Monte Carlo simulation
function mean_percentile=MCSimulation(num_sim,seed,p,input_file)database=xlsread(input_file);[row,col]=size(database);percentili=zeros(row,seed);for j=1:seedfor i=1:row a=normrnd(database(i,1),database(i,2),1,num_sim); percentili(i,j) = prctile(a(1,:),p); clear aend randn('state',sum(100*clock));endmean_percentile=zeros(row,1);for i=1:rowmean_percentile(i,1)=-mean(percentili(i,:));endclear databaseend
but then when i try using it I have this error message:
Attempt to reference field of non-structure array.
Can anyone help me please?
thanks very much!
Best Answer