Skip to content

Commit

Permalink
Fix bloomberg data
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-leme committed May 8, 2021
1 parent 0356041 commit 5b4cc21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions hack_itau_quant/bloomberg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def get_hack_data():
df_IMAB.index = pd.to_datetime(df_IMAB.index)
df_IRFM.index = pd.to_datetime(df_IRFM.index)

df_IMAB_indice = blp.bdh('BZRFIMAB index', 'PX_LAST', '2017-12-30', '2019-05-20')
df_IMAB_indice = blp.bdh('BZRFIMAB index', 'PX_LAST', '2017-12-30', '2019-05-19')
df_IMAB_indice.index = pd.to_datetime(df_IMAB_indice.index)
df_IMAB_indice = df_IMAB_indice.rename(columns ={'BZRFIMAB index' : 'IMAB11 BZ Equity'})
df_IMAB = pd.concat([df_IMAB_indice/1000, df_IMAB])

df_IRFM_indice = blp.bdh('BZRFIRFM Index', 'PX_LAST', '2017-12-30', '2019-09-23')
df_IRFM_indice = blp.bdh('BZRFIRFM Index', 'PX_LAST', '2017-12-30', '2019-09-22')
df_IRFM_indice.index = pd.to_datetime(df_IRFM_indice.index)
df_IRFM_indice = df_IRFM_indice.rename(columns ={'BZRFIRFM Index' : 'IRFM11 BZ Equity'})
df_IRFM = pd.concat([df_IRFM_indice/1000, df_IRFM])
Expand Down
40 changes: 20 additions & 20 deletions hack_itau_quant/efficient_frontier.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,48 +67,48 @@ def _plot(self, returns, risks, weigths):
hovertemplate="Volatilities: %{x:,.2f}<br>"+
"Returns: %{y:.5f}<br>"+
"Sharpe: %{text:.5f}<br>"+
"BOVV11: %{customdata[0]}%<br>"+
"SPXI11: %{customdata[1]}%<br>"+
"IMAB11: %{customdata[2]}%<br>"+
"IRFM11: %{customdata[3]}%<br>",
"BOVV11 BZ Equity: %{customdata[0]}%<br>"+
"SPXI11 BZ Equity: %{customdata[1]}%<br>"+
"IMAB11 BZ Equity: %{customdata[2]}%<br>"+
"IRFM11 BZ Equity: %{customdata[3]}%<br>",
mode = ' markers + lines',
showlegend = False)

Max_Sharpe = go.Scatter(x = max_sharpe.Volatilies,
y = max_sharpe.Returns,
text=df[df['Volatilies'] == float(max_sharpe.Volatilies)]['Sharpe'],
customdata = np.stack((df[df['Volatilies'] == float(max_sharpe.Volatilies)]['BOVV11'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['SPXI11'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['IMAB11'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['IRFM11']),
customdata = np.stack((df[df['Volatilies'] == float(max_sharpe.Volatilies)]['BOVV11 BZ Equity'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['SPXI11 BZ Equity'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['IMAB11 BZ Equity'],
df[df['Volatilies'] == float(max_sharpe.Volatilies)]['IRFM11 BZ Equity']),
axis = -1),
hovertemplate=
"Volatilities: %{x:,.2f}<br>"+
"Returns: %{y:.5f}<br>"+
"Sharpe: %{text:.4f}<br>"+
"BOVV11: %{customdata[0]}%<br>"+
"SPXI11: %{customdata[1]}%<br>"+
"IMAB11: %{customdata[2]}%<br>"+
"IRFM11: %{customdata[3]}%<br>",
"BOVV11 BZ Equity: %{customdata[0]}%<br>"+
"SPXI11 BZ Equity: %{customdata[1]}%<br>"+
"IMAB11 BZ Equity: %{customdata[2]}%<br>"+
"IRFM11 BZ Equity: %{customdata[3]}%<br>",
mode = ' markers + lines',
name = 'Maximum Sharpe')

Min_Vol = go.Scatter(x = min_vol.Volatilies,
y = min_vol.Returns,
text=df[df['Volatilies'] == float(min_vol.Volatilies)]['Sharpe'],
customdata = np.stack((df[df['Volatilies'] == float(min_vol.Volatilies)]['BOVV11'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['SPXI11'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['IMAB11'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['IRFM11']),
customdata = np.stack((df[df['Volatilies'] == float(min_vol.Volatilies)]['BOVV11 BZ Equity'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['SPXI11 BZ Equity'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['IMAB11 BZ Equity'],
df[df['Volatilies'] == float(min_vol.Volatilies)]['IRFM11 BZ Equity']),
axis = -1),
hovertemplate=
"Volatilities: %{x:,.2f}<br>"+
"Returns: %{y:.5f}<br>"+
"Sharpe: %{text:.4f}<br>"+
"BOVV11: %{customdata[0]}%<br>"+
"SPXI11: %{customdata[1]}%<br>"+
"IMAB11: %{customdata[2]}%<br>"+
"IRFM11: %{customdata[3]}%<br>",
"BOVV11 BZ Equity: %{customdata[0]}%<br>"+
"SPXI11 BZ Equity: %{customdata[1]}%<br>"+
"IMAB11 BZ Equity: %{customdata[2]}%<br>"+
"IRFM11 BZ Equity: %{customdata[3]}%<br>",
mode = ' markers + lines',
name = 'Minimal Volatility')

Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy as np

close_prices = BloombergData.get()
close_prices = BloombergData.get_hack_data()

returns = close_prices.pct_change()[1:]

Expand Down

0 comments on commit 5b4cc21

Please sign in to comment.