필터 지우기
필터 지우기

How to remove stock prices that falls on weekend ?

조회 수: 1 (최근 30일)
Sana Ejaz
Sana Ejaz 2019년 2월 26일
댓글: Stephan 2019년 3월 2일
So I have got a big cell array having stock pricess of almost 1000 companies and then another datetime array having dates.I want to remove stock prices that falls on weekends.
I managed to get a logical column vector using is weekend function on the date time array but now I don't know how to use that logical column vector to remove rows of stock prices.
I tried using logical indexing but it didn't work.
  댓글 수: 7
Sana Ejaz
Sana Ejaz 2019년 3월 2일
Hi,
Actually my data is really huge and I can't open it.So I dont know how to extraxt a small sample.I am just a beginer and don't know even basic stuff related to MATLAB.So I am not sure if I can extract and save a small sample of my data.I know I can read my data using textscan but I am not sure if I can save a short sample
Stephan
Stephan 2019년 3월 2일
im sure you have a csv, text or xls file as base. Dont you? extract 2-3 weeks from it and save a copy. if you do not know how to do this in Matlab perhaps you can do this in Excel or editor.

댓글을 달려면 로그인하십시오.

답변 (1개)

Naman Bhaia
Naman Bhaia 2019년 3월 1일
Hey Sana,
After you have generated the logical vector you can use that logical vector as index positions to eliminate the values which fall on weekends. Consider the example
x=[1 2 3 4 5 6 7 8 9 10];
y=[1 1 0 1 1 0 1 1 0 1];
x(~y)=[]
You may also visit this MATLAB answer to know more about your problem.
  댓글 수: 4
Stephan
Stephan 2019년 3월 1일
Maybe creating a timetable is a good choice, since the usual functions of Financial Toolbox accept timetables as input argument. Deleting values from a table by logical statements is also very easy.
Sana Ejaz
Sana Ejaz 2019년 3월 2일
I created a timetable using below code
TT = array2timetable(stockprices,'RowTimes',datstms);
TT = TT(~isweekend(TT.Time),:);
but this wasnt working even.
I guess my textscan code have got some problem as it is not reading data properly.
I am using below code to read 1 2 7 and 17 column of my data file.
for i = 1:nolines
tline = fgetl(fid);
new = textscan(tline,['%s %s %*f %*s %*f %*f %f' , repmat('%*f',[1,5]) '%*s %*f %*f %*f %f %*[^/n]'],'delimiter',',', 'MultipleDelimsAsOne',1);
dt= new{:,2}; %extracting second column of data
datstms(i,:)= dt;
st= new{:,3};%extracting third column
stockprices (i,:) = st;
adjfactor = new{:,4};
CFACPR(i,:) = adjfactor;
end
above code was working since yesterday but now it is not working.textscan is just reading the second column whereas Third and fourth column is blank with [] this sighn.
after storing data in different variables I am now trying to know if I have got any weekend in my data or not
tf = isweekend(datstms);
if tf == 1 %checking if we have got a weekend in our dataset or not
disp('its a weekend');
stockprices(tf,:) = []; %remove data that falls on weekend
else
disp('no weekend');
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by