Info

This question is closed. Reopen it to edit or answer.

Hello, I have that code and I really can't identify it's use. Can anyone correct that code and let me know what it's purpose? Thank yo

1 view (last 30 days)
function [ relMyScen ] = f_relativeMyScen( myScen)
% This function computes the 'relative' MyScen (from each asset, it subtracts the (peer/benchmark) portfolio return)
% myScen is a 3-D matrix (or tensor) of scenarios (NxTxK), N=number of assets, K = number of scenarios T = time period (scalar number of months)
% w_peer is Nx1 vector of portfolio weights where N=number of assets
s1 = size(myScen,1); % num of assets
s2 = size(myScen,2); % num of periods
s3 = size(myScen,3); % num of simulations
ret_peer = sum( repmat(w_peer(:), 1,s2, s3) .* myScen, 1 );
relMyScen = myScen + repmat(ret_peer, s2, 1, 1) ;
end
  8 Comments
Antonis
Antonis on 27 Jul 2014
This is one of the tasks that I have to do. But I really can not understand anything about that code and what their orders doing. That's why I have asked that question here that I know there are probably more experienced people in this forum than me.
Image Analyst
Image Analyst on 27 Jul 2014
That did not answer the question, so I'm going to assume it is homework and tag it as such. Good luck. If you do what I said in my answer then you'll see an error with a pretty obvious cause. If you fix that one, then there may or may not be another.

Answers (1)

Image Analyst
Image Analyst on 27 Jul 2014
Edited: Image Analyst on 27 Jul 2014
What if you just make up data? Like make up a 3D array and pass it in and see what errors you get:
function test3
clc;
a = rand(3,4,2);
relMyScen = f_relativeMyScen(a)

Products

Community Treasure Hunt

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

Start Hunting!