from typing import Dict
from typing import Union


def initialize_period_dict(periods):
    """
    Initialize the period dict with all the distinct periods as key, and
    the needed keys to calculate the loss function.
    """
    period_dict: Dict[Union[str, int], Dict[str, float]] = {}
    for period in periods:
        period_dict[period] = {}
        period_dict[period]["count"] = 0
        period_dict[period]["sum"] = 0
        period_dict[period]["squared_sum"] = 0

    return period_dict