expanded_str = [date.strftime(c.DATE_FORMAT) for date in expanded_dates]
here raises an error, if expanded_dates is None, which happens if start_date and end_date are respectively min and max dates of the new_data.
This leads to inability to run optimization with new_data, unless start_date or end_date is not actual start or end dates of new_data - which seems counterintuitive.