Пример #1
0
def get_diffs(contract, diff_length, start=None, end=None):
    """
    Get the price differences for the diff_length
    for a given contract from the start to end date.
    The diff_length param should be an int representing
    the number of months.
    """
    collapse, diff_length = helpers.get_collapse(diff_length)
    start = helpers.convert_start_date(start, diff_length)
    data = _get_data(contract, start=start, end=end, collapse=collapse)
    diffs = pd.Series()
    for i in xrange(diff_length, len(data)):
        diffs[data.index[i]] = data[i] - data[i - diff_length]
    return diffs
Пример #2
0
def get_diffs(contract, diff_length, start=None, end=None):
    """
    Get the price differences for the diff_length
    for a given contract from the start to end date.
    The diff_length param should be an int representing
    the number of months.
    """
    collapse, diff_length = helpers.get_collapse(diff_length)
    start = helpers.convert_start_date(start, diff_length)
    data = _get_data(
        contract, start=start, end=end, collapse=collapse
    )
    diffs = pd.Series()
    for i in xrange(diff_length, len(data)):
        diffs[data.index[i]] = data[i] - data[i - diff_length]
    return diffs
Пример #3
0
def get_quarterly_diffs(contract, diff_length, start, end):
    collapse, diff_length = helpers.get_collapse(diff_length)
    start = helpers.convert_start_date(start, diff_length)
    start_c = '{}{}'.format(QUARTERS_REVERSE[start[5:]], start[:3])
    end_c = '{}{}'.format(QUARTERS_REVERSE[end[5:]], end[:3])
    starting_index = contracts.QUARTERLY.index(start_c)
    ending_index = contracts.QUARTERLY.index(end_c)
    all_data = pd.Series()
    for i in xrange(starting_index, ending_index + 1):
        current = contracts.QUARTERLY[i]
        # end_date = '{}-{}'.format(current[1:], QUARTERS[current[0]])
        # start_date = datetime.strptime(end_date, '%Y-%m-%d')
        # start_date = start_date - relativedelta(months=6)
        data = _get_data(
            contract + contracts.QUARTERLY[i],
            start=start, end=end, collapse=collapse
        )
        all_data[data.index[-1]] = data[-1] - data[0]
    return all_data
Пример #4
0
def get_quarterly_diffs(contract, diff_length, start, end):
    collapse, diff_length = helpers.get_collapse(diff_length)
    start = helpers.convert_start_date(start, diff_length)
    start_c = '{}{}'.format(QUARTERS_REVERSE[start[5:]], start[:3])
    end_c = '{}{}'.format(QUARTERS_REVERSE[end[5:]], end[:3])
    starting_index = contracts.QUARTERLY.index(start_c)
    ending_index = contracts.QUARTERLY.index(end_c)
    all_data = pd.Series()
    for i in xrange(starting_index, ending_index + 1):
        current = contracts.QUARTERLY[i]
        # end_date = '{}-{}'.format(current[1:], QUARTERS[current[0]])
        # start_date = datetime.strptime(end_date, '%Y-%m-%d')
        # start_date = start_date - relativedelta(months=6)
        data = _get_data(contract + contracts.QUARTERLY[i],
                         start=start,
                         end=end,
                         collapse=collapse)
        all_data[data.index[-1]] = data[-1] - data[0]
    return all_data