Forcasting prices for Gold, Oil and S&P 500 for 2017.

The packages that are required are xts, utlis and hydroTSM. The monthly data sets for Gold and S&P 500 and Daily data set for Crude Oil are loaded. Read.zoo function is used in order to read the date format. Also, the oil data set is converted into xts data frame.

require(xts)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
require(utils)
require(hydroTSM)
## Loading required package: hydroTSM
setwd("/Users/anushiarora/Desktop")
goldseries <- read.zoo("goldmonthly.csv",sep=",",
                              header=TRUE,stringsAsFactors=FALSE)
sp500series <-read.zoo("sp500_5yrs.csv",sep=",",
                        header=TRUE,stringsAsFactors=FALSE)

oilmonth <- as.xts(read.zoo("oildaily.csv",sep=",",header=TRUE))

Converting Oil daily series to monthly series.

oilmonthly <- apply.monthly(oilmonth,sum)
oilmonthly <- daily2monthly(oilmonth, FUN=mean,na.rm=TRUE)
head(oilmonthly)
##                Open     High      Low    Close    Volume Adj.Close
## 2011-11-01 24.91143 25.14143 24.65429 24.92714  490628.6  24.92714
## 2011-12-01 25.08857 25.28381 24.82952 25.06190  460404.8  25.06190
## 2012-01-01 25.58800 25.77050 25.31300 25.52650  561935.0  25.52650
## 2012-02-01 25.89600 26.11400 25.67050 25.95800 1083700.0  25.95800
## 2012-03-01 26.82955 27.05818 26.61409 26.86727  778954.5  26.86727
## 2012-04-01 25.85750 26.06050 25.67100 25.90700  612375.0  25.90700

Time series for Gold, Oil and S&P 500.

ts.gold<-ts(goldseries)
ts.gold
## Time Series:
## Start = 1 
## End = 61 
## Frequency = 1 
##      Open   High    Low  Close  Volume Adj.Close
##  1 107.80 110.22  95.75 106.91 1001600 103.38049
##  2 106.72 109.64  97.15 102.10  568700  98.72928
##  3 105.69 115.44 105.21 114.41  476900 110.63289
##  4 115.81 119.73 108.63 114.73  517900 110.94232
##  5 115.69 117.28  85.33  87.98 1125300  85.07544
##  6  85.00  92.53  80.14  89.15  853000  86.20682
##  7  87.26  88.83  72.91  79.35  757000  77.12740
##  8  80.58  96.70  80.58  90.01  917200  87.48881
##  9  89.89  94.10  82.52  89.48  505300  86.97366
## 10  89.73 103.61  86.85 102.97  466300 100.08580
## 11 102.10 124.80 100.68 123.00  888100 119.55476
## 12 123.43 127.27 116.74 119.59  558500 116.24026
## 13 119.73 122.29 100.06 107.36  566000 104.35284
## 14 107.62 107.86  96.26  99.21  503100  96.43111
## 15 101.14 102.02  91.91  94.16  512300  91.52257
## 16  95.85 100.78  81.31  82.87  589400  80.54881
## 17  81.88  86.66  79.51  85.98  617100  83.57169
## 18  85.64  85.69  66.51  81.78 1067300  79.48933
## 19  80.90  81.53  70.92  78.38  919900  76.67519
## 20  78.50  80.50  60.44  64.00 1042500  62.60797
## 21  63.82  75.41  60.17  74.27 1143200  72.65459
## 22  75.10  84.61  66.05  78.02 1030100  76.32302
## 23  79.68  80.43  69.79  71.53 1032600  69.97418
## 24  69.60  79.77  67.68  73.90  783000  72.29264
## 25  73.15  79.33  67.52  70.75  943600  69.21115
## 26  69.09  69.25  60.90  62.81  810300  61.44385
## 27  63.37  71.50  59.19  68.90  880100  67.40139
## 28  71.80  81.89  70.11  79.04  946500  77.32084
## 29  82.13  85.48  74.04  75.00  804700  73.82177
## 30  74.95  81.63  74.60  80.07  659100  78.81213
## 31  79.12  81.35  72.69  73.93  418200  72.76859
## 32  73.56  84.89  72.14  84.60  542300  83.27096
## 33  85.60  89.89  84.48  86.14  558800  84.78677
## 34  85.61  86.92  80.06  84.15  467200  82.82803
## 35  83.05  83.33  67.35  67.59  763700  66.52818
## 36  67.44  70.91  58.00  58.21 1196200  57.29554
## 37  60.16  71.36  58.40  64.68 1284700  63.66390
## 38  66.48  69.52  61.11  67.41  958600  66.35101
## 39  66.83  85.84  66.69  85.26 1272200  83.92059
## 40  83.64  85.46  75.12  79.19  810200  77.94595
## 41  79.00  79.33  66.45  69.27  927800  68.77554
## 42  69.74  78.90  69.36  76.17  669000  75.62628
## 43  75.33  77.79  70.56  72.23  510700  71.71441
## 44  72.25  73.69  66.90  66.95  498700  66.47209
## 45  66.04  67.62  57.06  60.37  738000  59.93907
## 46  59.09  68.12  57.85  60.29  954600  59.85964
## 47  60.28  61.20  54.88  59.09 1017300  58.66821
## 48  60.27  72.07  58.34  66.87  990700  66.39267
## 49  66.12  67.20  58.77  60.60  880700  60.16742
## 50  61.68  65.35  59.08  61.93  639600  61.48793
## 51  63.03  70.78  59.96  70.72  846600  70.21519
## 52  72.00  93.67  71.59  91.25 1315900  90.59864
## 53  89.89  96.50  86.61  90.81  961000  90.81000
## 54  88.10 100.52  87.95 100.50  931600 100.50000
## 55 101.28 101.60  82.85  84.31 1072200  84.31000
## 56  85.39 112.13  83.63 112.04 1162300 112.04000
## 57 117.18 126.55 110.73 117.61 1253900 117.61000
## 58 117.61 120.72  93.03  93.65  986300  93.65000
## 59  93.47 106.01  93.32 100.07  929700 100.07000
## 60 100.72 100.93  82.49  88.73 1058300  88.73000
## 61  90.34  93.87  70.58  72.19 1686400  72.19000
## attr(,"index")
##  [1] "2011-11-21" "2011-12-01" "2012-01-03" "2012-02-01" "2012-03-01"
##  [6] "2012-04-02" "2012-05-01" "2012-06-01" "2012-07-02" "2012-08-01"
## [11] "2012-09-04" "2012-10-01" "2012-11-01" "2012-12-03" "2013-01-02"
## [16] "2013-02-01" "2013-03-01" "2013-04-01" "2013-05-01" "2013-06-03"
## [21] "2013-07-01" "2013-08-01" "2013-09-03" "2013-10-01" "2013-11-01"
## [26] "2013-12-02" "2014-01-02" "2014-02-03" "2014-03-03" "2014-04-01"
## [31] "2014-05-01" "2014-06-02" "2014-07-01" "2014-08-01" "2014-09-02"
## [36] "2014-10-01" "2014-11-03" "2014-12-01" "2015-01-02" "2015-02-02"
## [41] "2015-03-02" "2015-04-01" "2015-05-01" "2015-06-01" "2015-07-01"
## [46] "2015-08-03" "2015-09-01" "2015-10-01" "2015-11-02" "2015-12-01"
## [51] "2016-01-04" "2016-02-01" "2016-03-01" "2016-04-01" "2016-05-02"
## [56] "2016-06-01" "2016-07-01" "2016-08-01" "2016-09-01" "2016-10-03"
## [61] "2016-11-01"
ts.oil<-ts(oilmonthly)
ts.oil
## Time Series:
## Start = 1 
## End = 61 
## Frequency = 1 
##         Open      High       Low     Close    Volume Adj.Close
##  1 24.911429 25.141429 24.654285 24.927143  490628.6 24.927143
##  2 25.088572 25.283810 24.829524 25.061905  460404.8 25.061905
##  3 25.588000 25.770500 25.313000 25.526500  561935.0 25.526500
##  4 25.896000 26.114000 25.670500 25.958000 1083700.0 25.958000
##  5 26.829546 27.058182 26.614091 26.867273  778954.5 26.867273
##  6 25.857500 26.060500 25.671000 25.907000  612375.0 25.907000
##  7 23.569091 23.718636 23.296364 23.462273  783463.6 23.462273
##  8 20.216666 20.440000 19.937619 20.182381  799881.0 20.182381
##  9 21.462381 21.677619 21.264762 21.494286  690714.3 21.494286
## 10 22.966956 23.174348 22.794348 23.001739  710126.1 23.001739
## 11 23.126842 23.260000 22.821053 23.021053  660305.3 23.021053
## 12 21.821429 21.999048 21.560952 21.767143  559457.1 21.767143
## 13 20.790000 20.987143 20.612381 20.807619  515328.6 20.807619
## 14 21.026500 21.166000 20.896000 21.052000  471080.0 21.052000
## 15 22.544762 22.643333 22.406667 22.551905  373181.0 22.551905
## 16 22.566842 22.702632 22.388948 22.542632  407657.9 22.542632
## 17 21.756000 21.901000 21.608000 21.791500  411495.0 21.791500
## 18 21.450000 21.645000 21.257727 21.500000  629713.6 21.500000
## 19 21.966364 22.200455 21.803182 22.037727  631931.8 22.037727
## 20 22.174500 22.368000 22.028500 22.225500  409215.0 22.225500
## 21 24.407727 24.609546 24.246818 24.476363  667104.5 24.476363
## 22 25.064091 25.256818 24.895909 25.093636  686359.1 25.093636
## 23 25.068500 25.258000 24.928000 25.107000  542180.0 25.107000
## 24 23.783043 23.966956 23.651739 23.813478  420443.5 23.813478
## 25 22.115500 22.249500 21.974500 22.097000  481905.0 22.097000
## 26 22.938571 23.056190 22.859524 22.959524  288252.4 22.959524
## 27 22.205238 22.315238 22.046667 22.177143  540257.1 22.177143
## 28 23.561579 23.717895 23.459474 23.599474  261494.7 23.599474
## 29 23.675238 23.807619 23.532381 23.659048  290328.6 23.659048
## 30 24.210476 24.329048 24.094286 24.197143  340166.7 24.197143
## 31 24.347619 24.452857 24.253809 24.360476  191757.1 24.360476
## 32 25.366190 25.465238 25.253333 25.378095  242285.7 25.378095
## 33 24.803636 24.915909 24.636363 24.758182  206854.5 24.758182
## 34 23.242857 23.358572 23.107619 23.247143  179100.0 23.247143
## 35 22.725714 22.920000 22.520000 22.726190  235571.4 22.726190
## 36 20.665652 20.866956 20.398695 20.626522  510708.7 20.626522
## 37 18.590526 18.745263 18.324737 18.476316  568578.9 18.476316
## 38 14.125909 14.372727 13.831364 14.080454 2167231.8 14.080454
## 39 10.742500 10.975000 10.515500 10.730000 4198340.0 10.730000
## 40 11.457368 11.753684 11.203684 11.477368 6022363.2 11.477368
## 41 10.443636 10.625909 10.247273 10.440909 5389109.1 10.440909
## 42 11.425238 11.705238 11.300952 11.530952 4428895.2 11.530952
## 43 12.306500 12.461000 12.148500 12.305000 3459150.0 12.305000
## 44 12.205455 12.350455 12.076818 12.229545 2836650.0 12.229545
## 45 10.197273 10.318182  9.993182 10.120455 3770213.6 10.120455
## 46  8.128571  8.322381  7.964286  8.152381 5934681.0  8.152381
## 47  8.531905  8.683333  8.348571  8.515714 3761657.1  8.515714
## 48  8.675909  8.821364  8.536364  8.678636 2996286.4  8.678636
## 49  8.003500  8.109500  7.885500  7.987500 3098200.0  7.987500
## 50  6.571364  6.689091  6.475455  6.562727 3958018.2  6.562727
## 51  5.413158  5.523158  5.207895  5.343684 7627163.2  5.343684
## 52  4.720000  4.825500  4.585500  4.710000 3544060.0  4.710000
## 53  5.296818  5.404091  5.225000  5.325000 3036418.2  5.325000
## 54  5.458095  5.573810  5.383333  5.491429 3155709.5  5.491429
## 55  6.140476  6.234286  6.046190  6.149524 2268019.0  6.149524
## 56  6.375909  6.469545  6.292727  6.395000 2414404.5  6.395000
## 57  5.781500  5.852000  5.671000  5.751500 2825250.0  5.751500
## 58  5.588696  5.685217  5.503478  5.601739 2970339.1  5.601739
## 59  5.531429  5.636190  5.452857  5.544286 3231961.9  5.544286
## 60  6.105238  6.166667  6.027143  6.098095 2532823.8  6.098095
## 61  5.422857  5.501429  5.337857  5.415714 2954385.7  5.415714
## attr(,"index")
##  [1] "2011-11-01" "2011-12-01" "2012-01-01" "2012-02-01" "2012-03-01"
##  [6] "2012-04-01" "2012-05-01" "2012-06-01" "2012-07-01" "2012-08-01"
## [11] "2012-09-01" "2012-10-01" "2012-11-01" "2012-12-01" "2013-01-01"
## [16] "2013-02-01" "2013-03-01" "2013-04-01" "2013-05-01" "2013-06-01"
## [21] "2013-07-01" "2013-08-01" "2013-09-01" "2013-10-01" "2013-11-01"
## [26] "2013-12-01" "2014-01-01" "2014-02-01" "2014-03-01" "2014-04-01"
## [31] "2014-05-01" "2014-06-01" "2014-07-01" "2014-08-01" "2014-09-01"
## [36] "2014-10-01" "2014-11-01" "2014-12-01" "2015-01-01" "2015-02-01"
## [41] "2015-03-01" "2015-04-01" "2015-05-01" "2015-06-01" "2015-07-01"
## [46] "2015-08-01" "2015-09-01" "2015-10-01" "2015-11-01" "2015-12-01"
## [51] "2016-01-01" "2016-02-01" "2016-03-01" "2016-04-01" "2016-05-01"
## [56] "2016-06-01" "2016-07-01" "2016-08-01" "2016-09-01" "2016-10-01"
## [61] "2016-11-01"
ts.sp<-ts(sp500series)
ts.sp
## Time Series:
## Start = 1 
## End = 72 
## Frequency = 1 
##       Open    High     Low   Close     Volume Adj.Close
##  1 1426.19 1509.94 1426.19 1498.11 3802304200   1498.11
##  2 1845.86 1850.84 1770.45 1782.59 3806266600   1782.59
##  3 2058.90 2072.36 1988.12 1994.99 4091934500   1994.99
##  4 1257.62 1302.67 1257.62 1286.12 4816605000   1286.12
##  5 1258.86 1333.47 1258.86 1312.41 4190155500   1312.41
##  6 1116.56 1150.45 1071.59 1073.87 5071601500   1073.87
##  7 1073.89 1112.42 1044.50 1104.49 4658238400   1104.49
##  8 1289.14 1344.07 1289.14 1327.22 3182974200   1327.22
##  9 1312.45 1378.04 1312.45 1365.68 4143404000   1365.68
## 10 1498.11 1530.94 1485.01 1514.68 3851884200   1514.68
## 11 1996.67 2119.59 1980.90 2104.50 3806470500   2104.50
## 12 1782.68 1867.92 1737.92 1859.45 3875949400   1859.45
## 13 1105.36 1180.69 1105.36 1169.43 4702951700   1169.43
## 14 1328.64 1332.28 1249.05 1325.83 4046691700   1325.83
## 15 1365.90 1419.15 1340.03 1408.47 3980752200   1408.47
## 16 1514.68 1570.28 1501.48 1569.19 3591577500   1569.19
## 17 2105.23 2117.52 2039.69 2067.89 3638745400   2067.89
## 18 1857.68 1883.97 1834.44 1872.34 3579015700   1872.34
## 19 1171.23 1219.80 1170.69 1186.69 5847150900   1186.69
## 20 1329.48 1364.56 1294.70 1363.61 4042194000   1363.61
## 21 1569.18 1597.57 1536.03 1597.57 3674685000   1597.57
## 22 1873.96 1897.28 1814.36 1883.95 3589287600   1883.95
## 23 2067.63 2125.92 2048.38 2085.51 3521458000   2085.51
## 24 1408.47 1422.38 1357.38 1397.91 3916786000   1397.91
## 25 1397.86 1415.32 1291.98 1310.33 4158095900   1310.33
## 26 1597.55 1687.18 1581.28 1630.74 3661220400   1630.74
## 27 1884.39 1924.03 1859.79 1923.57 3185100900   1923.57
## 28 2087.38 2134.72 2067.93 2107.39 3455756000   2107.39
## 29 1365.21 1370.58 1311.80 1345.20 4114534200   1345.20
## 30 1188.58 1205.13 1040.78 1089.41 6626699400   1089.41
## 31 1087.30 1131.23 1028.33 1030.71 5235174000   1030.71
## 32 1345.20 1345.20 1258.07 1320.64 4105601300   1320.64
## 33 1309.87 1363.46 1266.74 1362.16 4103472300   1362.16
## 34 2108.64 2129.87 2056.32 2063.11 3513296300   2063.11
## 35 1923.87 1968.17 1915.98 1960.23 3158130000   1960.23
## 36 1631.71 1654.19 1560.33 1606.28 3996199000   1606.28
## 37 1031.10 1120.95 1010.91 1101.60 4704026600   1101.60
## 38 1320.64 1356.48 1282.86 1292.28 4308168000   1292.28
## 39 1609.78 1698.78 1604.57 1685.73 3270645900   1685.73
## 40 1962.29 1991.39 1930.67 1930.67 3214440400   1930.67
## 41 2067.00 2132.82 2044.02 2103.84 3709178600   2103.84
## 42 1362.33 1391.74 1325.41 1379.32 3663113300   1379.32
## 43 1292.59 1307.38 1101.54 1218.89 4942913400   1218.89
## 44 1379.32 1426.68 1354.65 1406.58 3183567800   1406.58
## 45 1689.42 1709.67 1627.47 1632.97 3069868600   1632.97
## 46 1929.80 2005.04 1904.78 2003.37 2875718500   2003.37
## 47 1107.53 1129.24 1039.70 1049.33 4080773600   1049.33
## 48 2104.49 2112.66 1867.01 1972.18 4216280400   1972.18
## 49 1049.72 1157.16 1049.72 1141.20 3993981400   1141.20
## 50 1219.12 1229.29 1114.22 1131.42 5104933800   1131.42
## 51 1970.09 2020.86 1871.91 1920.03 4024497100   1920.03
## 52 2004.07 2019.26 1964.04 1972.29 3364623800   1972.29
## 53 1635.95 1729.86 1633.41 1681.55 3474152000   1681.55
## 54 1406.54 1474.51 1396.56 1440.67 3857553100   1440.67
## 55 1143.49 1196.14 1131.87 1183.26 4432102300   1183.26
## 56 1440.90 1470.96 1403.28 1412.16 3587115700   1412.16
## 57 1682.41 1775.22 1646.47 1756.54 3498866500   1756.54
## 58 1971.44 2018.19 1820.66 2018.05 4260310800   2018.05
## 59 1919.65 2094.32 1893.70 2079.36 4095504500   2079.36
## 60 1131.21 1292.66 1074.77 1253.30 4874946600   1253.30
## 61 1185.71 1227.08 1173.00 1180.55 4354084200   1180.55
## 62 1251.00 1277.55 1158.66 1246.96 4289379000   1246.96
## 63 1412.20 1434.27 1343.35 1416.18 3593110000   1416.18
## 64 1758.70 1813.55 1746.20 1805.81 3261324500   1805.81
## 65 2080.76 2116.48 2019.39 2080.41 4007931000   2080.41
## 66 2018.21 2075.76 2001.01 2067.56 3479201500   2067.56
## 67 1186.60 1262.60 1186.60 1257.64 3762922700   1257.64
## 68 1246.91 1269.37 1202.37 1257.60 3667346600   1257.60
## 69 2065.78 2093.55 1972.56 2058.90 3788631300   2058.90
## 70 2082.93 2104.27 1993.26 2043.94 3922935900   2043.94
## 71 1806.55 1849.44 1767.99 1848.36 3203412300   1848.36
## 72 1416.34 1448.00 1398.11 1426.19 3479625500   1426.19
## attr(,"index")
##  [1] "0001-02-13" "0001-02-14" "0001-02-15" "0001-03-11" "0001-03-12"
##  [6] "0001-04-10" "0002-01-10" "0002-01-11" "0002-01-12" "0002-01-13"
## [11] "0002-02-15" "0002-03-14" "0003-01-10" "0003-01-11" "0003-01-12"
## [16] "0003-01-13" "0003-02-15" "0003-03-14" "0004-01-10" "0004-01-11"
## [21] "0004-01-13" "0004-01-14" "0004-01-15" "0004-02-12" "0005-01-12"
## [26] "0005-01-13" "0005-01-14" "0005-01-15" "0005-02-11" "0005-03-10"
## [31] "0006-01-10" "0006-01-11" "0006-01-12" "0006-01-15" "0006-02-14"
## [36] "0006-03-13" "0007-01-10" "0007-01-11" "0007-01-13" "0007-01-14"
## [41] "0007-01-15" "0007-02-12" "0008-01-11" "0008-01-12" "0008-01-13"
## [46] "0008-01-14" "0008-02-10" "0008-03-15" "0009-01-10" "0009-01-11"
## [51] "0009-01-15" "0009-02-14" "0009-03-13" "0009-04-12" "0010-01-10"
## [56] "0010-01-12" "0010-01-13" "0010-01-14" "0010-01-15" "0010-03-11"
## [61] "0011-01-10" "0011-01-11" "0011-01-12" "0011-01-13" "0011-02-15"
## [66] "0011-03-14" "0012-01-10" "0012-01-11" "0012-01-14" "0012-01-15"
## [71] "0012-02-13" "0012-03-12"

Monthly Time series for Gold, Oil and S&P 500 with the plots.

ts.gold1<-ts(goldseries$Close, frequency = 12, start = c(2011), end = c(2016))    
ts.gold1
##         Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct
## 2011 106.91 102.10 114.41 114.73  87.98  89.15  79.35  90.01  89.48 102.97
## 2012 107.36  99.21  94.16  82.87  85.98  81.78  78.38  64.00  74.27  78.02
## 2013  70.75  62.81  68.90  79.04  75.00  80.07  73.93  84.60  86.14  84.15
## 2014  64.68  67.41  85.26  79.19  69.27  76.17  72.23  66.95  60.37  60.29
## 2015  60.60  61.93  70.72  91.25  90.81 100.50  84.31 112.04 117.61  93.65
## 2016  72.19                                                               
##         Nov    Dec
## 2011 123.00 119.59
## 2012  71.53  73.90
## 2013  67.59  58.21
## 2014  59.09  66.87
## 2015 100.07  88.73
## 2016
plot.ts(ts.gold1, xlab="Years", ylab="Gold Price", main="Time Series for Gold")

ts.gold2 <-decompose(ts.gold1)
plot(ts.gold2)

#From the plot it can be said that Gold Price have seasonality but no trend.

ts.oil1<-ts(oilmonthly$Close, frequency = 12, start = c(2011), end = c(2016))
ts.oil1
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2011 24.927143 25.061905 25.526500 25.958000 26.867273 25.907000 23.462273
## 2012 20.807619 21.052000 22.551905 22.542632 21.791500 21.500000 22.037727
## 2013 22.097000 22.959524 22.177143 23.599474 23.659048 24.197143 24.360476
## 2014 18.476316 14.080454 10.730000 11.477368 10.440909 11.530952 12.305000
## 2015  7.987500  6.562727  5.343684  4.710000  5.325000  5.491429  6.149524
## 2016  5.415714                                                            
##            Aug       Sep       Oct       Nov       Dec
## 2011 20.182381 21.494286 23.001739 23.021053 21.767143
## 2012 22.225500 24.476363 25.093636 25.107000 23.813478
## 2013 25.378095 24.758182 23.247143 22.726190 20.626522
## 2014 12.229545 10.120455  8.152381  8.515714  8.678636
## 2015  6.395000  5.751500  5.601739  5.544286  6.098095
## 2016
plot.ts(ts.oil1, xlab="Years", ylab="Oil Price", main="Time Series for Oil")

ts.oil2 <-decompose(ts.oil1)
plot(ts.oil2)

#From the plot it can be said that Oil Price have seasonality but no trend.

ts.sp1<-ts(sp500series$Close, frequency = 12, start = c(2011), end = c(2016))
ts.sp1
##          Jan     Feb     Mar     Apr     May     Jun     Jul     Aug
## 2011 1498.11 1782.59 1994.99 1286.12 1312.41 1073.87 1104.49 1327.22
## 2012 1169.43 1325.83 1408.47 1569.19 2067.89 1872.34 1186.69 1363.61
## 2013 1310.33 1630.74 1923.57 2107.39 1345.20 1089.41 1030.71 1320.64
## 2014 1101.60 1292.28 1685.73 1930.67 2103.84 1379.32 1218.89 1406.58
## 2015 1141.20 1131.42 1920.03 1972.29 1681.55 1440.67 1183.26 1412.16
## 2016 1180.55                                                        
##          Sep     Oct     Nov     Dec
## 2011 1365.68 1514.68 2104.50 1859.45
## 2012 1597.57 1883.95 2085.51 1397.91
## 2013 1362.16 2063.11 1960.23 1606.28
## 2014 1632.97 2003.37 1049.33 1972.18
## 2015 1756.54 2018.05 2079.36 1253.30
## 2016
plot.ts(ts.sp1,  xlab="Years", ylab="S&P 500 value", main="Time Series for S&P500")

ts.sp2 <-decompose(ts.sp1)
plot(ts.sp2)

Correlation between Gold and Oil using time series analysis

Correlation between gold and oil series can be estimated by combining both the series as they are of the same frequency

combine <- cbind(ts.gold1,ts.oil1)
plot.ts (combine, xlab="Years", main="Correlation between Gold and Oil") 

HoltWinter’s filtering for Gold, Oil and S&P500 with plots.

rain.gold<- HoltWinters(ts.gold1, gamma=TRUE)
plot(rain.gold,xlab="Years", ylab="Observed/Fitted values for Gold", main="Holt-Winter's filtering for Gold")

rain.oil<- HoltWinters(ts.oil1, gamma=TRUE)
plot(rain.oil,xlab="Years", ylab="Observed/Fitted values for Oil", main="Holt-Winter's filtering for Oil")

rain.sp <- HoltWinters(ts.sp1, gamma=TRUE)
plot(rain.sp,xlab="Years", ylab="Observed/Fitted values for S&P 500", main="Holt-Winter's filtering for S&P 500" )

Forecasts from HoltWinters for Gold, Oil and S&P 500.

library(forecast)
## Loading required package: timeDate
## This is forecast 7.3
## 
## Attaching package: 'forecast'
## The following object is masked from 'package:hydroTSM':
## 
##     ma
rain.forecastgold <- forecast.HoltWinters(rain.gold, h=12, start=c(2011), end=c(2016))
plot.forecast(rain.forecastgold,xlab ="Years",ylab = "Gold Price", main = "Forecasts from HoltWinters for Gold")

rain.forecastoil <- forecast.HoltWinters(rain.oil, h=12, start=c(2011), end=c(2016))
plot.forecast(rain.forecastoil,xlab ="Years",ylab = "Oil Price", main = "Forecasts from HoltWinters for Oil")

rain.forecastsp <- forecast.HoltWinters(rain.sp, h=12, start=c(2012), end=c(2016))
plot.forecast(rain.forecastsp,xlab ="Years",ylab = "S&P 500 Value", main = "Forecasts from HoltWinters for S&P 500")

Forecasts from ARIMA 1,2,1 for Gold, Oil and S&P 500

To quantify the variance in time series forecasts.

auto.arima(ts.sp1)
## Series: ts.sp1 
## ARIMA(0,0,0)(1,1,0)[12]                    
## 
## Coefficients:
##          sar1
##       -0.6893
## s.e.   0.1008
## 
## sigma^2 estimated as 90974:  log likelihood=-352.64
## AIC=709.28   AICc=709.54   BIC=713.06
sp500.arima<-arima(ts.sp1, c(1,0,0))    
sp500.arima.forecasts <- forecast.Arima(sp500.arima, h=12)
plot(sp500.arima.forecasts,xlab ="Years",ylab = "S&P 500 Value", main = "Forecasts from ARIMA for S&P 500")

auto.arima(ts.gold1)
## Series: ts.gold1 
## ARIMA(0,1,0)(0,1,1)[12]                    
## 
## Coefficients:
##          sma1
##       -0.7881
## s.e.   0.4297
## 
## sigma^2 estimated as 131.1:  log likelihood=-189.86
## AIC=383.73   AICc=384   BIC=387.47
gold.arima<-arima(ts.gold1, c(0,1,0))    
gold.arima.forecasts <- forecast.Arima(gold.arima, h=12)
plot(gold.arima.forecasts,xlab ="Years",ylab = "Gold Price", main = "Forecasts from ARIMA for Gold" )

auto.arima(ts.oil1)
## Series: ts.oil1 
## ARIMA(0,1,1)(0,0,1)[12]                    
## 
## Coefficients:
##          ma1    sma1
##       0.3742  0.3334
## s.e.  0.1079  0.1437
## 
## sigma^2 estimated as 1.348:  log likelihood=-93.87
## AIC=193.73   AICc=194.16   BIC=200.01
oil.arima<-arima(ts.oil1, c(0,1,1))    
oil.arima.forecasts <- forecast.Arima(oil.arima, h=12)
plot(oil.arima.forecasts,xlab ="Years",ylab = "Oil Price", main = "Forecasts from ARIMA for Oil")

1. Prove the correlation between Gold and Oil using time series analysis

From the time series of Gold & Oil it can be said that Gold and Oil prices are dollar dominated, hence they are strongly linked. For an instance, when we consider the years from 2014 to 2016, the time series plot depictss that Gold prices is going high while the oil prices at the same time are going completely low, almost below the average. This shows that there is a negative correlation between gold and oil prices. Similarly, if we look at the years before 2013, the oil and gold prices show almost similar respective ups and downs in the prices, proving that there is an average correlation. Hence there is a correlation between gold and crude oil prices.

2. Complete the forecast between Gold, Oil, or SP500 based for 2017. How should you invest your money?

Decomposition of additive time series:

Trend Analysis for Gold: For Gold, there has been a major downfall between 2012 and 2013. The gold prices didn’t overcome the downfall until 2015. Though there was a slight improvement last year, but the trend shows that its not that much in control.

Trend Analysis for Oil: Till mid of 2013 the oil prices approximately remained the same. But from 2014, a major downfall is experienced in the price of oil. And hence investment in crude oil will not be a good option.

Trend Analysis for S&P 500: There have been almost the same trend for every year in S&P 500. Also there is seasonality in the S&p 500 prices that states that there are same kind of changes very year.

Forecast from HoltWinters:

For Oil: For the year 2017, there is the same trend followed like the year 2016. There is no major increase in the price of the crude oil. So looking at the trend and HoltWinters forecast, we can say that investing in crude oil is not an option.

For Gold: The starting of the year 2017 will show a downfall going below 50 dollar. And it continues even for the mid of the year. When nearing the end of the year, the prices go high up to 65-75 dollar. But at the end of the year there is downfall by few dollars.

For S&P 500: The value for S&P 500 for 2017 is on a average scale up to mid of 2017 where there is a downfall. But there is a peak in price after that and a slight downfall and again increase by the end of the year. This can be an option for investing, as the trend is not same like last year. There is no high decrease in prices.

Hence, considering the Trend and Forecast from HoltWinters we can say that, investment in crude oil is a bad choice. Investment in S&P 500, can be a good option, if only the investment is done in the beginning of the year and sold when there is a increase in prices at the mid of the year. And investment in Gold is also similar, though its unruly but still it can also be an option if bought at starting of the year and sold at the end of the year when there is peak in prices.

But if we look at “Forecast from ARIMA”, the S&P 500 forecast at (1,0,0) is almost a straight line after an increase in the price and for gold is a straight line at (0,1,0). So if we consider the forecast from ARIMA at (0,1,1) for Oil, which is also a straight constant line. Since there is an increase in the beginning for S&P 500, we should invest money in S&P 500.

This investment choice is done only considering the previous 5 year’s prices data. We are not actually considering the Tesla impact, new presidency of U.S. which is effecting the dollar rate which will indirectly affect the prices of commodities. The Economic growth also plays major role. Hence, considering only the prices of last 5 years is bad way to calculate whether to invest the money on Crude Oil, Gold or S&P 500.