'fit Pareto with nested optimization
originally published on stackoverflow'

def fit_ks1(self):

    rvs = self.endog
    rvsmin = rvs.min()
    def pareto_ks(loc, rvs):
        est = stats.pareto.fit_fr(rvs, 1.0, frozen=[np.nan, loc, np.nan])
        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, 1.0, frozen=[np.nan, locest, np.nan])
    args = (est[0], locest[0], est[1])
    return args
