Borrar filtros
Borrar filtros

gap adjustment in time series data

2 visualizaciones (últimos 30 días)
Taylor
Taylor el 1 de Abr. de 2011
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
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?

Iniciar sesión para comentar.

Respuesta aceptada

Taylor
Taylor el 5 de Abr. de 2011
I guess I'm just going to take the difference close(t)-open(t) and then numerically integrate to get what I want. This will be a lot simpler (but the error will get bigger and bigger I suppose).

Más respuestas (2)

Jarrod Rivituso
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
  1. Create array with overlapping data next to each other
  2. Define a logical array that indicates which elements should be removed
  3. Use logical indexing to set those elements to "empty"
Hope this helps!

Taylor
Taylor el 3 de Abr. de 2011
Hm. I'm still a little confused on two points:
1.)What exactly do you mean by "overlapping"? In the case of a candle stick chart do you mean a vector like this: [open(1),close(1),open(2),close(2),open(3),close(3),...]? If you mean this, then I don't know how useful the "diff" operator is going to be. i'm testing for open(n)-close(n-1) not equal to zero, but if we're using that vector above, you'll get some values that are of the form close(n)-open(n) which pretty much always is going to be non-zero.
2.)also, you're telling me to remove elements, right. I'm looking to shift subsets of the data around and not delete anything.
To answer the comment above, the code executes fine, but it isn't doing what I want it to do. I start to get confused when there is more than one gap to adjust. If there's only one, then we just run the for loop to find that spot, keep the back half the same, and then shift the front half down or up by the size of the gap.
But if there's more than one gap, as soon as we get to (at least) the second one, i can't really figure out what to keep. We have to keep the "first part" of a new vector. And for an arbitrarily large data set, how do I plan for these multiple gaps?
For those of you who aren't familiar with the candle stick charts, just check out some website like freestockcharts.com or whatever.
  1 comentario
Jarrod Rivituso
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]

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB 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!

Translated by