Playing with time series matrices

1 view (last 30 days)
Dinh Xuan TRAN
Dinh Xuan TRAN on 31 Aug 2015
Answered: Cam Salzberger on 3 Sep 2015
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

Answers (1)

Cam Salzberger
Cam Salzberger on 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

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!