text_html_output_2.png
import matplotlib.pyplot as plt

import pandas as pd

import plotly.graph_objects as go

data = pd.read_csv('/kaggle/input/ibex3519942020/IBEX-2021.csv')

fg, ax =plt.subplots(1,2,figsize=(20,7))
ax[0].plot(data['Open'],label='Open',color='green')
ax[0].set_xlabel('Date',size=15)
ax[0].set_ylabel('Price',size=15)
ax[0].legend()

ax[1].plot(data['Close'],label='Close',color='red')
ax[1].set_xlabel('Date',size=15)
ax[1].set_ylabel('Price',size=15)
ax[1].legend()

fg.show()

import plotly.graph_objects as go
fig = go.Figure(data=go.Ohlc(x=data['Date'], open=data['Open'], high=data['High'], low=data['Low'], close=data['Close']))

data['SMA5'] = data.Close.rolling(5).mean()
data['SMA20'] = data.Close.rolling(20).mean()
data['SMA50'] = data.Close.rolling(50).mean()
fig = go.Figure(data=[go.Ohlc(x=data['Date'], open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], name='OHLC'), go.Scatter(x=data.Date, y=data.SMA5, line=dict(color='orange', width=1), name='SMA5'), go.Scatter(x=data.Date, y=data.SMA20, line=dict(color='green', width=1), name='SMA20'), go.Scatter(x=data.Date, y=data.SMA50, line=dict(color='blue', width=1), name='SMA50')])

data['EMA5'] = data.Close.ewm(span=5, adjust=False).mean()
data['EMA20'] = data.Close.ewm(span=20, adjust=False).mean()
fig = go.Figure(data=[go.Ohlc(x=data['Date'], open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], name='OHLC'), go.Scatter(x=data.Date, y=data.EMA5, line=dict(color='orange', width=1), name='EMA5'), go.Scatter(x=data.Date, y=data.EMA20, line=dict(color='green', width=1), name='EMA20')])

def bollinger_bands(df, n, m):
    TP = (df['High'] + df['Low'] + df['Close']) / 3
    data = TP
    B_MA = pd.Series(data.rolling(n, min_periods=n).mean(), name='B_MA')
    sigma = data.rolling(n, min_periods=n).std()
    BU = pd.Series(B_MA + m * sigma, name='BU')
    BL = pd.Series(B_MA - m * sigma, name='BL')
    df = df.join(B_MA)
    df = df.join(BU)
    df = df.join(BL)
    return df
df = bollinger_bands(data, 20, 2)

plt.figure(figsize=(15, 5))
plt.plot(df['Date'], df['Adj Close'])
plt.title('Price chart (Adj Close) IBEX')
plt.show()
plt.figure(figsize=(15, 5))
plt.title('Bollinger Bands chart IBEX')
plt.plot(df['Date'], df['Adj Close'])
plt.plot(df['Date'], df['BU'], alpha=0.3)
plt.plot(df['Date'], df['BL'], alpha=0.3)
plt.plot(df['Date'], df['B_MA'], alpha=0.3)
plt.fill_between(df['Date'], df['BU'], df['BL'], color='grey', alpha=0.1)
plt.show()