Why is this function returning the wrong size matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Cedric
il 30 Mar 2013
Modificato: Cedric
il 30 Mar 2013
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!