title: Outier detection using tsoutlier in R
body: <p>I am trying to predict the weekly stock price of Nifty using ARIMA model. Data can be downloaded <a href="https://docs.google.com/spreadsheets/d/163gLVLlM9Z-Aom0qMQWmbhxD8Sc46XDYf05dGMKXRFc/edit?usp=sharing" rel="nofollow">here</a>. I tried the following three cases: </p>
  
  <p><strong>First Case:</strong> I used <code>tso</code> function from <a href="http://cran.r-project.org/web/packages/tsoutliers/tsoutliers.pdf" rel="nofollow">tsoutliers</a> package to identify outliers (if any) and to fit ARIMA model. I got the results as ARIMA(1,1,1) with no outliers detected. Minimal code: </p>
  
  <p><code>outliers1 &lt;- tso(close, tsmethod = c("auto.arima"), args.tsmethod = list(allowdrift=TRUE))</code></p>
  
  <p>Results Obtained: </p>
  
  <pre><code>ARIMA(1,1,1)                    
  
  Coefficients:
           ar1      ma1
        0.6112  -0.5684
  s.e.  0.3496   0.3632
  
  sigma^2 estimated as 25268:  log likelihood=-2523.68
  AIC=5053.35   AICc=5053.41   BIC=5065.24
  
  No outliers were detected.
  </code></pre>
  
  <p><strong>Second Case:</strong> Since there were no outliers detected, I used <code>auto.arima()</code> from forecast package to see what model I get. As suggested in previous posts, I made stepwise and approximation to FALSE. I obtained ARIMA (3,1,2) model. Minimal code: </p>
  
  <pre><code>close &lt;- read.ts("close.csv", header = FALSE")
  fit &lt;- auto.arima(close, stepwise = FALSE, trace = TRUE, approximation = FALSE)
  </code></pre>
  
  <p>Results Obtained: </p>
  
  <pre><code>Series: close 
  ARIMA(3,1,2) with drift         
  
  Coefficients:
            ar1      ar2     ar3     ma1     ma2    drift
        -1.7302  -0.7838  0.0624  1.7730  0.9097  10.4769
  s.e.   0.0695   0.1125  0.0578  0.0483  0.0475   8.4509
  
  sigma^2 estimated as 24413:  log likelihood=-2510.18
  AIC=5034.37   AICc=5034.66   BIC=5062.11
  </code></pre>
  
  <p><strong>Third Case:</strong> In my third case, I tried using ARIMA(3,1,2) obtained in second case in tso to check for any outliers. But the model detected no outliers. Minimal code: </p>
  
  <pre><code>outlier2 &lt;- tso(close, maxit = 10, tsmethod = c("arima"), args.tsmethod = list(order =c(3,1,2)))
  </code></pre>
  
  <p>Results obtained:  </p>
  
  <pre><code>    Coefficients:
            ar1     ar2      ar3     ma1      ma2
        -0.2224  0.3573  -0.0186  0.2451  -0.2548
  s.e.   0.7914  0.4344   0.1107  0.7884   0.4603
  sigma^2 estimated as 24986:  log likelihood = -2521.51,  aic = 5055.02
  No outliers were detected.
  </code></pre>
  
  <p>My question is if there aren't any outliers in the data then why are the results different in cases 1 and 2. Is there something I am missing out in the model building? In addition, the forecasts obtained using both ARIMA (3,1,2) and (1,1,1) are poor. </p>