Problems with logical indexing

1 view (last 30 days)
Tobi
Tobi on 12 Oct 2013
Hi all,
I have problem with using local indexing and cumsum. I have a matrix in which each column its self gets cumulated until a certain symmetric boundary is hit (here 0.05). When the boundary gets hit the code shall start the cumulation (cumsum) new, BUT only for the column the event occurred. So each column shall cumsum for its own. The mistake must be in the indexing section for the cumsum. I don't know how else to address multiple matrix indexes, but this method does not work.
I think there is a way to do it with sub2ind, for example if I have a start indexes [1 3542 7083] and as end indexes [3541 7082 10623]. But I don't know how to implement this in a cumsum...
I'd very much appreciate help :) Thanks!
Cheers Tobi
This is my code so far:
if true
% code
T = 3541,
N = 13;
% Exposure Matrices
EXP_Curr = zeros(T,N);
Diff_EXP_Curr = zeros(T,N);
EXP_Portf = zeros(T,1);
Cum_Portf_EXP = zeros(T,1);
Cum_Curr_EXP = zeros(T,N);
EXP_Portf_reset = 1;
EXP_Curr_reset(1,1:N) = 1;
C = zeros(T,N);
for i=1:T
%Exposure
%Exposure per currency per day: Days x Currencies
%Histweights_LCY und CurrencyMatrix werden vorbestimmt und sind definitiv fehlerfrei
EXP_Curr(i,:) = HistWeights_LCY(i,:) * CurrencyMatrix';
if i >= 2 && i <= T-1
%Exposure difference per day
Diff_EXP_Curr(i,:) = diff(log(EXP_Curr(i - 1:i,:))).*EXP_Curr(i - 1,:);
%Total Portfolio Exposure per day
EXP_Portf(i,:) = sum(Diff_EXP_Curr(i,:),2);
%Cumulative Portfolio Exposure per day
Cum_Portf_EXP(EXP_Portf_reset:end,:) = cumsum(EXP_Portf(EXP_Portf_reset:end,:));
%Cumulative Exposure per Currency
%HERE MUST BE THE MISTAKE
Cum_Curr_EXP(EXP_Curr_reset:end,:) = cumsum(Diff_EXP_Curr(EXP_Curr_reset:end,:),1);
%Logical Matices
%rebalance all currencies
if abs(Cum_Portf_EXP(i,1)) >= cut_off
EXP_Portf_reset = i;
end
%rebalance single currencies
CurrExpBreach = abs(Cum_Curr_EXP(i,:)) >= cut_off;
EXP_Curr_reset(1,CurrExpBreach) = i + 1;
end
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!