'Handles the close of the given day, in both minute and daily emission.
In daily emission, also updates performance, benchmark and risk metrics
as it would in handle_minute_close if it were minute emission.
Parameters
dt : Timestamp
The minute that is ending
Returns
A daily perf packet.'

def handle_market_close(self, dt, data_portal):

    completed_session = self._current_session
    if (self.emission_rate == 'daily'):
        self.position_tracker.sync_last_sale_prices(dt, False, data_portal)
        self.update_performance()
        account = self.get_account(False)
        benchmark_value = self.all_benchmark_returns[completed_session]
        self.cumulative_risk_metrics.update(completed_session, self.todays_performance.returns, benchmark_value, account.leverage)
    self.session_count += 1.0
    try:
        next_session = self.trading_calendar.next_session_label(completed_session)
    except NoFurtherDataError:
        next_session = None
    daily_update = self.to_dict(emission_type='daily')
    if (self.market_close >= self.last_close):
        return daily_update
    if ((next_session is None) or (next_session >= self.last_close)):
        return daily_update
    self._current_session = next_session
    (self.market_open, self.market_close) = self.trading_calendar.open_and_close_for_session(self._current_session)
    self.todays_performance.rollover()
    self.todays_performance.period_open = self.market_open
    self.todays_performance.period_close = self.market_close
    self.check_upcoming_dividends(next_session=next_session, adjustment_reader=data_portal._adjustment_reader)
    return daily_update
