Economic data is often reported on the last day of each month or quarter. So end-of-month ambiguities can arise when computing period-over-period returns for periods that exceed the periodicity at which data is reported.
Simulate five years of daily prices and store the result in the timetable TT
.
ans=10×1 timetable
Time Prices
___________ ______
01-Jan-2014 100
02-Jan-2014 100
03-Jan-2014 100
04-Jan-2014 100
05-Jan-2014 100.01
06-Jan-2014 100.01
07-Jan-2014 100.02
08-Jan-2014 100.02
09-Jan-2014 100.04
10-Jan-2014 100.06
Create a new timetable by sampling TT
on the last day of each month to mimic monthly reporting.
ans=10×1 timetable
Time Prices
___________ ______
31-Jan-2014 100.47
28-Feb-2014 100.93
31-Mar-2014 102
30-Apr-2014 102.28
31-May-2014 103.22
30-Jun-2014 103.92
31-Jul-2014 102.2
31-Aug-2014 104.79
30-Sep-2014 103.11
31-Oct-2014 105.29
Display a subset of the dates and compare a direct calculation of the dates in previous months to those shifted to the end of the month in which the previous period occurs.
ans = 13x3 datetime
29-Feb-2016 28-Feb-2015 28-Feb-2015
31-Mar-2016 31-Mar-2015 31-Mar-2015
30-Apr-2016 30-Apr-2015 30-Apr-2015
31-May-2016 31-May-2015 31-May-2015
30-Jun-2016 30-Jun-2015 30-Jun-2015
31-Jul-2016 31-Jul-2015 31-Jul-2015
31-Aug-2016 31-Aug-2015 31-Aug-2015
30-Sep-2016 30-Sep-2015 30-Sep-2015
31-Oct-2016 31-Oct-2015 31-Oct-2015
30-Nov-2016 30-Nov-2015 30-Nov-2015
31-Dec-2016 31-Dec-2015 31-Dec-2015
31-Jan-2017 31-Jan-2016 31-Jan-2016
28-Feb-2017 28-Feb-2016 29-Feb-2016
Examine these results and notice that the dates in the second and third columns of the last row differ. Specifically, when the current date in the first column is 28-Feb-2017
the dates in the second and third columns differ because 2016 is a leap year. More generally, the dates differ whenever the month of the previous period has more days than the current month for which returns are computed. In this example, end-of-months dates present the following ambiguity. When the current date of interest is 28-Feb-2017
, should subtracting one calendar year produce 28-Feb-2016
or 29-Feb-2016
?
The correct answer depends on the application, and both approaches are valid use cases. This problem is exacerbated, for example, when working with end-of-monthly price data and computing month-over-month returns. To address the end-of-month ambiguity, the rollingreturns
function supports an EndOfMonth
flag.
The EndOfMonth
flag ensures that the rollingreturns
function uses the correct end-of-month date of each calendar month. In this example, the return on 28-Feb-2017
is correctly computed from the price reported 29-Feb-2016
rather than 28-Feb-2016
.
ans=13×2 timetable
Time Prices Prices_Return_1y
___________ ______ ________________
29-Feb-2016 135.59 0.21671
31-Mar-2016 138.47 0.25052
30-Apr-2016 131.44 0.11598
31-May-2016 129.34 0.083068
30-Jun-2016 133.86 0.077865
31-Jul-2016 132.78 0.046253
31-Aug-2016 140.32 0.11871
30-Sep-2016 136.52 0.087549
31-Oct-2016 141.27 0.10652
30-Nov-2016 140.76 0.1053
31-Dec-2016 135.96 0.057643
31-Jan-2017 129.52 0.0099025
28-Feb-2017 136.36 0.0056789