Assignment Week 3-3B Approach
Approach
I will use an LLM to generate a simulated time-series dataset of daily closing prices for three fictional stocks, with columns for the date, item, and closing price, covering weekdays from January 2025 to November 2026. Because the data covers two years, I can check that the year-to-date average restarts each January. I will save the dataset as a CSV file on GitHub so the code can be run on any computer.
In R, I will use dplyr window functions to calculate, separately for each item:
- Year-to-date (YTD) average: the average closing price from January 1 of the same year up to the current day. I will group by item and year, sort by date, and use
cummean(). - Six-day moving average: the average of the current day and the five previous trading days. I will group by item, sort by date, and use
lag()to get the five previous prices.
Anticipated Challenges
- Data quality: I will check that the dates are correctly formatted and in chronological order, and that there are no missing values.
- The first days of each item: the first five rows do not have six days of data, so their six-day moving average will be
NAinstead of an average of fewer days. - Checking the results: I will calculate a few values by hand and confirm that they match the results.