<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def by_period(self, field=None, period=None, timezone=None, start=None, end=None):
 """ Create a date histogram aggregation using the last added aggregation for the current object. Add this date_histogram aggregation into self.aggregations :param field: the index field to create the histogram from :param period: the interval which elasticsearch supports, ex: "month", "week" and such :param timezone: custom timezone :param start: custom start date for the date histogram, default: start date under range :param end: custom end date for the date histogram, default: end date under range :returns: self, which allows the method to be chainable with the other methods """


        hist_period = period if period else self.interval_
        time_zone = timezone if timezone else "UTC"

        start_ = start if start else self.start_date
        end_ = end if end else self.end_date
        bounds = self.get_bounds(start_, end_)

        date_field = field if field else "grimoire_creation_date"
        agg_key = "date_histogram_" + date_field
        if agg_key in self.aggregations.keys():
            agg = self.aggregations[agg_key]
        else:
            agg = A("date_histogram", field=date_field, interval=hist_period,
                    time_zone=time_zone, min_doc_count=0, **bounds)

        child_agg_counter = self.child_agg_counter_dict[agg_key]
        child_name, child_agg = self.aggregations.popitem()

        agg.metric(child_agg_counter, child_agg)
        self.aggregations[agg_key] = agg
        self.child_agg_counter_dict[agg_key] += 1
        return self