Exemple #1
0
def getegarchreturn(start, startfromenum, end, endfromenum, datefunc,
                    returnfunc):
    if startfromenum == True and endfromenum == True:
        startdate = start.value
        enddate = end.value
    elif startfromenum == True and endfromenum == False:
        startdate = start.value
        enddate = pandas.to_datetime(end)
    elif startfromenum == False and endfromenum == True:
        startdate = pandas.to_datetime(start)
        enddate = end.value
    elif startfromenum == False and endfromenum == False:
        startdate = pandas.to_datetime(start)
        enddate = pandas.to_datetime(end)
    else:
        print("invalid booleans")
    date = datefunc.tolist()
    startindex = date.index(startdate)
    endindex = date.index(enddate)
    archrange = returnfunc[startindex:endindex]
    am = arch.arch_model(archrange)
    am.volatility = arch.EGARCH(p=2, o=1, q=1)
    amres = am.fit(update_freq=0)
    print(amres)
    return amres.params
Exemple #2
0
 def egarchmodel(self):
     ae = self.am
     ae.volatility = arch.EGARCH(p=2, o=1, q=1)
     self.aeres = ae.fit(update_freq=0)
     print(self.aeres.summary())
     egarchFig = plt.figure()
     self.eresiduals = self.aeres.resid / self.aeres.conditional_volatility
     ergraph = egarchFig.add_subplot(212)
     ergraph.plot(self.modelDate, self.eresiduals)
     self.evolatility = self.aeres._volatility
     evgraph = egarchFig.add_subplot(211)
     evgraph.plot(self.modelDate, self.evolatility)
     plt.draw()
     plt.show()
    def linesmodel(self):
        ae = self.am
        ae.volatility = arch.EGARCH(p=2, o=1, q=1)
        self.aeres = ae.fit(update_freq=0)
        print(self.aeres.summary())
        egarchFig = plt.figure()
        self.eresiduals = self.aeres.resid / self.aeres.conditional_volatility
        ergraph = egarchFig.add_subplot(212)
        ergraph.plot(self.modelDate, self.eresiduals)
        self.evolatility = self.aeres._volatility
        evgraph = egarchFig.add_subplot(211)
        evgraph.plot(self.modelDate, self.evolatility)
        ergraph.set_title('EGARCH Standardized Residuals')
        evgraph.set_title('EGARCH Conditional Volatility')

        for xc in self.xposition:
            evgraph.axvline(x=xc, color='k', linestyle='-')
            ergraph.axvline(x=xc, color='k', linestyle='-')

        plt.draw()
        plt.show()