but for the original data set tickers will have different number of dates so it will not be possible to put them in a table (I think?)
Not a problem, as long as there's good overlap between the date. If they're completely distinct then it may be a waste of time.
Using your demo test file:
numdateperticker = arrayfun(@(s) numel(s.Date), stocks);
tickers = table(datetime(vertcat(stocks.Date)), vertcat(stocks.AdjClose), repelem({stocks.Ticker}', numdateperticker), ...
'VariableNames', {'Date', 'AdjClose', 'Ticker'});
tickers = table2timetable(unstack(tickers, 'AdjClose', 'Ticker'))
Tickers for which there's no value for a date will get a NaN for that particular date.
Now to plot this for a given time range:
range = timerange('01-Jan-2016', '10-Apr-2018');
selectedtickers = {'AAPL', 'FB'};
tickersrange = tickers(range, :);
plot(tickersrange.Properties.RowTimes, tickersrange{:, selectedtickers});
legend(selectedtickers);
Or using stacked plots, even simpler:
range = timerange('01-Jan-2016', '10-Apr-2018');
selectedtickers = {'AAPL', 'FB'};
stackedplot(tickers(range, selectedtickers));
Best Answer