gap adjustment in time series data
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've only just started using Matlab, and I already have a question with a little thing I'm working on for fun. I have open high low close data for a stock, and I'm trying to make a function that outputs a new time series that closes the morning gaps (shifts the whole time series so that all the open prices of every bar are equal to the previous bars close). Here's my code:
%gapadjust
%[newOpen, newHigh, newLow, newClose] = gapadjust(open,high,low,close,time)
%this function forward adjusts a time series for gaps
%(in case you don't have any overnight exposure)
function [newOpen, newHigh, newLow, newClose] = gapadjust(open,high,low,close,time)
if nargin<5
disp('need more arguments');
end
for index=2:size(time,1)
if abs(open(index)-close(index-1))>.01
x=open(index)-close(index-1);
shiftVector = [zeros((index-1),1); x*ones(size(time,1)-(index-1),1)];
newOpen=open-shiftVector;
newHigh=high-shiftVector;
newLow=low-shiftVector;
newClose=close-shiftVector;
end
end
Thanks very much for any help.
1 comentario
the cyclist
el 1 de Abr. de 2011
So, what's the question? Is the code failing to execute? Are you getting an error or a warning? Is it producing incorrect results?
Also, could you use the code markup tools to improve the layout of the code, to make it more readable?
Respuesta aceptada
Más respuestas (2)
Jarrod Rivituso
el 2 de Abr. de 2011
Here's a little example that has helped me in similar situations.
>> x1 = [1 2 3 4 5]
>> x2 = [5 4 3 2 1]
>> xtot = [x1 x2]
>> conditionForRemoval = diff(xtot) == 0
>> xtot(conditionForRemoval) = []
The main steps in that code are
- Create array with overlapping data next to each other
- Define a logical array that indicates which elements should be removed
- Use logical indexing to set those elements to "empty"
Hope this helps!
0 comentarios
Taylor
el 3 de Abr. de 2011
1 comentario
Jarrod Rivituso
el 3 de Abr. de 2011
Hi Taylor,
It seems I have misunderstood your question. I'm still not sure I completely understand the data inputs you have and the desired output.
Is it something like this...
open - [1.0,3.1,4.2,5.4]
close - [3.0,4.2,5.1,5.8]
If so, what are your desired output arrays? Is it this...?
open - [1.0,3.0,4.2,5.1]
close - [3.0,4.2,5.1,5.8]
Ver también
Categorías
Más información sobre Graphics Performance 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!