calculating returns every 5 minutes

1 次查看(过去 30 天)
angelavtc
angelavtc 2016-4-21
评论: angelavtc 2016-4-23
Hello! I would be really happy if you help me to solve this doubt :)
I have a date column,for example,
d=['1-jan-16 9:00', '1-jan-16 9:01','1-jan-16 9:02','1-jan-16 9:03', '1-jan-16 9:04', '1-jan-16 9:05', ...., '10-feb-16 9:00', '10-feb-16 9:01','10-feb-16 9:02','10-feb-16 9:03', '10-jan-16 9:04', '10-feb-16 9:05']
(dates are in matlab format) that is associated with some stock prices (another column)
p=[10.1, 10, 10.01, 10.002, 11, 11.2 ,..., 14,14.05, 15.01, 14.04, 13, 13.02]
I want to create a third column that calculates the stock return for every day and for every 5 minutes. To calculate the return I use the formula log(price 1-jan-16 9:05)-log (1-jan-16 price 9:00)= log(11.2)-log(10.1) and the next 5 minutes return will be log(price 1-jan-16 9:10)-log (1-jan-16 price 9:05)and so on.
I would like to create another column doing the same but starting at 9:01 and calculating the 5 minutes return of 9:06 vs 9:01 for every day.
Does anyone have an idea of how to solve this problem?
I would be really really grateful if you can help me,
Have a nice day!
  4 个评论
Brendan Hamm
Brendan Hamm 2016-4-22
MATLAB has many formats for dates, but what you have given above for d would not be one of them. You literally have a single string which looks like this below:
d = '1-jan-16 9:001-jan-16 9:011-jan-16 9:021-jan ...' %... means the pattern continues
The answer to this question is going to depend on the variable type that 'd' really is. Please provide the result of:
class(d)
What version of MATLAB are you using? There are "better" answers depending on this. Also, do you have the Financial Toolbox?
angelavtc
angelavtc 2016-4-23
Ok Brendan, here is the answer: class(d)
ans =
char
And the Date is exhibited in matlab date format number "0": 04-Jan-1990 13:10:00
And my Matlab version is 2012 and I havent tried with the financial toolbook? Is it for free?
Thanks!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series Objects 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by