def summarize_all(self): if len(self.independent) == 1: dependent = self.dependent independent = self.independent[0] params = self.result.params result = self.result k = params[1] b = params[0] conf = result.conf_int() cadf = adfuller(result.resid) if cadf[0] <= cadf[4]['5%']: boolean = 'likely' else: boolean = 'unlikely' print print("{:^40}".format("{} vs {}".format(dependent.upper(), independent.upper()))) print("%20s %s = %.4f * %s + %.4f" % ("Model:", dependent, k, independent, b)) print("%20s %.4f" % ("R square:", result.rsquared)) print("%20s [%.4f, %.4f]" % ("Confidence interval:", conf.iloc[1, 0], conf.iloc[1, 1])) print("%20s %.4f" % ("Model error:", result.resid.std())) print("%20s %s" % ("Mean reverting:", boolean)) print("%20s %d" % ("Half life:", half_life(result.resid))) else: dependent = self.dependent independent = self.independent # list params = self.result.params result = self.result b = params[0] conf = result.conf_int() # pandas cadf = adfuller(result.resid) if cadf[0] <= cadf[4]['5%']: boolean = 'likely' else: boolean = 'unlikely' print print("{:^40}".format("{} vs {}".format( dependent.upper(), (', '.join(independent)).upper()))) string = [] for i in range(len(independent)): string.append("%.4f * %s" % (params[independent[i]], independent[i])) print("%20s %s = %s + %.4f" % ("Model:", dependent, ' + '.join(string), b)) print("%20s %.4f" % ("R square:", result.rsquared)) string = [] for i in range(len(independent)): string.append( "[%.4f, %.4f]" % (conf.loc[independent[i], 0], conf.loc[independent[i], 1])) print("%20s %s" % ("Confidence interval:", ' , '.join(string))) print("%20s %.4f" % ("Model error:", result.resid.std())) print("%20s %s" % ("Mean reverting:", boolean)) print("%20s %d" % ("Half life:", half_life(result.resid)))
def summarize_all(self): if len(self.independent) == 1: dependent = self.dependent independent = self.independent[0] params = self.result.params result = self.result k = params[1] b = params[0] conf = result.conf_int() cadf = adfuller(result.resid) if cadf[0] <= cadf[4]['5%']: boolean = 'likely' else: boolean = 'unlikely' print print ("{:^40}".format("{} vs {}".format(dependent.upper(), independent.upper()))) print ("%20s %s = %.4f * %s + %.4f" % ("Model:", dependent, k, independent, b)) print ("%20s %.4f" % ("R square:", result.rsquared)) print ("%20s [%.4f, %.4f]" % ("Confidence interval:", conf.iloc[1, 0], conf.iloc[1, 1])) print ("%20s %.4f" % ("Model error:", result.resid.std())) print ("%20s %s" % ("Mean reverting:", boolean)) print ("%20s %d" % ("Half life:", half_life(result.resid))) else: dependent = self.dependent independent = self.independent # list params = self.result.params result = self.result b = params[0] conf = result.conf_int() # pandas cadf = adfuller(result.resid) if cadf[0] <= cadf[4]['5%']: boolean = 'likely' else: boolean = 'unlikely' print print ("{:^40}".format("{} vs {}".format(dependent.upper(), (', '.join(independent)).upper()))) string = [] for i in range(len(independent)): string.append("%.4f * %s" % (params[independent[i]], independent[i])) print ("%20s %s = %s + %.4f" % ("Model:", dependent, ' + '.join(string), b)) print ("%20s %.4f" % ("R square:", result.rsquared)) string = [] for i in range(len(independent)): string.append("[%.4f, %.4f]" % (conf.loc[independent[i], 0], conf.loc[independent[i], 1])) print ("%20s %s" % ("Confidence interval:", ' , '.join(string))) print ("%20s %.4f" % ("Model error:", result.resid.std())) print ("%20s %s" % ("Mean reverting:", boolean)) print ("%20s %d" % ("Half life:", half_life(result.resid)))
def run_all(self): """ Lazy ass's ultimate solution. Run all available analysis Pre-condition: There should be only one independent variable """ _2D = len(self.independent) == 1 print self.plot_all() print print self.summary() if _2D: self.plot2D() print print 'Error statistics' print self.residual().describe() print self.residual_vs_fit() self.residual_plot() residual = self.residual() test_mean_reverting(residual) print print 'Halflife = ', half_life(residual)