|
438 | 438 | <div class="content">
|
439 | 439 | <div class="container p-0 read-area">
|
440 | 440 |
|
441 |
| - <div class="hero-area col-sm-12" id="hero-area" style='background-image: url(/images/default-hero.jpg);'> |
| 441 | + <div class="hero-area col-sm-12" id="hero-area" style='background-image: url(/posts/finance/stock_prediction/arima/images/find_d.png);'> |
442 | 442 | </div>
|
443 | 443 |
|
444 | 444 |
|
|
447 | 447 | <div class="author-profile ms-auto align-self-lg-center">
|
448 | 448 | <img class="rounded-circle" src='/images/author/profile_hu8a567cefac8c1a165d433ac0796ac418_3088978_120x120_fit_q75_box.jpg' alt="Author Image">
|
449 | 449 | <h5 class="author-name">Stefano Giannini</h5>
|
450 |
| - <p class="text-muted">Friday, June 28, 2024 | 5 minutes</p> |
| 450 | + <p class="text-muted">Friday, June 28, 2024 | 6 minutes</p> |
451 | 451 | </div>
|
452 | 452 |
|
453 | 453 |
|
@@ -541,6 +541,7 @@ <h2 id="4-implementing-arima-models-in-python">4. Implementing ARIMA Models in P
|
541 | 541 | </span></span><span style="display:flex;"><span> print(<span style="color:#e6db74">'ADF Statistic:'</span>, result[<span style="color:#ae81ff">0</span>])
|
542 | 542 | </span></span><span style="display:flex;"><span> print(<span style="color:#e6db74">'p-value:'</span>, result[<span style="color:#ae81ff">1</span>])
|
543 | 543 | </span></span><span style="display:flex;"><span>
|
| 544 | +</span></span><span style="display:flex;"><span><span style="color:#75715e"># if p-value is > 0.05, it means the series is not stationary.</span> |
544 | 545 | </span></span><span style="display:flex;"><span>test_stationarity(ts)
|
545 | 546 | </span></span><span style="display:flex;"><span>
|
546 | 547 | </span></span><span style="display:flex;"><span><span style="color:#75715e"># If non-stationary, difference the series</span>
|
@@ -578,6 +579,30 @@ <h2 id="5-model-selection-and-diagnostic-checking">5. Model Selection and Diagno
|
578 | 579 | <li><strong>Grid search</strong>: Trying different combinations of p, d, and q and selecting the best based on information criteria like AIC or BIC.</li>
|
579 | 580 | <li><strong>Diagnostic checking</strong>: Analyzing residuals to ensure they resemble white noise.</li>
|
580 | 581 | </ol>
|
| 582 | +<h3 id="finding-arima-parameters-p-d-q">Finding ARIMA Parameters (p, d, q)</h3> |
| 583 | +<p>Determining the optimal ARIMA parameters involves a combination of statistical tests, visual inspection, and iterative processes. Here’s a systematic approach to finding p, d, and q:</p> |
| 584 | +<ul> |
| 585 | +<li>Determine d (Differencing Order): |
| 586 | +<ul> |
| 587 | +<li>Use the Augmented Dickey-Fuller test to check for stationarity.</li> |
| 588 | +<li>If the series is not stationary, difference it and test again until stationarity is achieved.</li> |
| 589 | +</ul> |
| 590 | +</li> |
| 591 | +<li>Determine p (AR Order) and q (MA Order): |
| 592 | +<ul> |
| 593 | +<li>After differencing, use ACF (Autocorrelation Function) and PACF (Partial Autocorrelation Function) plots.</li> |
| 594 | +<li>The lag where the ACF cuts off indicates the q value.</li> |
| 595 | +<li>The lag where the PACF cuts off indicates the p value.</li> |
| 596 | +</ul> |
| 597 | +</li> |
| 598 | +<li>Fine-tune with Information Criteria: |
| 599 | +<ul> |
| 600 | +<li>Use AIC (Akaike Information Criterion) or BIC (Bayesian Information Criterion) to compare different models.</li> |
| 601 | +</ul> |
| 602 | +</li> |
| 603 | +</ul> |
| 604 | +<h3 id="finding-d-values-from-plots">Finding d values from plots</h3> |
| 605 | +<h3 id="grid-search">Grid Search</h3> |
581 | 606 | <p>Here’s a Python function to perform a grid search:</p>
|
582 | 607 | <div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">grid_search_arima</span>(ts, p_range, d_range, q_range):
|
583 | 608 | </span></span><span style="display:flex;"><span> best_aic <span style="color:#f92672">=</span> float(<span style="color:#e6db74">'inf'</span>)
|
@@ -788,7 +813,13 @@ <h5 class="text-center ps-3">Table of Contents</h5>
|
788 | 813 | </ul>
|
789 | 814 | </li>
|
790 | 815 | <li><a href="#4-implementing-arima-models-in-python">4. Implementing ARIMA Models in Python</a></li>
|
791 |
| - <li><a href="#5-model-selection-and-diagnostic-checking">5. Model Selection and Diagnostic Checking</a></li> |
| 816 | + <li><a href="#5-model-selection-and-diagnostic-checking">5. Model Selection and Diagnostic Checking</a> |
| 817 | + <ul> |
| 818 | + <li><a href="#finding-arima-parameters-p-d-q">Finding ARIMA Parameters (p, d, q)</a></li> |
| 819 | + <li><a href="#finding-d-values-from-plots">Finding d values from plots</a></li> |
| 820 | + <li><a href="#grid-search">Grid Search</a></li> |
| 821 | + </ul> |
| 822 | + </li> |
792 | 823 | <li><a href="#6-limitations-and-considerations">6. Limitations and Considerations</a></li>
|
793 | 824 | <li><a href="#7-advanced-topics-and-extensions">7. Advanced Topics and Extensions</a></li>
|
794 | 825 | <li><a href="#8-conclusion">8. Conclusion</a></li>
|
|
0 commit comments