def evaluate(self, context, symbol, start=None, end=None): df_split = context.dependencies(source_reference) df_normalization = pandas.DataFrame(index=dateutils.range(start, end)) for column in ['open', 'high', 'low', 'close']: df_normalization[column] = 1 for i in range(len(df_split)): row = df_split.ix[i] day = dateutils.relative_working_day(-1, row.name) df_normalization.update(df_normalization[:day] * row['factor']) df_normalization['volume'] = 1 / df_normalization['close'] return df_normalization
def test_return_should_be_instance_of_date(self): assert isinstance(util.relative_working_day(0), date)
def test_should_consider_last_working_day_if_weekend_date_was_given2(self): assert util.relative_working_day(2, date(2012, 12, 15)) == date(2012, 12, 18)
def test_should_return_friday_date_if_weekend_and_0_as_arg(self): d = date(2012, 12, 16) assert util.relative_working_day(0, d) == util.last_working_day(d)
def test_should_use_today_if_no_argument_is_given(self): assert util.relative_working_day(0) == util.last_working_day( date.today())
def test_should_return_date_1_working_day_ago(self): dt_today = date.today() assert util.relative_working_day(-1) == util.last_working_day( util.last_working_day(dt_today) - timedelta(1))
def test_should_return_positive_relative_day(self): assert util.relative_working_day(20, date(2012, 12, 17)) == date(2013, 1, 14)
def test_should_return_negative_relative_day(self): assert util.relative_working_day(-20, date(2012, 12, 17)) == date(2012, 11, 19)