In [ ]:


In [1]:
# Importing pandas
import pandas as pd
# Import pandas Web reader - for Yahoo/Google Finance
from pandas.util.testing import assert_frame_equal
import pandas_datareader.data as web

import numpy as np

import datetime

# Importing matplotlib and setting aesthetics for plotting later.
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'svg' 
plt.style.use('fivethirtyeight')


/home/guido/.ve/statistics/lib/python3.6/site-packages/pandas/compat/__init__.py:117: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
  warnings.warn(msg)
/home/guido/.ve/statistics/lib/python3.6/site-packages/ipykernel_launcher.py:4: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
  after removing the cwd from sys.path.

In [2]:
start = datetime.datetime(2015, 1, 1)

In [3]:
tickers_commercial = ["HGRE11.SA", "BRCR11.SA", "KNRI11.SA"]


b3_data = pd.DataFrame()
for fii in tickers_commercial:
    b3_data[fii] = web.DataReader(fii, data_source='yahoo', start=start)['Close']

b3_data.head()


Out[3]:
HGRE11.SA BRCR11.SA KNRI11.SA
Date
2015-01-02 126.656998 110.000000 104.199997
2015-01-05 128.199005 110.449997 105.199997
2015-01-06 125.500000 109.599998 105.750000
2015-01-07 125.500000 110.480003 104.000000
2015-01-08 125.500999 109.800003 104.500000

In [4]:
def plot_normalized_returns(b3_data):
    log_returns = b3_data / b3_data.iloc[0]*100
    log_returns.plot(figsize=(15,5))
    plt.ylabel('NORMALIZED PRICES')
    plt.xlabel('DATE')
    plt.show()

plot_normalized_returns(b3_data)



In [14]:
tickers_logistic = ["HGLG11.SA", "GGRC11.SA", "FIIB11.SA", "ALZR11.SA", "LVBI11.SA"]
start = datetime.datetime(2019, 1, 1)

b3_data_logistic = pd.DataFrame()
for fii in tickers_logistic:
    b3_data_logistic[fii] = web.DataReader(fii, data_source='yahoo', start=start)['Close']

b3_data_logistic.head()


Out[14]:
HGLG11.SA GGRC11.SA FIIB11.SA ALZR11.SA LVBI11.SA
Date
2019-01-02 140.899994 136.619995 426.5 97.800003 105.0
2019-01-03 140.949997 135.000000 427.5 97.989998 105.0
2019-01-04 140.250000 134.500000 427.5 98.000000 105.0
2019-01-07 141.500000 134.699997 428.0 98.699997 105.0
2019-01-08 142.000000 134.179993 428.0 98.599998 101.0

In [15]:
plot_normalized_returns(b3_data_logistic)



In [ ]: