gap adjustment in time series data
조회 수: 1 (최근 30일)
이전 댓글 표시
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
the cyclist
2011년 4월 1일
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?
채택된 답변
추가 답변 (2개)
Jarrod Rivituso
2011년 4월 2일
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
Taylor
2011년 4월 3일
댓글 수: 1
Jarrod Rivituso
2011년 4월 3일
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]
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!