def treasury_yield(required_data):
    '''
    required data is an empty? dataframe that will be populated.
    
    
    Returns a dataframe.
    '''
    treasury_data = zipline_treasuries.get_treasury_data()
    treasury_yield = pd.DataFrame.from_records(data=treasury_data)
    treasury_yield.set_index('date', inplace=True)
    required_data.update(treasury_yield)
    required_data = required_data * 10 # zipline has their yields in tenths' of a percent??
    return required_data
Beispiel #2
0
def treasury_yield(required_data):
    '''
    required data is an empty? dataframe that will be populated.
    
    
    Returns a dataframe.
    '''
    treasury_data = zipline_treasuries.get_treasury_data()
    treasury_yield = pd.DataFrame.from_records(data=treasury_data)
    treasury_yield.set_index('date', inplace=True)
    required_data.update(treasury_yield)
    required_data = required_data * 10  # zipline has their yields in tenths' of a percent??
    return required_data
Beispiel #3
0
    def load_market_data(self, bm_symbol='^GSPC'):
        #TODO Parametric
        #event_dt = datetime.today().replace(tzinfo=pytz.utc)
        event_dt = datetime.now(pytz.utc)

        # Getting today benchmark return
        #NOTE Seems shit but later, previous days could be used to compute indicators
        #last_bench_return = get_benchmark_returns(bm_symbol, start_date=(event_dt - pd.datetools.Day(self.loopback)))
        #last_bench_return = last_bench_return[-1]
        #print('Benchmark on {}: {}'.format(last_bench_return.date, last_bench_return.returns))

        for exchange, infos in datautils.Exchange.iteritems():
            if infos['index'] == bm_symbol:
                code = datautils.Exchange[exchange]['code']
                break

        bm_returns = []
        while event_dt < self.last_trading_day:
            #TODO Current value to give
            #TODO Append only if trading day and market hour
            #bm_returns.append(DailyReturn(date=event_dt.replace(microsecond=0), returns=last_bench_return.returns))
            bm_returns.append(DailyReturn(date=event_dt.replace(microsecond=0), returns=code))
            #TODO Frequency control
            event_dt += self.offset

        bm_returns = sorted(bm_returns, key=attrgetter('date'))

        tr_gen = get_treasury_data()
        while True:
            try:
                last_tr = tr_gen.next()
            except StopIteration:
                break

        tr_curves = {}
        #tr_dt = datetime.today().replace(tzinfo=pytz.utc)
        tr_dt = datetime.now(pytz.utc)
        while tr_dt < self.last_trading_day:
            #tr_dt = tr_dt.replace(hour=0, minute=0, second=0, tzinfo=pytz.utc)
            tr_curves[tr_dt] = last_tr
            tr_dt += self.offset

        tr_curves = OrderedDict(sorted(
                                ((dt, c) for dt, c in tr_curves.iteritems()),
                                key=lambda t: t[0]))

        return bm_returns, tr_curves