Ibovespa is Brazilian stock market price analysis in python

What is Brazilian  stock market called?

Brazil stock market is ^BVSP is benchmark of 70 stocks.

IBOVESPA (^BVSP) is Brl means brazil

<matplotlib.legend.Legend at 0x7ff576dc1550>
<matplotlib.legend.Legend at 0x7ff576dc1550>
bvsp return



Need some code in python

import yfinance as yf

import numpy as np

import pandas as pd

import seaborn as sns

import scipy.stats as scs

import statsmodels.api as sm

import statsmodels.tsa.api as smt

import matplotlib.pyplot as plt

How to collect data in python?

df = yf.download('^BVSP',

start='1985-01-01',

end='2021-07-29',

progress=False)

Find simple and log return

df[['simple_rtn','log_rtn']].tail(20)

Get simple and log return

Define Relise volatility code in python

def realized_volatility(x):

 return np.sqrt(np.sum(x**2))

df_rv = df.groupby(pd.Grouper(freq='M')).apply(realized_volatility)

df_rv.rename(columns={'log_rtn': 'rv'}, inplace=True)

df_rv.rv = df_rv.rv * np.sqrt(12)

fig, ax = plt.subplots(2, 1, sharex=True)

ax[0].plot(df)

ax[1].plot(df_rv)

Plot relise volatility

How to plot simple,log return in python?

fig, ax = plt.subplots(3, 1, figsize=(24, 20), sharex=True)

df.adj_close.plot(ax=ax[0])

ax[0].set(title = 'BVSP time series',

ylabel = 'Stock price ($)')

df.simple_rtn.plot(ax=ax[1])

ax[1].set(ylabel = 'Simple returns (%)')

df.log_rtn.plot(ax=ax[2])

ax[2].set(xlabel = 'Date',

ylabel = 'Log returns (%)')

Log return

fig, ax = plt.subplots()

ax.plot(df_outliers.index, df_outliers.simple_rtn,

color='blue', label='Normal')

ax.scatter(outliers.index, outliers.simple_rtn,

color='red', label='Anomaly')

ax.set_title("BVSP returns")

ax.legend(loc='lower right')

Outliers simple return plot

Correction between Ibovespa  and vix

ax = sns.regplot(x='log_rtn', y='vol_rtn', data=df,

line_kws={'color': 'red'})

ax.set(title=f'BVSP vs. VIX ($\\rho$ = {corr_coeff:.2f})',

ylabel='VIX log returns',

xlabel='BVSP log returns')

Plot correlation between BVSP and VIX

New updated IBOVESPA

Post a Comment

0 Comments