Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Autoregressive Model with Moving Average(ARMA) | Time Series Forecasting
/
Introduction to Finance with Python
セクション 3.  3
single

single

bookChallenge: Autoregressive Model with Moving Average(ARMA)

メニューを表示するにはスワイプしてください

What is a Moving Average?

Before discovering model, which this chapter is devoted to, it will be better to define basic concept, called Moving Average.

This model is denoted as MA(q), where q - is model's parameter, which, analogically to AR model called it's order, and corresponds to number of previous steps, from which errors are taken.

For example, here is an expression for MA(3) model:

Here ε_k - is an error on time step k, which could be computed in the next way:

Here y_k - is real value of time series at time step k, while y_k_hat - corresponding value, predicted by model.

We should mention, that practically - MA models are really used, but their combination with another models - is way more effective and popular thing.

What is an ARMA?

As well as before, autoregressive component (AR), uses previous values of time series for predicting future values.

Meanwhile, moving average component (MA) measures dependencies between future values and errors on previous values.

Defining model

In case of ARMA, model already has two parameters: as before - we use order of autoregression p, but now - we are also using order of moving average q, which is a number of previous steps, from which errors will be taken.

We will denote it like ARMA(p,q).

For example, model ARMA(2,3) can be represented, using the next expression:

Here, y_t - value of time series on time step t, ε_t - random error on step t, c - bias coefficient.

Code implementation

To implement and train ARMA model in Python we can use the following code:

# Importing necessary package
import statsmodels.api as sm
# Creating and training ARMA (4,3) model called `model` on a Series with time series values called `data`
model = sm.tsa.arima.ARIMA(data, order = (4, 0, 3))
res = model.fit()

To make future predictions, we can use just the same code, we used into previous chapter for AR model:

# Making forecast on the next 7 time steps
forecast = res.forecast(steps = 7)
タスク

スワイプしてコーディングを開始

In this task you need to:

  1. Train ARMA(5,2) model on a prepared dataset data of Microsoft's stock prices.

Note: You need to pass data as the first argument, without specifying name of corresponding parameter, in order to complete this chapter.

  1. Make forecast on the next 14 steps, using the trained model.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  3
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt