Playing with time series matrices
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I have a time series matrix (ie : first column being a date, second a value of an investment) and I wish to compute the daily returns. What's the formulae I should use in the command windows ? Thanks, Xuan
0 commentaires
Réponses (1)
Cam Salzberger
le 3 Sep 2015
Hello Dinh,
I understand that you are looking to determine the daily return from investment data. I am assuming that your data is formatted similarly to this:
Data = [datenum(now-30:now).' 500*rand(31,1)+1000];
The daily return can be calculated quite simply using the diff function to determine the gain or loss from each day:
dailyGain = [0 ; diff(Data(:,2))];
dailyReturn = dailyGain/Data(1,2);
The data can then be easily visualized, including the dates on the x-axis, with:
plot(datetime(Data(:,1),'ConvertFrom','datenum'),dailyReturn)
If your dates are something other than MATLAB datenums, you can still convert them with the datetime function's 'ConvertFrom' parameter.
I hope this helps with your financial data calculations.
-Cam
0 commentaires
Voir également
Catégories
En savoir plus sur Language Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!