Equipo:

A00833617 | Yessica Acosta Blancheth

A01275763 | Eli Gabriel Hernández Medina

A00833172 | Genaro Rodríguez Alcántara

Background

• Briefly describe the selected company / variable (i.e., What is the company’s background? What is the consumer price index?)

In the fast-paced world of finance, companies are constantly looking for ways to leverage their historical data to gain insight and make informed decisions. In this context, this project focuses on the construction of a time series model to analyze the financial performance of the company “Canadian Solar Inc.”

The main objective of this project is to develop a model to understand and predict the performance of Canadian Solar Inc. shares and other relevant financial variables. To achieve this, time series analysis techniques will be used, which will provide crucial information for decision-making at both a strategic and operational level.

• How has been the stock price / variable’s performance in the last year? At first glance, we can see that, in the last year, the variable that indicates the price of the company has had a performance that seems constant, because despite constant variations throughout the year, it ended the year with very similar values. at the beginning of the year, considering a lot of variability throughout the year. However, it is important to analyze this data in depth and compare it with previous years to identify the seasonality of the data and to have a more accurate model for this company. For this reason, we will begin with an exploratory analysis of the data that allows us to discover insights about the data and the behavior of the variable over the years.

# Loading
library(xts)
library(dplyr)
library(zoo)
library(tseries)
library(stats)
library(forecast)
library(astsa)
library(corrplot)
library(AER)
library(vars)
library(dynlm)
library(vars)
library(TSstudio)
library(tidyverse)
library(sarima)
library(dygraphs)
# Import dataset

CSIQ<-read.csv( "//Users/genarorodriguezalcantara/Desktop/Tec/Introduction to econometrics/ts_stock_prices/CSIQ.csv")

head(CSIQ)
##         Date  Open  High   Low Close Adj.Close   Volume
## 1 2015-01-05 24.20 24.51 21.72 22.90     22.90  9388500
## 2 2015-01-12 22.66 23.16 21.01 21.29     21.29 10843500
## 3 2015-01-19 21.06 21.19 18.68 19.30     19.30 15126400
## 4 2015-01-26 19.25 20.73 18.98 20.39     20.39 10836000
## 5 2015-02-02 20.84 27.35 20.63 25.66     25.66 29040500
## 6 2015-02-09 25.62 29.72 25.57 28.84     28.84 16991600
colnames(CSIQ)
## [1] "Date"      "Open"      "High"      "Low"       "Close"     "Adj.Close"
## [7] "Volume"
# Setting time series format
# Here we are checking the date data in our database
CSIQ$Date
##   [1] "2015-01-05" "2015-01-12" "2015-01-19" "2015-01-26" "2015-02-02"
##   [6] "2015-02-09" "2015-02-16" "2015-02-23" "2015-03-02" "2015-03-09"
##  [11] "2015-03-16" "2015-03-23" "2015-03-30" "2015-04-06" "2015-04-13"
##  [16] "2015-04-20" "2015-04-27" "2015-05-04" "2015-05-11" "2015-05-18"
##  [21] "2015-05-25" "2015-06-01" "2015-06-08" "2015-06-15" "2015-06-22"
##  [26] "2015-06-29" "2015-07-06" "2015-07-13" "2015-07-20" "2015-07-27"
##  [31] "2015-08-03" "2015-08-10" "2015-08-17" "2015-08-24" "2015-08-31"
##  [36] "2015-09-07" "2015-09-14" "2015-09-21" "2015-09-28" "2015-10-05"
##  [41] "2015-10-12" "2015-10-19" "2015-10-26" "2015-11-02" "2015-11-09"
##  [46] "2015-11-16" "2015-11-23" "2015-11-30" "2015-12-07" "2015-12-14"
##  [51] "2015-12-21" "2015-12-28" "2016-01-04" "2016-01-11" "2016-01-18"
##  [56] "2016-01-25" "2016-02-01" "2016-02-08" "2016-02-15" "2016-02-22"
##  [61] "2016-02-29" "2016-03-07" "2016-03-14" "2016-03-21" "2016-03-28"
##  [66] "2016-04-04" "2016-04-11" "2016-04-18" "2016-04-25" "2016-05-02"
##  [71] "2016-05-09" "2016-05-16" "2016-05-23" "2016-05-30" "2016-06-06"
##  [76] "2016-06-13" "2016-06-20" "2016-06-27" "2016-07-04" "2016-07-11"
##  [81] "2016-07-18" "2016-07-25" "2016-08-01" "2016-08-08" "2016-08-15"
##  [86] "2016-08-22" "2016-08-29" "2016-09-05" "2016-09-12" "2016-09-19"
##  [91] "2016-09-26" "2016-10-03" "2016-10-10" "2016-10-17" "2016-10-24"
##  [96] "2016-10-31" "2016-11-07" "2016-11-14" "2016-11-21" "2016-11-28"
## [101] "2016-12-05" "2016-12-12" "2016-12-19" "2016-12-26" "2017-01-02"
## [106] "2017-01-09" "2017-01-16" "2017-01-23" "2017-01-30" "2017-02-06"
## [111] "2017-02-13" "2017-02-20" "2017-02-27" "2017-03-06" "2017-03-13"
## [116] "2017-03-20" "2017-03-27" "2017-04-03" "2017-04-10" "2017-04-17"
## [121] "2017-04-24" "2017-05-01" "2017-05-08" "2017-05-15" "2017-05-22"
## [126] "2017-05-29" "2017-06-05" "2017-06-12" "2017-06-19" "2017-06-26"
## [131] "2017-07-03" "2017-07-10" "2017-07-17" "2017-07-24" "2017-07-31"
## [136] "2017-08-07" "2017-08-14" "2017-08-21" "2017-08-28" "2017-09-04"
## [141] "2017-09-11" "2017-09-18" "2017-09-25" "2017-10-02" "2017-10-09"
## [146] "2017-10-16" "2017-10-23" "2017-10-30" "2017-11-06" "2017-11-13"
## [151] "2017-11-20" "2017-11-27" "2017-12-04" "2017-12-11" "2017-12-18"
## [156] "2017-12-25" "2018-01-01" "2018-01-08" "2018-01-15" "2018-01-22"
## [161] "2018-01-29" "2018-02-05" "2018-02-12" "2018-02-19" "2018-02-26"
## [166] "2018-03-05" "2018-03-12" "2018-03-19" "2018-03-26" "2018-04-02"
## [171] "2018-04-09" "2018-04-16" "2018-04-23" "2018-04-30" "2018-05-07"
## [176] "2018-05-14" "2018-05-21" "2018-05-28" "2018-06-04" "2018-06-11"
## [181] "2018-06-18" "2018-06-25" "2018-07-02" "2018-07-09" "2018-07-16"
## [186] "2018-07-23" "2018-07-30" "2018-08-06" "2018-08-13" "2018-08-20"
## [191] "2018-08-27" "2018-09-03" "2018-09-10" "2018-09-17" "2018-09-24"
## [196] "2018-10-01" "2018-10-08" "2018-10-15" "2018-10-22" "2018-10-29"
## [201] "2018-11-05" "2018-11-12" "2018-11-19" "2018-11-26" "2018-12-03"
## [206] "2018-12-10" "2018-12-17" "2018-12-24" "2018-12-31" "2019-01-07"
## [211] "2019-01-14" "2019-01-21" "2019-01-28" "2019-02-04" "2019-02-11"
## [216] "2019-02-18" "2019-02-25" "2019-03-04" "2019-03-11" "2019-03-18"
## [221] "2019-03-25" "2019-04-01" "2019-04-08" "2019-04-15" "2019-04-22"
## [226] "2019-04-29" "2019-05-06" "2019-05-13" "2019-05-20" "2019-05-27"
## [231] "2019-06-03" "2019-06-10" "2019-06-17" "2019-06-24" "2019-07-01"
## [236] "2019-07-08" "2019-07-15" "2019-07-22" "2019-07-29" "2019-08-05"
## [241] "2019-08-12" "2019-08-19" "2019-08-26" "2019-09-02" "2019-09-09"
## [246] "2019-09-16" "2019-09-23" "2019-09-30" "2019-10-07" "2019-10-14"
## [251] "2019-10-21" "2019-10-28" "2019-11-04" "2019-11-11" "2019-11-18"
## [256] "2019-11-25" "2019-12-02" "2019-12-09" "2019-12-16" "2019-12-23"
## [261] "2019-12-30" "2020-01-06" "2020-01-13" "2020-01-20" "2020-01-27"
## [266] "2020-02-03" "2020-02-10" "2020-02-17" "2020-02-24" "2020-03-02"
## [271] "2020-03-09" "2020-03-16" "2020-03-23" "2020-03-30" "2020-04-06"
## [276] "2020-04-13" "2020-04-20" "2020-04-27" "2020-05-04" "2020-05-11"
## [281] "2020-05-18" "2020-05-25" "2020-06-01" "2020-06-08" "2020-06-15"
## [286] "2020-06-22" "2020-06-29" "2020-07-06" "2020-07-13" "2020-07-20"
## [291] "2020-07-27" "2020-08-03" "2020-08-10" "2020-08-17" "2020-08-24"
## [296] "2020-08-31" "2020-09-07" "2020-09-14" "2020-09-21" "2020-09-28"
## [301] "2020-10-05" "2020-10-12" "2020-10-19" "2020-10-26" "2020-11-02"
## [306] "2020-11-09" "2020-11-16" "2020-11-23" "2020-11-30" "2020-12-07"
## [311] "2020-12-14" "2020-12-21" "2020-12-28" "2021-01-04" "2021-01-11"
## [316] "2021-01-18" "2021-01-25" "2021-02-01" "2021-02-08" "2021-02-15"
## [321] "2021-02-22" "2021-03-01" "2021-03-08" "2021-03-15" "2021-03-22"
## [326] "2021-03-29" "2021-04-05" "2021-04-12" "2021-04-19" "2021-04-26"
## [331] "2021-05-03" "2021-05-10" "2021-05-17" "2021-05-24" "2021-05-31"
## [336] "2021-06-07" "2021-06-14" "2021-06-21" "2021-06-28" "2021-07-05"
## [341] "2021-07-12" "2021-07-19" "2021-07-26" "2021-08-02" "2021-08-09"
## [346] "2021-08-16" "2021-08-23" "2021-08-30" "2021-09-06" "2021-09-13"
## [351] "2021-09-20" "2021-09-27" "2021-10-04" "2021-10-11" "2021-10-18"
## [356] "2021-10-25" "2021-11-01" "2021-11-08" "2021-11-15" "2021-11-22"
## [361] "2021-11-29" "2021-12-06" "2021-12-13" "2021-12-20" "2021-12-27"
## [366] "2022-01-03" "2022-01-10" "2022-01-17" "2022-01-24" "2022-01-31"
## [371] "2022-02-07" "2022-02-14" "2022-02-21" "2022-02-28" "2022-03-07"
## [376] "2022-03-14" "2022-03-21" "2022-03-28" "2022-04-04" "2022-04-11"
## [381] "2022-04-18" "2022-04-25" "2022-05-02" "2022-05-09" "2022-05-16"
## [386] "2022-05-23" "2022-05-30" "2022-06-06" "2022-06-13" "2022-06-20"
## [391] "2022-06-27" "2022-07-04" "2022-07-11" "2022-07-18" "2022-07-25"
## [396] "2022-08-01" "2022-08-08" "2022-08-15" "2022-08-22" "2022-08-29"
## [401] "2022-09-05" "2022-09-12" "2022-09-19" "2022-09-26" "2022-10-03"
## [406] "2022-10-10" "2022-10-17" "2022-10-24" "2022-10-31" "2022-11-07"
## [411] "2022-11-14" "2022-11-21" "2022-11-28" "2022-12-05" "2022-12-12"
## [416] "2022-12-19" "2022-12-26"
# Suponiendo que las fechas están en formato "dd/mm/yyyy"
CSIQ$Date <- as.Date(CSIQ$Date)
 # para que tome en cuenta el mes, dia y  año - permite visualizar la linea de tiempo
summary(CSIQ$Adj.Close) # checar el precio mínimo, máximo y mediana
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   11.07   16.19   20.41   24.26   32.36   63.00

Visualization

• Plot the stock price / variable using a time series format.

class(CSIQ$Date)
## [1] "Date"
# time series plot 1
plot(CSIQ$Date,CSIQ$Adj.Close,type="l",col="blue", lwd=2, xlab ="Date",ylab ="Adjusted Close Price", main = "Canadian Solar Inc Stock Price")

  #en esta serie de tiempo primero se observa una tendencia decreciente ( en este caso )
  #hay que hacer la serie estaciona
# Time series plot 2

CSIQxts<-xts(CSIQ$Adj.Close,order.by=CSIQ$Date)
plot(CSIQxts)

# ti series plot 3 ## mejor plot
dygraph(CSIQxts, main = "Canadian Solar Inc") %>% 
  dyOptions(colors = RColorBrewer::brewer.pal(4, "Dark2")) %>%
  dyShading(from = "2018-07-02",
            to = "2022-07-04", 
            color = "#FFE6E6")
# Stationary Test
adf.test(CSIQ$Adj.Close)   ### H0: Non-stationary and HA: Stationary. p-values < 0.05 reject the H0. 
## 
##  Augmented Dickey-Fuller Test
## 
## data:  CSIQ$Adj.Close
## Dickey-Fuller = -2.5048, Lag order = 7, p-value = 0.3642
## alternative hypothesis: stationary
                         ### P-Value > 0.05. Fails to Reject the H0. Time series data is non-stationary.
What did happen to GE Stock Price?

• Decompose the time series data in observed, trend, seasonality, and random.

CSIQts<-ts(CSIQ$Adj.Close,frequency=52,start=c(2015,1))
CSIQ_ts_decompose<-decompose(CSIQts)
plot(CSIQ_ts_decompose)

# ver el comportamiendo de las variables randome (cambio abruptos, cariables desconocidas, si es constante y no hay mucho cambio significa que
# la variación de las acciones depende solamente de la información conocida)

• Briefly comment on the following components:

  1. Do the time series data show a trend? Yes, the stock price does show a tend. The trend component obtained from the decomposition of the time series data indicates a consistent downward trend over the analyzed period. This suggests that the stock price has been decreasing over time.

  2. Do the time series data show seasonality? How is the change of the seasonal component over time? Regarding seasonality, the analysis does not explicitly mention the presence of seasonality in the time series data. However, to determine if there is seasonality, we would need to further investigate the seasonal component obtained from the decomposition. If the seasonal component exhibits recurring patterns or cycles at regular intervals, it would indicate the presence of seasonality in the data. Unfortunately, the document does not provide specific information about the change of the seasonal component over time. Further analysis would be required to understand the behavior of the seasonal component in more detail.

Estimation

• Detect if the time series data is stationary.

# Stationary Test
adf.test(CSIQ$Adj.Close)   ### H0: Non-stationary and HA: Stationary. p-values < 0.05 reject the H0. 
## 
##  Augmented Dickey-Fuller Test
## 
## data:  CSIQ$Adj.Close
## Dickey-Fuller = -2.5048, Lag order = 7, p-value = 0.3642
## alternative hypothesis: stationary
                         ### P-Value > 0.05. Fails to Reject the H0. Time series data is non-stationary.

The p-value is > 0.05, so we fail to reject the H0. The time series data is non-stationary.

• Detect if the time series data shows serial autocorrelation.

acf(CSIQ$Adj.Close,main="Significant Autocorrelations") 

• Estimate 3 different time series regression models. You might want to consider ARMA (p,q) and / or ARIMA (p,d,q).

# esta en primer orden + t-1
summary(CSIQ_ARMA<-arma(log(CSIQ$Adj.Close),order=c(1,1))) #transforma en estacionaria
## 
## Call:
## arma(x = log(CSIQ$Adj.Close), order = c(1, 1))
## 
## Model:
## ARMA(1,1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.350680 -0.040645  0.002824  0.041949  0.227205 
## 
## Coefficient(s):
##            Estimate  Std. Error  t value Pr(>|t|)    
## ar1        0.982798    0.009389   104.67   <2e-16 ***
## ma1        0.013266    0.049155     0.27   0.7873    
## intercept  0.054055    0.029372     1.84   0.0657 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Fit:
## sigma^2 estimated as 0.005732,  Conditional Sum-of-Squares = 2.38,  AIC = -963.03
plot(CSIQ_ARMA)

# Omit NA
CSIQ_ARMA$residuals
##   [1]            NA -0.0730924890 -0.0986099777  0.0531124288  0.2269941260
##   [6]  0.1155831388  0.0060477640  0.0269764770  0.1281306397 -0.0419995339
##  [11]  0.0916834856 -0.0057053346 -0.0103371225  0.0256850590  0.0146096927
##  [16]  0.0500990309  0.0043411878  0.0305567329  0.0537922654 -0.1337277467
##  [21] -0.0234112442  0.0214176554 -0.0056347074 -0.0083900500 -0.0767078717
##  [26] -0.0769600123 -0.0550924402  0.0301019527 -0.0482519315  0.0639395133
##  [31] -0.0680620072 -0.0101989820 -0.3506795219  0.0787152268 -0.0320614815
##  [36]  0.0307317852  0.0024606092 -0.1170291573  0.0935481187  0.1131054889
##  [41]  0.0240063496 -0.0495827126  0.0528286813  0.0749724876 -0.1014899168
##  [46] -0.0195118739  0.0722598333  0.0877763257 -0.0475753344  0.1439829170
##  [51]  0.0809593482 -0.0097053917 -0.2049408077 -0.2207050720  0.0597372958
##  [56]  0.0071169014 -0.0393346467 -0.1731505774  0.1843504303  0.1183381412
##  [61]  0.0049658355 -0.1276190971  0.0332113677 -0.0883659498  0.0060834542
##  [66] -0.0965795837  0.0359043543  0.0502678919 -0.0652182073 -0.1225959117
##  [71]  0.0567436774  0.0596322913  0.0308243605 -0.0708892488 -0.0705802460
##  [76] -0.0436067133 -0.0668652863  0.0218027775 -0.0226514758 -0.0389063416
##  [81] -0.0060943747 -0.0342874812  0.0177636543 -0.1291694304  0.0655479959
##  [86] -0.0666398566 -0.0081161428 -0.0172801857 -0.1053442645  0.0794113574
##  [91]  0.0474044807  0.0338294800  0.0349515077  0.0415108873 -0.0721019669
##  [96] -0.1891135692 -0.0515721497 -0.0177580435 -0.0218188646 -0.0566736924
## [101]  0.1316973187 -0.0341261208 -0.0238479519 -0.0227665792  0.0310553084
## [106] -0.0306276193 -0.0030670685 -0.0073269702 -0.0443567670  0.0146805998
## [111]  0.1134230580  0.0370192774 -0.0286715584 -0.0813575228  0.0116038431
## [116] -0.2180060438  0.0860364308  0.0208005606 -0.0074877145  0.0418712689
## [121] -0.0174574682 -0.0085570167 -0.0245540902 -0.0194275736  0.0101314174
## [126] -0.0435497578 -0.0229918767  0.0032458831  0.1990557255 -0.0004067636
## [131] -0.0293143382  0.0720078368 -0.0208090067  0.0059257634 -0.0098011359
## [136]  0.0234182169 -0.0391286544 -0.0774830139  0.0340041596  0.0056410166
## [141]  0.0516897166 -0.0537703793  0.0176639094 -0.0242950110 -0.0219468420
## [146] -0.0256688520  0.0535797205  0.0987186158 -0.0595937453 -0.0037460603
## [151]  0.0111296278 -0.0099650790 -0.0451227470  0.0018883538 -0.0200728613
## [156] -0.0190852620  0.0036503422 -0.0327716562 -0.0517208281  0.0098077332
## [161] -0.0471294199 -0.0407087593  0.0478222499 -0.0246016771  0.0182883783
## [166]  0.0144588448 -0.0505487572  0.0914660092 -0.0550358496 -0.0139849874
## [171] -0.0017056520 -0.0254458505 -0.0055128333 -0.0435555100  0.0767209247
## [176]  0.0281284543 -0.0384718412 -0.0663213455 -0.2459951558 -0.0396803810
## [181]  0.0333420579 -0.0312824514  0.0310520779  0.0156318243 -0.0347389889
## [186]  0.0210536578  0.0301786921  0.0305996138 -0.0942077924  0.0470937139
## [191]  0.0259841005  0.0114279674 -0.0100786557 -0.0009620772 -0.0228408777
## [196] -0.0279539192 -0.0038174212  0.0429445972 -0.1524510961  0.1081618843
## [201] -0.0322329250  0.1065276246  0.0260233090  0.0148028975 -0.0436065411
## [206]  0.0181932014 -0.1572603302  0.0035461328  0.1159154624  0.0683464636
## [211]  0.0151654553  0.0743827845  0.0087967671  0.0373273101 -0.0039935564
## [216]  0.1669137427  0.0258042648 -0.0789756868  0.0104728467 -0.2168719146
## [221] -0.0071761887  0.0327199229 -0.0297721225  0.0068715469  0.0606900190
## [226]  0.0534859758 -0.1170175856 -0.0897068706  0.0026430428  0.0753931142
## [231]  0.1061574296  0.0106794679  0.0197308452 -0.0120239552  0.0213412236
## [236] -0.0709670517  0.0053296965 -0.0274392422  0.0640756891  0.0008586894
## [241]  0.0666459932 -0.0288960653  0.0282526613 -0.0292666895 -0.0640097590
## [246]  0.0385306285 -0.1327398903 -0.0406236554 -0.0015533104 -0.0362424163
## [251] -0.0176498546 -0.0257411831 -0.0382412835 -0.1275144944 -0.0078456099
## [256]  0.0840663527  0.1082978683  0.0960436336  0.0369947444  0.0277599172
## [261] -0.0009573231  0.0327978908 -0.0071208682 -0.0616532777 -0.0508953848
## [266]  0.0549107619  0.0921350733 -0.0144851611 -0.1203125199 -0.0050072339
## [271] -0.1919258239 -0.1358268221  0.0320122202 -0.0327611295  0.1176167145
## [276]  0.0175769058 -0.0310126683  0.0114220160  0.0731873379 -0.0885776231
## [281]  0.0611790841  0.0274789203  0.0186635013 -0.0840948631  0.0138542002
## [286]  0.0185312970  0.0774454095  0.1514903657 -0.0005499519 -0.0288048646
## [291] -0.0275352026  0.1338002997  0.0220221713  0.0043258800  0.2272054139
## [296] -0.0678816938 -0.0585304205  0.0341098199  0.0980225190  0.1137510269
## [301]  0.1538753772 -0.0837415409  0.0709066450 -0.0962738231  0.1009605455
## [306] -0.0179319239 -0.0012263963  0.1479360366 -0.0768588033 -0.0551256933
## [311]  0.1800647683  0.1667445755 -0.0163489898  0.1039583717 -0.0756635458
## [316]  0.2207038350 -0.1260698756  0.0720678019  0.0585766256 -0.1202819298
## [321] -0.1017090799 -0.1318828325  0.1363294698 -0.0020444647  0.0421828547
## [326]  0.0465894482 -0.0999007502  0.0290364757  0.0472037200 -0.0926976572
## [331] -0.0286662345 -0.0693703237  0.0730510854  0.0214997666 -0.0101964022
## [336]  0.0454393569 -0.0131807071  0.0353718093  0.0726026955 -0.0444176385
## [341] -0.0705246165  0.0452976927  0.0394092434  0.0030049334 -0.0270296994
## [346] -0.1666729635  0.1389835015  0.0123805495 -0.0127350374  0.0245663754
## [351] -0.0842953961  0.0281280862 -0.0347779413  0.1122019435  0.0282612427
## [356]  0.1099486265 -0.0707643622  0.0350962984  0.0462994035 -0.0565521048
## [361] -0.1536769354  0.0063399139 -0.0132359027 -0.0181591682  0.0110875960
## [366] -0.0444319156 -0.0478283217 -0.1109903867  0.0052919643  0.0561446066
## [371]  0.0363287302  0.0304050815  0.0532593378  0.0372650656  0.0763277656
## [376]  0.0614495534  0.0269242630  0.0074197544 -0.0536044165  0.0015101483
## [381] -0.1201013329 -0.0647196458  0.0253948512 -0.1413576708  0.1912645120
## [386]  0.0645254559  0.0602413747 -0.0178834662 -0.0483432579  0.0610123718
## [391] -0.0347338842  0.0635943388 -0.1182084581  0.1050377342  0.1402504448
## [396]  0.0532719156  0.0883346171  0.0116494030  0.0687945164  0.0065185954
## [401] -0.0200216623 -0.0583729680 -0.0755534698  0.0200555386 -0.0836756503
## [406] -0.1105139797  0.0096685190  0.0565694036  0.0584295822  0.0769783100
## [411]  0.0074822079 -0.0051954638  0.0299423183 -0.0850397332  0.0305239496
## [416] -0.0887022968 -0.0129988779
CSIQ_ARMA$residuals <- na.omit(CSIQ_ARMA$residuals)
CSIQ_estimated_stock_price<-exp(CSIQ_ARMA$fitted.values) # se vuelven a transformar las variables a los originales(si aplica log se tiene que aplicar el exponencial(es lo contrario))
plot(CSIQ_estimated_stock_price)

CSIQ_estimated_stock_price<-exp(CSIQ_ARMA$fitted.values)

Model Evaluation:

# Ho: There is no serial autocorrelation 
# H1: There is serial autocorrelation
CSIQ_ARMA_residuals<-CSIQ_ARMA$residuals
Box.test(CSIQ_ARMA_residuals,lag=5,type="Ljung-Box") # Reject the Ho. P-value is < 0.05 indicating that ARMA Model does show residual serial autocorrelation. 
## 
##  Box-Ljung test
## 
## data:  CSIQ_ARMA_residuals
## X-squared = 1.7594, df = 5, p-value = 0.8813
adf.test(CSIQ_ARMA$residuals)
## Warning in adf.test(CSIQ_ARMA$residuals): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  CSIQ_ARMA$residuals
## Dickey-Fuller = -7.777, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
# Forecast (ARMA)
CSIQ_ARMA_forecast<-forecast(CSIQ_estimated_stock_price,h=5)
## Warning in ets(object, lambda = lambda, biasadj = biasadj,
## allow.multiplicative.trend = allow.multiplicative.trend, : Missing values
## encountered. Using longest contiguous portion of time series
CSIQ_ARMA_forecast
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 418       30.92413 27.93365 33.91460 26.35059 35.49766
## 419       30.92413 26.75531 35.09294 24.54847 37.29978
## 420       30.92413 25.83884 36.00941 23.14685 38.70140
## 421       30.92413 25.06012 36.78813 21.95590 39.89235
## 422       30.92413 24.36985 37.47840 20.90023 40.94802
plot(CSIQ_ARMA_forecast)

autoplot(CSIQ_ARMA_forecast)

# Forecast (ARIMA)

CSIQ_ARIMA <- Arima(CSIQ$Adj.Close,order=c(1,1,1))
print(CSIQ_ARIMA)
## Series: CSIQ$Adj.Close 
## ARIMA(1,1,1) 
## 
## Coefficients:
##           ar1     ma1
##       -0.4675  0.3883
## s.e.   0.2547  0.2628
## 
## sigma^2 = 4.528:  log likelihood = -903.43
## AIC=1812.86   AICc=1812.92   BIC=1824.95
plot(CSIQ_ARIMA$residuals,main="ARIMA(1,1,1) - CSIQ Stock Price")

acf(CSIQ_ARIMA$residuals,main="ACF - ARIMA (1,1,1)")                # ACF plot displays weak or no autocorrelation. 

Box.test(CSIQ_ARIMA$residuals,lag=1,type="Ljung-Box")               # P-value is > 0.05 indicating that ARMA model does not show residual serial autocorrelation. 
## 
##  Box-Ljung test
## 
## data:  CSIQ_ARIMA$residuals
## X-squared = 0.039597, df = 1, p-value = 0.8423
adf.test(CSIQ_ARIMA$residuals)                                      # ADF test suggest that ARMA residuals are stationary since p-value is < 0.05.
## Warning in adf.test(CSIQ_ARIMA$residuals): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  CSIQ_ARIMA$residuals
## Dickey-Fuller = -7.6988, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
# Plotting log-transformation and differences
plot(CSIQ$Date,CSIQ$Adj.Close, type="l",col="blue", lwd=2, xlab ="Date",ylab ="Stock Price", main = "CSIQ Stock Price") # serie original

plot(CSIQ$Date,log(CSIQ$Adj.Close), type="l",col="blue", lwd=2, xlab ="Date",ylab ="log(Stock Price)", main = "CSIQ Stock Price") # variable con log, mismo comportamiento

plot(diff(log(CSIQ$Adj.Close)),type="l",ylab="first order difference",main = "Diff - CSIQ Stock Price") # cambia el comportamiento, ahora es estacionaria!! y se puede aplicar modelo ARIMA para pronóstico (no es el precio real de la acción)

adf.test(log(CSIQ$Adj.Close))
## 
##  Augmented Dickey-Fuller Test
## 
## data:  log(CSIQ$Adj.Close)
## Dickey-Fuller = -2.4346, Lag order = 7, p-value = 0.3938
## alternative hypothesis: stationary
adf.test(diff(log(CSIQ$Adj.Close)))
## Warning in adf.test(diff(log(CSIQ$Adj.Close))): p-value smaller than printed
## p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff(log(CSIQ$Adj.Close))
## Dickey-Fuller = -7.8178, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
Describe meaningful information from data analytics

Searching the Internet…

Based on the provided data analytics results, we can draw some meaningful conclusions:

  1. Stationarity: The Augmented Dickey-Fuller (ADF) test was performed on the log-transformed data of the Canadian Solar Inc. stock prices (CSIQ\(Adj.Close). The test results indicate that the differenced log-transformed data (diff(log(CSIQ\)Adj.Close))) is stationary, as the p-value is less than 0.05. This suggests that the data has a stable mean and variance over time, which is an important assumption for time series analysis.

  2. Model Selection: Three different regression models were estimated, including ARMA(1,1), ARIMA, and SARIMA models. The residuals of the ARMA(1,1) model (CSIQ_ARMA\(residuals) and the ARIMA model (CSIQ_ARIMA\)residuals) were also tested for stationarity using the ADF test. Both models’ residuals were found to be stationary, indicating that they capture the underlying patterns in the data effectively.

  3. Forecasting: The ARMA(1,1) model was used to make forecasts for the next five periods. The forecasted values indicate the estimated stock prices for the upcoming time intervals. These forecasts can provide valuable insights for decision-making and planning purposes.

  4. Log-Transformation: The log-transformed data (log(CSIQ\(Adj.Close)) was also tested for stationarity using the ADF test. The test results show that the log-transformed data is not stationary, as the p-value is greater than 0.05. However, after differencing the log-transformed data (diff(log(CSIQ\)Adj.Close))), the resulting series was found to be stationary.

In summary, the data analytics results suggest that the ARMA(1,1) model with stationary residuals is a suitable choice for forecasting the Canadian Solar Inc. stock prices. The differenced log-transformed data provides a stationary series, indicating that it captures the underlying patterns in the data effectively. These findings can help in understanding the historical performance of the stock and making informed decisions for the future.