Example #1
0
'''

from mle import simulate as sim
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import matplotlib.pyplot as plt
import numpy as np
from mle import likelihood as logL
import scipy.optimize as opt
import mle.constraint as cons

import datetime

np.random.seed(10)
phi = [0.1, 0.2, 0.1]

x = sim.arpGaussian(t=500, phi=phi)

# sigma = 1
x0 = tuple([0. for i in range(len(phi))])  # + [sigma])
bounds = [(-0.99, 0.99) for i in range(len(phi))]  # + [(0, None)]

# plot_acf(x, lags = 10)
# plot_pacf(x, lags = 10)

time1 = datetime.datetime.now()

# x0 = tuple([0. for i in range(len(phi))])
# bounds = [(-0.99, 0.99) for i in range(len(phi))]

# params = opt.minimize(logL.maxARpN, x0 = x0, \
#                         args = x, \
Example #2
0
@author: snake91
'''

import numpy as np
import scipy.linalg as slin
import scipy.optimize as opt
import scipy.stats as st
import pandas as pd
import matplotlib.pyplot as plt

from mle import simulate as sim
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
from statsmodels.tsa.stattools import acf, pacf

x = sim.arpGaussian(t=500, phi=[0.5, 0.2])
acfList = acf(x, nlags=20)


def empirical_acf(params, n):

    rhoList = [1.]

    p = len(params)

    for i in range(0, n):
        rho = 0.
        for p in range(len(params)):

            rho += params[p] * rhoList[i - p]
Example #3
0
'''
Created on Sep 8, 2019

@author: snake91
'''

import pymc3 as pm

import numpy as np
import matplotlib.pyplot as plt
import mle.simulate as sim

np.random.seed(1)
phi1 = 0.1

y = sim.arpGaussian(t=200, phi=[phi1])


def b0_bayesianmodel(y):
    with pm.Model(
    ) as model:  # model specifications in PyMC3 are wrapped in a with-statement
        # Define priors
        #     sigma = HalfCauchy('sigma', beta=10, testval=1.)
        sigma = 1
        intercept = pm.Uniform('phi1', -0.99, 0.99)
        x_coeff = phi1  #Normal('x', 0, sd=20)

        # Define likelihood
        likelihood = pm.Normal('y',
                               mu=np.hstack([[0], phi1 * y[1:]]),
                               sd=sigma,
Example #4
0
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as st
import prediction.confidence_interval as ci

window = 250
phi = [-0.6, -0.3]
sigma = 1
u = int(np.random.randint(1000))
# u = 15

np.random.seed(u)
x = np.random.normal(size=500)

np.random.seed(u)
y = sim.arpGaussian(t=500, phi=phi, y0=list(np.random.normal(size=len(phi))))

var_x = [np.percentile(x[i - window:i], q=0.99) for i in range(window, 500)]
var_y_iid = [
    np.percentile(y[i - window:i], q=0.99) for i in range(window, 500)
]

var_y_ar = ci.arpGaussian(y, phi=phi, window=250, q=0.99, sigma=1)[1]

# plt.plot(x[window:], label = 'iid')
plt.plot(y[window:], label='arp')
# plt.plot(var_x, label = 'var_iid_iid')
plt.plot(var_y_iid, label='var_arp_iid')
plt.plot(var_y_ar, label='var_arp_arp')
plt.legend()