'fit Pareto with nested optimization
originally published on stackoverflow
this doesn\'t trim lower values during ks optimization'

def fit_ks(self):

    rvs = self.endog
    rvsmin = rvs.min()
    fixdf = (np.nan * np.ones(3))
    self.fixed_params = fixdf
    self.fixed_paramsmask = np.isnan(fixdf)
    def pareto_ks(loc, rvs):
        self.fixed_params[1] = loc
        est = self.fit(start_params=self.start_params[self.fixed_paramsmask]).params
        args = (est[0], loc, est[1])
        return stats.kstest(rvs, 'pareto', args)[0]
    locest = optimize.fmin(pareto_ks, (rvsmin - 1.5), (rvs,))
    est = stats.pareto.fit_fr(rvs, 0.0, frozen=[np.nan, locest, np.nan])
    args = (est[0], locest[0], est[1])
    return args
