How to remove stock prices that falls on weekend ?

3 次查看(过去 30 天)
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