import numpy as np
import scipy as sp
import pandas as pd
import pandas.io.data as web
import matplotlib.pyplot as plt
import scipy.optimize as opt
from pandas.io.pytables import HDFStore
from datetime import datetime

def optimize(self, opts={}):
    niter = opts.get("niter", 5)
    x0 = self.portfolio.weights.tolist()           
    res = opt.basinhopping(self.utilityFunction, x0,  niter=niter, disp=True)

    print res          

    #call utility function to set resulting weights
    self.utilityFunction(res.x)
    