Exemplo n.º 1
0
    def test_dayofweek_value_not_specified_default_returned(self):
        default_value = 0.5

        dayofweek_adjust = adjustments.dayofweek(default_value)

        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-13',
                                                    freq='D')))  # monday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-14',
                                                    freq='D')))  # tuesday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-15',
                                                    freq='D')))  # wednesday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-16',
                                                    freq='D')))  # thursday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-17',
                                                    freq='D')))  # friday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-18',
                                                    freq='D')))  # saturday
        self.assertEqual(default_value,
                         dayofweek_adjust(pd.Period('2019-05-19',
                                                    freq='D')))  # sunday
Exemplo n.º 2
0
def read_fwd_curve():
    fwd_periods = []
    fwd_prices = []
    fwd_row = 0
    while fwd_input_sheet[fwd_row, 0].value != '':
        fwd_periods.append(
            pd.Period(fwd_input_sheet[fwd_row, 0].value, freq=freq))
        fwd_prices.append(fwd_input_sheet[fwd_row, 1].value)
        fwd_row += 1
    if smooth_curve_wgt.value:
        p1, p2 = itertools.tee(fwd_periods)
        next(p2, None)
        contracts = []
        for start, end, price in zip(p1, p2, fwd_prices):
            contracts.append((start, end - 1, price))
        weekend_adjust = None
        if apply_wkend_shaping_wgt.value:
            wkend_factor = wkend_factor_wgt.value
            weekend_adjust = adjustments.dayofweek(default=1.0,
                                                   saturday=wkend_factor,
                                                   sunday=wkend_factor)
        return max_smooth_interp(contracts,
                                 freq=freq,
                                 mult_season_adjust=weekend_adjust)
    else:
        return pd.Series(
            fwd_prices,
            pd.PeriodIndex(fwd_periods)).resample(freq).fillna('pad')
Exemplo n.º 3
0
    def test_dayofweek_values_specified(self):
        dayofweek_adjust = adjustments.dayofweek(0.5,
                                                 monday=3.4,
                                                 tuesday=1.2,
                                                 wednesday=1.1,
                                                 thursday=0.9,
                                                 friday=0.7,
                                                 saturday=0.2,
                                                 sunday=0.1)

        self.assertEqual(3.4,
                         dayofweek_adjust(pd.Period('2019-05-13',
                                                    freq='D')))  # monday
        self.assertEqual(1.2,
                         dayofweek_adjust(pd.Period('2019-05-14',
                                                    freq='D')))  # tuesday
        self.assertEqual(1.1,
                         dayofweek_adjust(pd.Period('2019-05-15',
                                                    freq='D')))  # wednesday
        self.assertEqual(0.9,
                         dayofweek_adjust(pd.Period('2019-05-16',
                                                    freq='D')))  # thursday
        self.assertEqual(0.7,
                         dayofweek_adjust(pd.Period('2019-05-17',
                                                    freq='D')))  # friday
        self.assertEqual(0.2,
                         dayofweek_adjust(pd.Period('2019-05-18',
                                                    freq='D')))  # saturday
        self.assertEqual(0.1,
                         dayofweek_adjust(pd.Period('2019-05-19',
                                                    freq='D')))  # sunday