Playing with time series matrices
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Cam Salzberger
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!