{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Estimate an ARMA process"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example we are going to estimate a scalar ARMA process using the Whittle estimator."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot\n",
    "import matplotlib.pyplot as plt\n",
    "ot.RandomGenerator.SetSeed(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Create an arma process\n",
    "myTimeGrid = ot.RegularGrid(0.0, 0.1, 30)\n",
    "myWhiteNoise = ot.WhiteNoise(ot.Triangular(-1.0, 0.0, 1.0), myTimeGrid)\n",
    "myARCoef = ot.ARMACoefficients([0.4, 0.3, 0.2, 0.1])\n",
    "myMACoef = ot.ARMACoefficients([0.4, 0.3])\n",
    "myARMAProcess = ot.ARMA(myARCoef, myMACoef, myWhiteNoise)\n",
    "myTimeSeries = myARMAProcess.getRealization()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create the estimator\n",
    "myFactory_42 = ot.WhittleFactory(4, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41.22386791008901 25.223867910089016 49.13657072551996\n"
     ]
    }
   ],
   "source": [
    "# Estimate the ARMA process\n",
    "myARMA_42, myCriterion = myFactory_42.buildWithCriteria(ot.TimeSeries(myTimeSeries))\n",
    "AICc, AIC, BIC = myCriterion[0:3]\n",
    "print(AICc, AIC, BIC)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
