Ejemplo n.º 1
0
mkts = {
    'SP 500': 'CHRIS/CME_SP1',
    'Natural Gas': 'CHRIS/CME_NG1',
    'US 10Y': 'CHRIS/CME_TY1',
    'Crude Oil': 'CHRIS/CME_CL1',
    'Eurostoxx 50': 'CHRIS/EUREX_FESX1',
    'Dollar Index': 'CHRIS/ICE_DX1',
    'Wheat': 'CHRIS/CME_W7',
    'Corn': 'CHRIS/CME_C1',
    'Dax': 'CHRIS/EUREX_FDAX1',
    'FTSE100': 'CHRIS/LIFFE_Z1',
    'Eurodollar': 'CHRIS/CME_ED1',
    'Euro': 'CHRIS/CME_EC1',
    'GBP': 'CHRIS/CME_BP1',
    'Gold': 'CHRIS/CME_EC1'
}

data_index = pd.DataFrame()
for m in mkts.keys():
    try:
        data_index[m] = quandl.get(mkts[m], authtoken=token).Last
    except:
        data_index[m] = quandl.get(mkts[m], authtoken=token).Settle
data_pct = data_index.pct_change()

s = calc_ts_pairwise_correlation(data_pct)
s['2000':].plot(colormap='jet').get_figure().savefig('pairwise.png')

e = Email(subject='Morning Update: Pairwise Correlation')
e.add_attachment('pairwise.png')
e.send()
            except:
                try:
                    data_index[m]=quandl.get(mkts[m],authtoken=token).value
                except:
                    data_index[m]=quandl.get(mkts[m],authtoken=token).Rate
data_pct=data_index.pct_change()  



s=calc_ts_pairwise_correlation(data_pct)
s.dropna().to_csv('pairwise_c.csv')

s['2000':].plot(colormap='jet').get_figure().savefig('pairwise.png')

e=Email(subject='Morning Update: Pairwise Correlation')
e.add_attachment('pairwise.png')
e.send()


data_pct['2019':].cumsum().ffill().plot(colormap='brg').get_figure().savefig('YTD.png')

e=Email(subject='Morning Update: Macro YTD Email')
e.add_attachment('YTD.png')
e.send()




def get_sector_data():
      sp=SectorPerformances (key=key, output_format='pandas')
      data,_ = sp.get_sector()
Ejemplo n.º 3
0
import pandas as pd
import matplotlib.pyplot as plt
plt.switch_backend('agg')
from mail import Email
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.sectorperformance import SectorPerformances
key = 'B22889019-EABCFEE1'
sns.set_context("poster")


def get_sector_data():
    sp = SectorPerformances(key=key, output_format='pandas')
    data, _ = sp.get_sector()
    df = pd.DataFrame()
    df['1M Performane'] = data['Rank D: Month Performance']
    df['YTD Performance'] = data['Rank F: Year-to-Date (YTD) Performance']
    df['1Y Performance'] = data['Rank G: Year Performance']
    df['3Y Performance'] = (data['Rank H: Year Performance'] +
                            1)**.33333333 - 1
    df['10Y Performance'] = (data['Rank J: Year Performance'] + 1)**.1 - 1
    return df


get_sector_data().plot(
    kind='bar', colormap='jet',
    title='Performance (Long term Annualized)').get_figure().savefig(
        'sector.png', bbox_inches='tight')

e = Email(subject='Morning Update: Sector Performance')
e.add_attachment('sector.png')
e.send()
Ejemplo n.º 4
0
sns.set(font_scale=1)


def get_stock_adj_price(ticker):
    ts = TimeSeries(key=key, output_format='pandas')
    data, meta_data = ts.get_daily_adjusted(ticker, outputsize='full')
    data.index = pd.to_datetime(data.index)
    return data['5. adjusted close']


df = pd.DataFrame()
time.sleep(61)
df['Min Vol'] = get_stock_adj_price('USMV')
df["Momentum"] = get_stock_adj_price('MTUM')
df['Quality'] = get_stock_adj_price('QUAL')
df['Value'] = get_stock_adj_price('FNDX')
time.sleep(61)
df['Size'] = get_stock_adj_price('SIZE')

sp = get_stock_adj_price('VOO')

rets = df.dropna().pct_change()
hedged_factor = rets.subtract(sp.pct_change(), axis=0)

hedged_factor.dropna()['2019':].cumsum().plot(
    title='Hedged US factor (ETF Performance)').get_figure().savefig(
        'factor.png', bbox_inches='tight')

e = Email(subject='Morning Update: Factor Performance')
e.add_attachment('factor.png')
e.send()
Ejemplo n.º 5
0
      'Corn':'CHRIS/CME_C1',
      'Dax':'CHRIS/EUREX_FDAX1',
      'FTSE100':'CHRIS/LIFFE_Z1',
      'Eurodollar':'CHRIS/CME_ED1',
      'Euro':'CHRIS/CME_EC1',
      'GBP':'CHRIS/CME_BP1',
      'Gold':'CHRIS/CME_EC1'
      }

data_index=pd.DataFrame()
for m in mkts.keys():
    try:
        data_index[m]=quandl.get(mkts[m],authtoken=token).Last
    except:
        data_index[m]=quandl.get(mkts[m],authtoken=token).Settle
data_pct=data_index.dropna().pct_change()
data=data_pct.dropna()
number=data.count().iloc[1]

window=20
results=pd.DataFrame()
for i in range(window+1,number):
    pca = PCA(n_components=5)
    pca.fit(data[i-window:i])
    results[data.iloc[i].name]=pd.Series(pca.explained_variance_)**.5

results.T['2018':].plot(kind='area',colormap='magma',title='Vol Explained').get_figure().savefig('vol_explained.png')

e=Email(subject='Morning Update: Volatility explained by compoents')
e.add_attachment('vol_explained.png')
e.send()
Ejemplo n.º 6
0
data_index = pd.DataFrame()
for m in mkts.keys():
    try:
        data_index[m] = quandl.get(mkts[m], authtoken=token).Last
    except:
        try:
            data_index[m] = quandl.get(mkts[m], authtoken=token).Settle
        except:
            try:
                data_index[m] = quandl.get(mkts[m], authtoken=token).Value
            except:
                try:
                    data_index[m] = quandl.get(mkts[m], authtoken=token).value
                except:
                    try:
                        data_index[m] = quandl.get(mkts[m],
                                                   authtoken=token).Rate
                    except:
                        print(m)
data_pct = data_index.pct_change()

mu = pd.ewma(data_pct, 260)
sd = pd.ewmstd(data_pct, 260)
zscores = (data_pct - mu) / sd
last = zscores.iloc[-2].dropna().sort_values()
last.plot(kind='barh', colormap='jet',
          ylim=[-3, 3]).get_figure().savefig('zscore.png', bbox_inches='tight')

e = Email(subject='Morning Update: Macro Dashboard')
e.add_attachment('zscore.png')
e.send()
Ejemplo n.º 7
0
    'GBP': 'CHRIS/CME_BP1',
    #'Gold':'CHRIS/CME_EC1'
}

data_index = pd.DataFrame()
for m in mkts.keys():
    try:
        data_index[m] = quandl.get(mkts[m], authtoken=token).Last
    except:
        try:
            data_index[m] = quandl.get(mkts[m], authtoken=token).Settle
        except:
            try:
                data_index[m] = quandl.get(mkts[m], authtoken=token).Value
            except:
                try:
                    data_index[m] = quandl.get(mkts[m], authtoken=token).value
                except:
                    try:
                        data_index[m] = quandl.get(mkts[m],
                                                   authtoken=token).Rate
                    except:
                        print(m)
data_pct = data_index.pct_change()

data_pct['2019':].cumsum().ffill().plot(
    colormap='brg').get_figure().savefig('YTD.png')

e = Email(subject='Morning Update: Macro YTD Email')
e.add_attachment('YTD.png')
e.send()