A common use of forecasting implementing exponential smoothing is within Finance. To preface, I don’t know much about finance and investing. But I have heard more than once of people trying to forecast and predict the stock market, though the masses have not harnessed this knowledge yet, or it’s hidden behind yet another Financial Guru’s pay wall. In a scenario like this, I would suspect alpha to be very high, given the volatile nature of the stock market. While there are trends in fiance and economics over time, with predictable trends during certain seasons like the holidays, summer, election cycles, and so on, the unpredictable and second to second nature of the world is evident in the Stock market, to my incomplete understanding.
From last week’s HW, we have already determined that there did not appear to be any clear trends in our summer temperatures throughout the years. With Holt-Winter’s method, we can verify this since it performs overall, trend, and seasonality smoothing with the parameters alpha, beta, and gamma respectively. Let’s load our data as a time series and visualize it. Prior to our exponential smoothing, let’s use a rolling average of 7 and 30 days to smooth our data as well, to make our graphs less “noisy”.
library(zoo)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
#prepare data as time series
#exclude DAY column, unlist, and convert dataset to a vector first
temps <- read.table("temps.txt", header=TRUE)
temp_ts <- ts(as.vector(unlist(temps[,-1])), frequency = 123, start = 1996)
temp_ts
## Time Series:
## Start = c(1996, 1)
## End = c(2015, 123)
## Frequency = 123
## [1] 98 97 97 90 89 93 93 91 93 93 90 91 93 93 82 91 96 95
## [19] 96 99 91 95 91 93 84 84 82 79 90 91 87 86 90 84 91 93
## [37] 88 91 84 90 89 88 86 84 86 89 90 91 91 90 89 90 91 91
## [55] 91 84 88 84 86 88 84 82 80 73 87 84 87 89 89 89 91 84
## [73] 86 88 78 79 86 82 82 78 79 79 78 81 84 84 87 84 79 75
## [91] 72 64 66 72 84 70 66 64 60 78 70 72 69 69 73 79 81 80
## [109] 82 66 63 68 79 81 69 73 73 75 75 81 82 82 81 86 90 93
## [127] 91 84 84 75 87 84 87 84 88 86 90 91 91 89 89 89 90 89
## [145] 84 87 88 89 89 91 91 89 88 72 80 84 88 89 88 84 84 80
## [163] 73 80 86 88 88 87 88 91 91 89 89 88 82 79 81 82 84 87
## [181] 90 90 91 91 88 88 91 93 81 81 82 86 88 84 80 82 86 87
## [199] 87 88 88 90 88 91 95 89 70 80 82 66 70 64 68 77 86 75
## [217] 73 75 78 81 82 82 82 80 82 82 79 80 68 63 57 66 64 69
## [235] 70 70 62 63 62 75 71 57 55 64 66 60 91 88 91 91 91 89
## [253] 93 95 95 91 91 86 88 87 91 87 90 91 95 91 91 89 91 91
## [271] 86 88 80 88 89 90 86 86 82 84 86 90 89 89 86 82 87 88
## [289] 84 86 80 82 86 84 87 90 79 84 87 87 88 90 91 89 90 93
## [307] 93 91 87 84 77 90 91 89 90 89 79 78 81 84 89 87 87 88
## [325] 87 82 80 82 82 88 84 81 82 84 87 80 75 75 86 78 77 82
## [343] 82 73 82 69 72 73 78 78 78 75 79 78 77 78 82 75 73 63
## [361] 63 72 75 79 79 79 78 82 79 84 82 87 88 90 91 82 86 87
## [379] 87 82 77 73 81 81 86 82 87 88 90 90 91 93 93 91 93 93
## [397] 93 93 97 99 96 93 88 89 91 93 93 93 91 90 96 98 97 98
## [415] 93 93 96 98 98 89 91 91 90 80 82 89 88 90 91 91 84 88
## [433] 91 84 93 96 96 91 91 77 87 87 87 86 87 89 81 81 82 79
## [451] 68 79 72 75 78 81 82 78 80 77 71 73 75 84 71 73 71 73
## [469] 73 72 72 73 70 64 75 73 77 80 71 66 60 64 73 57 59 64
## [487] 69 75 73 72 75 75 89 91 93 95 96 96 96 91 96 99 96 93
## [505] 91 93 93 93 91 97 100 99 93 96 87 82 75 82 88 91 89 87
## [523] 86 86 81 84 88 91 91 91 91 96 95 89 89 89 89 94 97 99
## [541] 101 101 97 87 86 88 92 92 90 90 92 92 88 87 79 81 82 87
## [559] 81 66 66 75 80 82 84 86 87 86 80 75 73 73 84 87 77 73
## [577] 81 84 82 68 71 75 73 75 77 79 82 81 82 73 66 55 55 64
## [595] 71 73 75 75 77 80 80 80 73 73 75 79 75 75 78 75 78 80
## [613] 75 77 78 84 87 87 84 86 87 87 89 91 87 90 90 86 82 82
## [631] 84 87 88 90 87 84 87 90 84 82 88 90 84 89 89 87 84 84
## [649] 84 86 88 84 86 88 87 88 86 86 81 87 84 90 91 91 87 86
## [667] 88 90 88 93 90 91 91 81 86 81 82 80 75 73 81 90 88 87
## [685] 86 86 89 87 84 84 86 77 77 81 81 82 84 86 87 88 69 66
## [703] 72 75 78 71 71 75 80 81 80 79 70 68 79 66 73 75 78 78
## [721] 75 75 62 60 64 71 75 79 80 81 79 73 64 51 55 63 72 71
## [739] 90 90 87 89 93 93 89 89 90 91 84 77 82 88 91 93 93 93
## [757] 93 91 95 91 89 87 84 86 89 91 91 88 90 93 91 91 91 93
## [775] 97 87 87 86 88 89 91 91 89 88 90 91 93 91 93 93 91 95
## [793] 93 91 88 84 82 82 78 77 84 84 89 95 93 91 88 87 91 95
## [811] 95 90 75 78 91 88 86 81 80 86 84 77 82 73 69 75 75 79
## [829] 73 79 82 84 84 82 87 86 80 71 66 70 78 84 79 68 57 66
## [847] 64 68 71 73 71 64 59 68 60 68 69 75 75 68 60 73 81 87
## [865] 86 80 84 87 90 89 84 84 86 87 84 86 88 88 88 88 88 89
## [883] 86 81 82 84 87 87 89 88 84 88 84 84 84 82 84 82 84 84
## [901] 86 87 84 81 87 89 90 86 89 90 90 87 88 88 90 89 88 89
## [919] 90 91 89 88 89 88 86 87 87 84 73 75 81 82 79 80 81 84
## [937] 82 82 81 81 81 84 87 82 75 81 80 82 82 82 73 66 71 72
## [955] 68 66 77 78 75 73 73 73 73 66 78 78 78 69 72 68 70 75
## [973] 78 84 78 78 73 73 68 64 57 70 77 75 82 81 86 88 90 90
## [991] 89 87 88 89 90 89 91 91 84 84 84 87 84 88 89 89 93 95
## [1009] 89 87 84 89 87 89 90 91 90 91 91 90 84 81 82 84 75 82
## [1027] 80 77 82 82 84 86 86 89 88 82 84 84 87 82 86 88 90 87
## [1045] 88 87 82 80 81 82 84 81 86 73 84 84 84 81 79 79 73 75
## [1063] 80 79 78 73 75 80 84 82 81 79 72 78 78 80 82 82 80 81
## [1081] 80 75 75 73 71 71 77 73 64 63 62 71 75 73 68 71 73 73
## [1099] 70 73 78 79 81 78 75 78 82 91 89 86 86 89 82 76 88 89
## [1117] 78 83 86 84 87 84 85 89 90 89 89 90 91 91 90 92 94 92
## [1135] 90 83 78 84 82 86 88 91 88 86 80 82 85 83 87 88 86 90
## [1153] 92 89 90 90 89 92 94 93 87 85 84 84 86 86 85 85 85 85
## [1171] 88 87 85 81 81 83 85 86 84 84 86 88 88 91 88 86 88 90
## [1189] 90 90 86 87 88 85 77 86 85 85 82 83 85 83 85 81 72 72
## [1207] 73 70 77 82 74 77 78 79 76 75 81 83 83 80 67 70 56 54
## [1225] 61 63 62 64 69 70 93 93 93 91 90 81 80 82 84 84 90 91
## [1243] 91 91 91 91 93 93 96 93 93 91 86 87 88 93 95 96 91 91
## [1261] 94 95 95 97 98 96 89 97 96 95 96 88 84 81 87 86 89 86
## [1279] 88 88 93 91 88 87 83 85 88 88 90 90 88 80 85 86 85 88
## [1297] 83 85 80 83 83 85 84 82 70 80 82 83 85 85 79 73 75 82
## [1315] 86 84 75 78 79 81 70 75 83 81 82 84 86 76 72 72 79 80
## [1333] 80 71 62 69 70 59 71 77 76 69 69 70 53 56 55 62 66 63
## [1351] 72 73 68 95 85 82 86 88 87 82 82 89 86 85 87 86 84 81
## [1369] 86 89 89 88 86 86 79 82 87 87 87 90 89 87 92 90 92 92
## [1387] 94 97 96 98 98 100 103 103 100 90 100 99 102 101 101 97 95 96
## [1405] 99 104 98 95 94 92 88 88 89 89 86 84 83 88 91 89 85 86
## [1423] 88 89 89 89 86 85 81 82 76 78 79 82 81 78 86 83 89 87
## [1441] 84 85 85 81 79 80 82 77 80 81 82 83 83 81 81 67 72 74
## [1459] 78 78 76 82 77 76 75 78 72 81 59 61 68 67 70 62 67 71
## [1477] 85 87 91 90 88 82 88 90 89 87 89 93 85 88 89 89 88 90
## [1495] 91 94 95 92 87 88 89 87 90 93 92 90 88 89 92 91 91 92
## [1513] 94 90 86 85 85 88 81 81 84 87 86 85 86 90 90 85 82 78
## [1531] 83 78 83 80 86 89 89 88 81 85 83 85 88 87 89 90 88 87
## [1549] 83 87 86 88 79 80 69 82 81 79 75 84 82 78 82 80 77 86
## [1567] 86 86 74 74 80 83 83 82 82 72 75 77 78 77 77 80 81 83
## [1585] 69 67 65 66 72 68 62 54 67 70 59 50 59 65 67 95 90 89
## [1603] 91 80 87 86 82 84 84 86 90 84 89 89 90 88 82 80 82 86
## [1621] 84 87 88 90 92 90 89 85 82 85 89 83 90 92 92 89 91 92
## [1639] 93 93 95 86 90 90 90 88 87 88 90 88 88 85 81 86 87 90
## [1657] 83 75 86 79 79 71 78 79 83 83 85 84 87 84 80 75 81 80
## [1675] 82 79 82 73 80 74 81 79 84 83 85 87 85 80 83 72 74 76
## [1693] 75 76 74 62 71 79 80 85 74 77 66 73 66 61 61 51 55 61
## [1711] 68 71 74 72 69 65 65 60 71 75 66 69 87 84 83 85 88 89
## [1729] 94 97 96 90 93 90 91 91 94 89 87 83 90 91 94 95 97 94
## [1747] 95 95 93 90 94 95 95 96 84 92 95 93 93 91 93 94 94 95
## [1765] 95 96 89 90 90 91 93 92 93 93 94 93 90 89 90 89 87 84
## [1783] 85 89 90 91 92 84 85 90 91 93 92 94 96 89 86 91 91 89
## [1801] 95 93 92 96 95 92 91 88 93 76 81 76 79 76 79 78 68 67
## [1819] 70 73 81 82 85 86 86 80 80 73 78 76 80 78 82 77 80 78
## [1837] 76 81 76 85 76 74 68 71 75 92 94 95 92 90 90 94 94 91
## [1855] 92 95 95 97 90 80 85 87 89 94 91 92 94 92 92 90 94 94
## [1873] 90 93 96 96 91 96 97 85 96 93 93 94 91 95 94 95 95 94
## [1891] 88 90 92 94 96 93 94 98 92 93 95 99 95 95 93 90 92 95
## [1909] 96 95 80 78 75 69 73 81 84 86 87 89 92 86 72 79 77 77
## [1927] 82 86 80 83 82 88 86 84 79 84 78 65 68 75 80 83 81 79
## [1945] 78 72 68 65 73 74 77 80 84 85 80 67 59 63 68 70 73 76
## [1963] 77 79 74 59 61 65 105 93 99 98 100 98 93 95 97 95 90 84
## [1981] 90 90 90 92 93 93 91 84 90 95 97 97 98 98 97 97 94 96
## [1999] 88 94 99 94 87 90 86 84 92 88 87 85 88 91 88 85 91 87
## [2017] 87 84 84 88 84 88 86 85 90 90 80 86 80 89 91 89 85 77
## [2035] 85 85 92 88 83 84 83 81 81 83 87 86 83 79 81 79 85 87
## [2053] 81 78 82 86 88 86 84 72 75 72 74 82 82 83 68 63 70 73
## [2071] 75 79 75 77 77 74 75 74 73 71 76 79 78 79 80 80 70 56
## [2089] 56 56 65 82 85 76 77 83 83 79 88 88 87 80 87 78 85 86
## [2107] 87 91 87 90 86 87 85 84 86 89 86 82 86 86 90 80 87 89
## [2125] 88 90 88 88 86 83 89 90 90 90 89 83 73 67 66 77 82 84
## [2143] 84 88 90 84 82 82 86 90 92 87 90 90 84 90 89 89 88 88
## [2161] 91 90 89 89 90 87 82 84 89 79 78 84 86 73 82 82 71 67
## [2179] 78 79 77 76 77 82 82 82 85 84 84 74 72 76 80 79 81 82
## [2197] 77 68 74 72 73 63 70 72 69 63 66 56 61 69 64 75 78 74
## [2215] 90 93 87 84 86 87 89 90 90 87 85 90 89 90 86 83 86 82
## [2233] 85 76 82 83 88 87 88 89 92 90 82 84 85 81 84 88 90 89
## [2251] 92 95 90 89 86 83 88 84 85 87 88 89 89 86 89 92 93 93
## [2269] 88 84 86 88 91 92 88 89 90 90 92 82 89 91 90 84 84 86
## [2287] 90 92 86 78 80 86 86 85 84 83 87 82 77 78 77 74 78 74
## [2305] 71 84 86 85 78 65 71 78 82 86 86 86 86 85 85 75 69 70
## [2323] 80 76 73 73 77 70 72 74 77 84 84 77 73 68 63 85 87 79
## [2341] 85 84 84 90 90 91 93 92 93 92 90 89 88 93 92 91 93 93
## [2359] 92 88 91 90 91 92 94 93 94 93 89 94 94 97 95 88 88 92
## [2377] 93 94 91 90 89 90 90 90 89 88 89 88 89 92 87 89 84 86
## [2395] 85 83 81 74 84 87 90 89 92 87 85 85 84 87 85 86 78 75
## [2413] 77 80 79 83 83 87 89 77 76 81 74 67 71 71 75 77 85 71
## [2431] 66 66 70 73 76 81 82 81 71 73 76 81 78 81 77 70 66 64
## [2449] 71 76 79 81 76 71 67 56 78 70 70 62
#from hw3, no clear trends over 20 year period
#but there appears to be seasonal trends/oscillations
#to be expected as summer ends and fall starts
plot(temp_ts)
#use rollmean to smooth data so graph isn't as noisy
#use previous week and month temp to find rolling avg temp
temp_mean7 <- rollmean(temp_ts, 7, fill=NA, align='right')
plot(temp_mean7)
temp_mean30 <- rollmean(temp_ts, 30, fill=NA, align='right')
plot(temp_mean30)
Again, we see no clear trends in our time series over time, though we do see oscillations which is expected since we know our data represents the change in temperatures from July through October. Let’s apply Holt-Winter’s method and interpret the output
#apply Holt-Winters
#so what do alpha, beta, and gamma tell us?
temp_HW <- HoltWinters(temp_ts)
temp_HW
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = temp_ts)
##
## Smoothing parameters:
## alpha: 0.6610618
## beta : 0
## gamma: 0.6248076
##
## Coefficients:
## [,1]
## a 71.477236414
## b -0.004362918
## s1 18.590169842
## s2 17.803098732
## s3 12.204442890
## s4 13.233948865
## s5 12.957258705
## s6 11.525341233
## s7 10.854441534
## s8 10.199632666
## s9 8.694767348
## s10 5.983076192
## s11 3.123493477
## s12 4.698228193
## s13 2.730023168
## s14 2.995935818
## s15 1.714600919
## s16 2.486701224
## s17 6.382595268
## s18 5.081837636
## s19 7.571432660
## s20 6.165047647
## s21 9.560458487
## s22 9.700133847
## s23 8.808383245
## s24 8.505505527
## s25 7.406809208
## s26 6.839204571
## s27 6.368261304
## s28 6.382080380
## s29 4.552058253
## s30 6.877476437
## s31 4.823330209
## s32 4.931885957
## s33 7.109879628
## s34 6.178469084
## s35 4.886891317
## s36 3.890547248
## s37 2.148316257
## s38 2.524866001
## s39 3.008098232
## s40 3.041663870
## s41 2.251741386
## s42 0.101091985
## s43 -0.123337548
## s44 -1.445675315
## s45 -1.802768181
## s46 -2.192036338
## s47 -0.180954242
## s48 1.538987281
## s49 5.075394760
## s50 6.740978049
## s51 7.737089782
## s52 8.579515859
## s53 8.408834158
## s54 4.704976718
## s55 1.827215229
## s56 -1.275747384
## s57 1.389899699
## s58 1.376842871
## s59 0.509553410
## s60 1.886439429
## s61 -0.806454923
## s62 5.221873550
## s63 5.383073482
## s64 4.265584552
## s65 3.841481452
## s66 -0.231239928
## s67 0.542761270
## s68 0.780131779
## s69 1.096690727
## s70 0.690525998
## s71 2.301303414
## s72 2.965913580
## s73 4.393732595
## s74 2.744547070
## s75 1.035278911
## s76 1.170709479
## s77 2.796838283
## s78 2.000312540
## s79 0.007337449
## s80 -1.203916069
## s81 0.352397232
## s82 0.675108103
## s83 -3.169643942
## s84 -1.913321175
## s85 -1.647780450
## s86 -5.281261301
## s87 -5.126493027
## s88 -2.637666754
## s89 -2.342133004
## s90 -3.281910970
## s91 -4.242033198
## s92 -2.596010530
## s93 -7.821281290
## s94 -8.814741200
## s95 -8.996689798
## s96 -7.835655534
## s97 -5.749139155
## s98 -5.196182693
## s99 -8.623793296
## s100 -11.809355220
## s101 -13.129428554
## s102 -16.095143067
## s103 -15.125436350
## s104 -13.963606549
## s105 -12.953304848
## s106 -16.097179844
## s107 -15.489223470
## s108 -13.680122300
## s109 -11.921434142
## s110 -12.035411347
## s111 -12.837047727
## s112 -9.095808127
## s113 -5.433029341
## s114 -6.800835107
## s115 -8.413639598
## s116 -10.912409484
## s117 -13.553826535
## s118 -10.652543677
## s119 -12.627298331
## s120 -9.906981556
## s121 -12.668519900
## s122 -9.805502547
## s123 -7.775306633
Our overall smoothing parameter indicates that there are changes year to year. As our initial and rolling average plots show, there is variability year to year. This value indicates that for forecasting, more recent data has a greater impact than older data.
Our trend smoothing parameter indicates that there is no trend in our time series, as we suspected. So, we can conclude the end of summer is not being postponed.
Our seasonality smoothing parameter indicates that our oscillations correspond with the known behavior of temperatures between July and October.
So our Holt-Winter’s model indicates that for forecasting, we can expect behavior at given intervals dependent on recent data. It also tells us that there is no long term trend in our data. While we already gathered this from last week’s assignment, the use of exponential smoothing and Holt-Winter’s method is valuable in understanding that despite no overall trend, we still experience large enough variability season to season, so we shouldn’t use the entire time series to make future predictions. Furthermore, we could compare compare a larger timeline of data to see if our forecasting is the same, our compare the forecasting between different geographic regions and use Atlanta as a baseline for what no overall trend looks like statistically.