How to remove stock prices that falls on weekend ?

3 visualizaciones (últimos 30 días)
Sana Ejaz
Sana Ejaz el 26 de Feb. de 2019
Comentada: Stephan el 2 de Mzo. de 2019
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 comentarios
Sana Ejaz
Sana Ejaz el 2 de Mzo. de 2019
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 el 2 de Mzo. de 2019
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.

Iniciar sesión para comentar.

Respuestas (1)

Naman Bhaia
Naman Bhaia el 1 de Mzo. de 2019
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 comentarios
Stephan
Stephan el 1 de Mzo. de 2019
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 el 2 de Mzo. de 2019
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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by