I'm trying to populate a 3d matrix with profit and loss values for cells defined ccs, cp and woy which are unique entries of my original data currencyPair, counterpartyAlias and weekofYear cells respectively. Unfortunately, length of ccs is 117, cp is 1380 and woy is 25 so the matrix takes a couple of days to calculate. However, the majority of rows and columns are zeros because most counterparties only deal across selective currency pairs. Is there a way to populate the matrix without calculating the zero entries? I tried concatenating the ccs and cp cells before looking for the unique entries but then I have nothing to use a strcmp against. Any ideas would be greatly appreciated!
PnL_CCSvsCP = zeros(length(ccs),length(cp),length(woy));for i=1:length(ccs) for j=1:length(cp) for k=1:length(woy) PnL_CCSvsCP(i,j,k) = sum(PnL(strcmp(currencyPair,ccs{i}) & ... strcmp(counterpartyAlias,cp{j}) & ... (weekofYear == woy(k)))); end endend
Best Answer