calculating returns every 5 minutes
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Brendan Hamm
il 22 Apr 2016
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?
Risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!