calculating returns every 5 minutes

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 Comments

Edit your question by putting your string between quotes.
d={'1-jan-16 9:00', '1-jan-16 9:01'}
Done Azzi, sorry for the mistake but I am new using Matlab. Can you helpe to solve my doubt? Thanks!!
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?
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!

Sign in to comment.

Answers (0)

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Asked:

on 21 Apr 2016

Commented:

on 23 Apr 2016

Community Treasure Hunt

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

Start Hunting!