'Run the algorithm.
:Arguments:
source : DataPortal
:Returns:
daily_stats : pandas.DataFrame
Daily performance metrics such as returns, alpha etc.'

def run(self, data=None, overwrite_sim_params=True):

    self._assets_from_source = []
    if isinstance(data, DataPortal):
        self.data_portal = data
        self._assets_from_source = self.trading_environment.asset_finder.retrieve_all(self.trading_environment.asset_finder.sids)
    else:
        if isinstance(data, pd.DataFrame):
            data = pd.Panel({'close': data.copy()})
            data = data.swapaxes(0, 2)
        if isinstance(data, pd.Panel):
            if (data.major_axis.tz is None):
                data.major_axis = data.major_axis.tz_localize('UTC')
            if overwrite_sim_params:
                self.sim_params = self.sim_params.create_new(self.trading_calendar.minute_to_session_label(data.major_axis[0]), self.trading_calendar.minute_to_session_label(data.major_axis[(-1)]))
                times = data.major_axis.time
                if np.all((times == times[0])):
                    self.sim_params.data_frequency = 'daily'
                else:
                    self.sim_params.data_frequency = 'minute'
            copy_panel = data.rename(minor_axis={'close_price': 'close', 'open_price': 'open'}, copy=True)
            copy_panel.items = self._write_and_map_id_index_to_sids(copy_panel.items, copy_panel.major_axis[0])
            self._assets_from_source = self.asset_finder.retrieve_all(copy_panel.items)
            if (self.sim_params.data_frequency == 'daily'):
                equity_reader_arg = 'equity_daily_reader'
            elif (self.sim_params.data_frequency == 'minute'):
                equity_reader_arg = 'equity_minute_reader'
            equity_reader = PanelBarReader(self.trading_calendar, copy_panel, self.sim_params.data_frequency)
            self.data_portal = DataPortal(self.asset_finder, self.trading_calendar, first_trading_day=equity_reader.first_trading_day, **{equity_reader_arg: equity_reader})
    self.perf_tracker = None
    try:
        perfs = []
        for perf in self.get_generator():
            perfs.append(perf)
        daily_stats = self._create_daily_stats(perfs)
        self.analyze(daily_stats)
    finally:
        self.data_portal = None
    return daily_stats
