Example #1
0
def plot_universe(universe='SMX'):
    rtn, rs, rm, v = channel.get_dataset(universe, max_spread=None)
    t4 = stocks.load_google_returns(data_table=stocks.UK_ESTIMATES,
                                    data_name='T4')
    t52 = stocks.load_google_returns(data_table=stocks.UK_ESTIMATES,
                                     data_name='T52')
    t4 = t4.reindex(rtn.columns, axis=1)
    t52 = t52.reindex(rtn.columns, axis=1)
    make_channel_pdf(rtn[dt(2010, 1, 1):], universe, t4.iloc[-1], t52.iloc[-1])
Example #2
0
def export_lse_spreads():
    filename = get_filename('spread')
    data = stocks.load_google_returns(data_name='Spread',
                                      data_table=stocks.UK_STOCKS)
    f = pd.ExcelWriter(filename)
    data.to_excel(f)
    f.save()
Example #3
0
def load_lse_ids(missing=True):
    u = stocks.load_uk_universe()
    if missing:
        existing = stocks.get_universe('LSE')
        u2 = u.loc[~u.index.isin(existing.index)]
        if u2.empty:
            s = stocks.load_google_returns(data_name='Spread')
            s = s.iloc[-1].loc[u.index]
            u = u.loc[s.isnull()]
        else:
            u = u2
    ans = pd.Series([])
    i = 0
    for ticker in u.index:
        logger.info('Loading %s' % ticker)
        tmp = load_lse_id(ticker)
        if tmp is None:
            i += 1
        else:
            i = 0
            ans.loc[ticker] = tmp
        if i >= 5:
            break
    if not ans.empty:
        ans.name = 'LSE'
        stocks._save_tickers(ans, 'LSE')
Example #4
0
def export_stock_returns():
    filename = get_filename('Returns')
    f = pd.ExcelWriter(filename)
    for data_type in ['Returns', 'Volume']:
        data = stocks.load_google_returns(data_name=data_type,
                                          data_table=stocks.UK_STOCKS)
        data.to_excel(f, sheet_name=data_type)
    f.save()
Example #5
0
def export_reuters_data():
    tags = ['Rating', 'C1', 'C3', 'T1', 'T4', 'T8', 'T52']
    filename = get_filename('Reuters')
    f = pd.ExcelWriter(filename)
    for data_name in tags:
        data = stocks.load_google_returns(data_name=data_name,
                                          data_table=stocks.UK_ESTIMATES)
        data.to_excel(f, sheet_name=data_name)
    f.save()
Example #6
0
def run_check():
    t4 = stocks.load_google_returns(data_table=stocks.UK_ESTIMATES,
                                    data_name='T4').iloc[-1]
    t8 = stocks.load_google_returns(data_table=stocks.UK_ESTIMATES,
                                    data_name='T8').iloc[-1]
    t52 = stocks.load_google_returns(data_table=stocks.UK_ESTIMATES,
                                     data_name='T52').iloc[-1]
    rtn, rm, vol, _ = cross.get_dataset('SMX')
    p = .2 / vol.iloc[-1]
    table = get_week_table(rtn)
    table2 = get_reversal_table(rm.loc[:, t4.reindex(rm.columns) > 0], t4, p)
    table7 = get_reversal_table(rm.loc[:, t8.reindex(rm.columns) > 0], t8, p,
                                8)
    table5 = get_momentum_table(rm.loc[:, t52.reindex(rm.columns) > 0], t4,
                                t52, p)
    rtn, rm, vol, _ = cross.get_dataset('FTSE250')
    p = .2 / vol.iloc[-1]
    table3 = get_week_table(rtn)
    table4 = get_reversal_table(rm.loc[:, t4.reindex(rm.columns) > 0], t4, p)
    table8 = get_reversal_table(rm.loc[:, t8.reindex(rm.columns) > 0], t8, p,
                                8)
    table6 = get_momentum_table(rm.loc[:, t52.reindex(rm.columns) > 0], t4,
                                t52, p)
    mail = Email('*****@*****.**', ['*****@*****.**'],
                 'Market Watch')
    mail.add_date(dt.today())
    mail.add_text('SMX Week')
    mail.add_table(table, width=300)
    mail.add_text('SMX Reversal')
    mail.add_table(table2, width=350)
    mail.add_text('SMX 2M Reversal')
    mail.add_table(table7, width=350)
    mail.add_text('SMX Momentum')
    mail.add_table(table5, width=400)
    mail.add_text('FTSE250 Week')
    mail.add_table(table3, width=300)
    mail.add_text('FTSE250 Reversal')
    mail.add_table(table4, width=350)
    mail.add_text('FTSE250 2M Reversal')
    mail.add_table(table8, width=350)
    mail.add_text('FTSE250 Momentum')
    mail.add_table(table6, width=400)
    mail.send_email()
Example #7
0
 def load_stock_data(self):
     logger.info('Loading stock returns')
     r = stocks.load_google_returns(self.start_date - relativedelta(years=1), self.end_date, data_table=stocks.UK_STOCKS)
     rx = stocks.load_google_returns(self.start_date - relativedelta(years=1), self.end_date, data_table=stocks.GLOBAL_ASSETS)
     vm = stocks.load_google_returns(self.start_date - relativedelta(years=1), self.end_date, 'Volume', data_table=stocks.UK_STOCKS)
     a = alpha.load_alpha(self.start_date - relativedelta(years=1), self.end_date, data_table=alpha.UK_ALPHA)
     self.market_returns = rx.loc[:, 'MCX']
     self.stock_returns = r.loc[:, r.columns.isin(self.u.index)]
     self.asset_names = self.stock_returns.columns
     self.stock_alpha = a.loc[:, a.columns.get_level_values(1).isin(self.u.index)]
     alpha_returns = a.loc[:, a.columns.get_level_values(0) == 'Alpha']
     alpha_returns = alpha_returns.groupby(level=1, axis=1).sum().loc[:, self.asset_names]
     self.stock_volume = vm.loc[:, self.stock_returns.columns]
     self._r = self.stock_returns.cumsum().ffill(limit=5).resample('W').last().diff()
     self._rs = alpha_returns.cumsum().ffill(limit=5).resample('W').last().diff()
     w = self.stock_returns.resample('W').sum().abs()
     v = w[w > 0].rolling(52, min_periods=13).median().ffill().bfill()
     self.stock_vol = tu.resample(v, self._r)
     self.stock_vol[self.stock_vol < STOCK_VOL_FLOOR] = STOCK_VOL_FLOOR
     self.r = self._r.divide(v)
     self.rs = self._rs.divide(v)
     self.rm = self.rs.subtract(self.rs.mean(axis=1), axis=0)
Example #8
0
def get_universe_returns(universe, data_name='Returns'):
    u = stocks.load_universe(universe)
    r = stocks.load_google_returns(data_table=stocks.UK_STOCKS,
                                   data_name=data_name,
                                   tickers=u.index)
    return r.reindex(u.index, axis=1)