Why is this function returning the wrong size matrix

6 ビュー (過去 30 日間)
Ali
Ali 2013 年 3 月 30 日
I wrote a very simple function to calculate stock price return regardless of the number of companies listed in the array. The company stock prices are listed in separate columns. The function code is:
function percentReturn=retCalc(prices)
percentReturn=prices(1:end-1,:)./prices(2:end,:)-1;
I would assume that this function should calculate the return regardless of the number of columns in the matrix. However, it just returns the first column of return. Can someone please tell me what I'm doing wrong?
  1 件のコメント
Cedric
Cedric 2013 年 3 月 30 日
編集済み: Cedric 2013 年 3 月 30 日
Did you check that the local variable prices has really the correct size? If you add the line
size(prices)
right before the line computing percentReturn, you might see that prices doesn't have as many columns (companies) as what you think. Well, reading again your statement .. the way you perform your computation suggests that there is one company per column, and therefore that prices vary along rows, which is not what you seem to indicate above.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by