%% Aggregate Timetable Data to Weekly Periodicity
% Load the simulated stock price data and corresponding logarithmic returns SimulatedStockSeries.mat.

load SimulatedStockSeries

% The timetable DataTable contains measurements recorded at various, irregular times during trading hours (09:30 to 16:00) of the New York Stock Exchange (NYSE) from January 1, 2018 through December 31, 2020.
% For example, display the first few observations.

head(DataTable)

% DataTable does not include business calendar awareness. If you want to account for nonbusiness days (weekends, holidays, and market closures) and you have a Financial Toolbox™ license, add business calendar awareness by using the addBusinessCalendar function.
% Aggregate the price series to a weekly series by reporting the final price in each week.

WeeklyPrice = convert2weekly(DataTable(:,"Price"));

% WeeklyPrice is a timetable containing the final prices for each reported week in DataTable.
% Copyright 2021 The MathWorks, Inc.