Playing with time series matrices
显示 更早的评论
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
回答(1 个)
Cam Salzberger
2015-9-3
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
类别
在 帮助中心 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!