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!