-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
66 lines (51 loc) · 2.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Importando as dependências
import yfinance as yf
import streamlit as st
import plotly.express as px
# Importando os módulos
from modulos.page import page
from modulos.style import css # Estilo
from modulos.data import dataFrame # Data frame
from modulos.graphic import line, bar # Gráficos
from modulos.right_bar import right_bar # Barra lateral esquerda
page()
st.markdown("<h1>Fechamento das ações 💹</h1>", unsafe_allow_html=True)
st.markdown("---")
ticker = st.text_input("Digite a sua ação", "Bbdc3") # ITUB4
empresa = yf.Ticker(f"{ticker}.SA")
# Data frame
tickerDF = empresa.history(period="id", start="2020-01-01", end="2024-01-20")
# Filtrando dados para os anos de 2020 até 2024
tickerDF_filtered = tickerDF[(tickerDF.index.year >= 2020) & (tickerDF.index.year <= 2024)]
# Agrupando os dados por ano
tickerDF_grouped = tickerDF_filtered.groupby(tickerDF_filtered.index.year).sum()
col_empresa,col_preço = st.columns(2) # Colunas
with col_empresa:
st.write(f"**Empresa:** {empresa.info['longName']}") # Nome da empresa
with col_preço:
st.write(f"**Preço Atual:** {empresa.info['currentPrice']}**BRL**") # Valor da ação
st.write(f"**Mercado:** {empresa.info['industryDisp']}") # Industria / Mercado
# Plotagem do data frame
with st.expander("Tabela"):
st.markdown("<h2>Data Frame 📋</h2>", unsafe_allow_html=True)
dataFrame(tickerDF_filtered)
st.markdown("---")
# Plotagem dos gráficos
tab1, tab2 = st.tabs(["Gráfico de Linha", "Gráfico Barras"])
with tab1:
line(tickerDF) # Linha
with tab2:
bar(tickerDF) # Barra
# Gráfico de Pizza (Pie Chart)
def pie():
colors = ['#004200', '#67a258', '#21187a', '#900000', '#ed3b20'] # Configurando as cores
fig_pie = px.pie(tickerDF_grouped, values='Close',
color_discrete_sequence=colors,
title=f"O gráfico abaixo mostra os fechamentos anuais da empresa: {ticker}", # Descrição
names=tickerDF_grouped.index
)
st.plotly_chart(fig_pie)
with st.expander("Fechamento Anual 💰"):
pie()
right_bar() # Barra lateral
css() # Estilo do projeto