Playing with time series matrices

8 visualizaciones (últimos 30 días)
Dinh Xuan TRAN
Dinh Xuan TRAN el 31 de Ag. de 2015
Respondida: Cam Salzberger el 3 de Sept. de 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

Respuestas (1)

Cam Salzberger
Cam Salzberger el 3 de Sept. de 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

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by