Compute an indicator for n components and store the results in a vector

조회 수: 3 (최근 30일)
Nicu Sprincean
Nicu Sprincean 2016년 10월 28일
편집: Nicu Sprincean 2016년 10월 28일
Hi, Matlab users, I have the following code to compute Marginal Expected Shortfall for one company:
% We need to have the same days for market_returns and firm_returns
if length(firm_returns)~=length(market_returns)
error('Unequal number of days for firm and market');
end
% Find the 5% quantile the market return
low_threshold = prctile(market_returns,5);
% Find the 5% worst days for the market return
worst_days = market_returns < low_threshold;
% Take the average of the firm's returns during the worst days of the
% market
mes = mean(firm_returns(worst_days));
Now, I have 2+ companies from the same country, and the same market portfolio (index). How can I change the above code to compute mes for all companies and store the results in a vector? I'm a newbie here and I'm thinking for a 'for loop' but don't know how to apply. Many thanks.

답변 (0개)

카테고리

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