├── requirements.txt ├── Screenshot_1.png ├── README.md ├── bovespa.py ├── .github └── workflows │ └── codeql-analysis.yml └── Como_extrair_dados_de_ações_da_Bovespa_sem_gastar_nada_com_Python.ipynb /requirements.txt: -------------------------------------------------------------------------------- 1 | yahooquery -------------------------------------------------------------------------------- /Screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigobercini/como-extrair-dados-bovespa/HEAD/Screenshot_1.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Instalar biblioteca 2 | 3 | ``` 4 | python -m pip install -r requirements.txt 5 | ``` 6 | 7 | Rodar o codigo localmente para teste 8 | 9 | ``` 10 | python bovespa.py 11 | ``` 12 | 13 | Notebook do artigo [Como extrair dados da Bovespa de graça com Python](https://medium.com/@rodrigobercinimartins/como-extrair-dados-da-bovespa-de-graca-com-python-14a03454a720) 14 | 15 | O código também está disponível em: 16 | https://gist.github.com/rodrigobercini/8bbee7fc735ad7d696f7a2ec31df9610 17 | 18 | ![Stocks](Screenshot_1.png) 19 | -------------------------------------------------------------------------------- /bovespa.py: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/rodrigobercini/8bbee7fc735ad7d696f7a2ec31df9610 2 | from yahooquery import Ticker 3 | 4 | # Período máximo 5 | petr = Ticker("PETR4.SA") 6 | petr.history(period='max') 7 | 8 | # Datas específicas 9 | petr.history(start='2005-05-01', end='2013-12-31') 10 | 11 | # Intraday - 30 minutos 12 | abev = Ticker('ABEV3.SA') 13 | abev.history(period='60d', interval = "30m") 14 | 15 | # Intraday - 1 minuto 16 | abev = abev.history(period='7d', interval = "1m") 17 | print(abev) 18 | 19 | # Informações financeiras 20 | petr = Ticker("PETR4.SA") # Coleta dados 21 | petr = petr.income_statement()# Chama função de Demonstração de resultados 22 | petr = petr.transpose() # Transpõe a matriz 23 | petr.columns = petr.iloc[0,:] # Renomeia colunas 24 | petr = petr.iloc[2:,:-1] # Seleciona dados 25 | petr = petr.iloc[:, ::-1] # Inverte colunas 26 | print(petr) 27 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '19 2 * * 0' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: [ 'python' ] 32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 33 | # Learn more: 34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 35 | 36 | steps: 37 | - name: Checkout repository 38 | uses: actions/checkout@v2 39 | 40 | # Initializes the CodeQL tools for scanning. 41 | - name: Initialize CodeQL 42 | uses: github/codeql-action/init@v1 43 | with: 44 | languages: ${{ matrix.language }} 45 | # If you wish to specify custom queries, you can do so here or in a config file. 46 | # By default, queries listed here will override any specified in a config file. 47 | # Prefix the list here with "+" to use these queries and those in the config file. 48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 49 | 50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 51 | # If this step fails, then you should remove it and run the build manually (see below) 52 | - name: Autobuild 53 | uses: github/codeql-action/autobuild@v1 54 | 55 | # ℹ️ Command-line programs to run using the OS shell. 56 | # 📚 https://git.io/JvXDl 57 | 58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 59 | # and modify them (or add more) to build your code if your project 60 | # uses a compiled language 61 | 62 | #- run: | 63 | # make bootstrap 64 | # make release 65 | 66 | - name: Perform CodeQL Analysis 67 | uses: github/codeql-action/analyze@v1 68 | -------------------------------------------------------------------------------- /Como_extrair_dados_de_ações_da_Bovespa_sem_gastar_nada_com_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "metadata": { 6 | "id": "VB9KRG7UGGMZ", 7 | "colab_type": "code", 8 | "colab": {}, 9 | "tags": [] 10 | }, 11 | "source": [ 12 | "!pip install yahooquery" 13 | ], 14 | "execution_count": 1, 15 | "outputs": [ 16 | { 17 | "output_type": "stream", 18 | "name": "stdout", 19 | "text": "Collecting git+https://github.com/dpguthrie/yahooquery.git\n Cloning https://github.com/dpguthrie/yahooquery.git to /tmp/pip-req-build-swi5xcz7\n Running command git clone -q https://github.com/dpguthrie/yahooquery.git /tmp/pip-req-build-swi5xcz7\nRequirement already satisfied: lxml==4.5.0 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from yahooquery==2.2.4) (4.5.0)\nRequirement already satisfied: pandas>=0.24 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from yahooquery==2.2.4) (1.0.1)\nRequirement already satisfied: requests-futures==1.0.0 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from yahooquery==2.2.4) (1.0.0)\nRequirement already satisfied: selenium==3.141.0 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from yahooquery==2.2.4) (3.141.0)\nRequirement already satisfied: pytz>=2017.2 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from pandas>=0.24->yahooquery==2.2.4) (2019.3)\nRequirement already satisfied: python-dateutil>=2.6.1 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from pandas>=0.24->yahooquery==2.2.4) (2.8.1)\nRequirement already satisfied: numpy>=1.13.3 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from pandas>=0.24->yahooquery==2.2.4) (1.18.1)\nRequirement already satisfied: requests>=1.2.0 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from requests-futures==1.0.0->yahooquery==2.2.4) (2.22.0)\nRequirement already satisfied: urllib3 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from selenium==3.141.0->yahooquery==2.2.4) (1.25.8)\nRequirement already satisfied: six>=1.5 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.6.1->pandas>=0.24->yahooquery==2.2.4) (1.14.0)\nRequirement already satisfied: certifi>=2017.4.17 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from requests>=1.2.0->requests-futures==1.0.0->yahooquery==2.2.4) (2019.11.28)\nRequirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from requests>=1.2.0->requests-futures==1.0.0->yahooquery==2.2.4) (3.0.4)\nRequirement already satisfied: idna<2.9,>=2.5 in /home/rodrigo/anaconda3/lib/python3.7/site-packages (from requests>=1.2.0->requests-futures==1.0.0->yahooquery==2.2.4) (2.8)\nBuilding wheels for collected packages: yahooquery\n Building wheel for yahooquery (setup.py) ... \u001b[?25ldone\n\u001b[?25h Created wheel for yahooquery: filename=yahooquery-2.2.4-py3-none-any.whl size=45988 sha256=56fad9db1c339369005699b56b3b438cb04688ace02c6cc6c4a5cd9703e500d9\n Stored in directory: /tmp/pip-ephem-wheel-cache-dy2ko8b8/wheels/16/cb/78/28d61d2a39f8935584b4dccd456b3f70aafbfee09c917fc05c\nSuccessfully built yahooquery\nInstalling collected packages: yahooquery\nSuccessfully installed yahooquery-2.2.4\n" 20 | } 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "metadata": { 26 | "id": "oY8C9teTE1ha", 27 | "colab_type": "code", 28 | "colab": {} 29 | }, 30 | "source": [ 31 | "from yahooquery import Ticker\n", 32 | "petr = Ticker(\"PETR4.SA\")" 33 | ], 34 | "execution_count": 2, 35 | "outputs": [] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "metadata": { 40 | "id": "1-fxIWjjMZFy", 41 | "colab_type": "code", 42 | "outputId": "e348e1a1-6c92-47af-bdb6-3346dad4ae99", 43 | "colab": { 44 | "base_uri": "https://localhost:8080/", 45 | "height": 428 46 | } 47 | }, 48 | "source": [ 49 | "petr.history(period='max')" 50 | ], 51 | "execution_count": 3, 52 | "outputs": [ 53 | { 54 | "output_type": "execute_result", 55 | "data": { 56 | "text/plain": " low close open high volume \\\n2000-01-03 12:00:00 5.875000 5.875000 5.875000 5.875000 3.538944e+10 \n2000-01-04 12:00:00 5.550000 5.550000 5.550000 5.550000 2.886144e+10 \n2000-01-05 12:00:00 5.494000 5.494000 5.494000 5.494000 4.303360e+10 \n2000-01-06 12:00:00 5.475000 5.475000 5.475000 5.475000 3.405568e+10 \n2000-01-07 12:00:00 5.500000 5.500000 5.500000 5.500000 2.091264e+10 \n... ... ... ... ... ... \n2020-06-25 13:00:00 20.730000 21.469999 20.910000 21.469999 4.726350e+07 \n2020-06-26 13:00:00 20.780001 20.840000 21.209999 21.469999 5.549930e+07 \n2020-06-29 13:00:00 20.930000 21.660000 21.100000 21.660000 5.980960e+07 \n2020-06-30 13:00:00 21.090000 21.549999 21.340000 21.799999 6.501060e+07 \n2020-07-01 13:57:58 21.740000 22.080000 21.750000 22.180000 1.353410e+07 \n\n adjclose dividends splits \n2000-01-03 12:00:00 4.050183 0.0 0.0 \n2000-01-04 12:00:00 3.826131 0.0 0.0 \n2000-01-05 12:00:00 3.787526 0.0 0.0 \n2000-01-06 12:00:00 3.774427 0.0 0.0 \n2000-01-07 12:00:00 3.791661 0.0 0.0 \n... ... ... ... \n2020-06-25 13:00:00 21.469999 0.0 0.0 \n2020-06-26 13:00:00 20.840000 0.0 0.0 \n2020-06-29 13:00:00 21.660000 0.0 0.0 \n2020-06-30 13:00:00 21.549999 0.0 0.0 \n2020-07-01 13:57:58 22.080000 0.0 0.0 \n\n[5158 rows x 8 columns]", 57 | "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
lowcloseopenhighvolumeadjclosedividendssplits
2000-01-03 12:00:005.8750005.8750005.8750005.8750003.538944e+104.0501830.00.0
2000-01-04 12:00:005.5500005.5500005.5500005.5500002.886144e+103.8261310.00.0
2000-01-05 12:00:005.4940005.4940005.4940005.4940004.303360e+103.7875260.00.0
2000-01-06 12:00:005.4750005.4750005.4750005.4750003.405568e+103.7744270.00.0
2000-01-07 12:00:005.5000005.5000005.5000005.5000002.091264e+103.7916610.00.0
...........................
2020-06-25 13:00:0020.73000021.46999920.91000021.4699994.726350e+0721.4699990.00.0
2020-06-26 13:00:0020.78000120.84000021.20999921.4699995.549930e+0720.8400000.00.0
2020-06-29 13:00:0020.93000021.66000021.10000021.6600005.980960e+0721.6600000.00.0
2020-06-30 13:00:0021.09000021.54999921.34000021.7999996.501060e+0721.5499990.00.0
2020-07-01 13:57:5821.74000022.08000021.75000022.1800001.353410e+0722.0800000.00.0
\n

5158 rows × 8 columns

\n
" 58 | }, 59 | "metadata": {}, 60 | "execution_count": 3 61 | } 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "metadata": { 67 | "id": "kjM4P57RIwNX", 68 | "colab_type": "code", 69 | "outputId": "14a22525-7ffd-44c2-ea39-84d68697d203", 70 | "colab": { 71 | "base_uri": "https://localhost:8080/", 72 | "height": 428 73 | } 74 | }, 75 | "source": [ 76 | "petr.history(start='2005-05-01', end='2013-12-31')" 77 | ], 78 | "execution_count": 4, 79 | "outputs": [ 80 | { 81 | "output_type": "execute_result", 82 | "data": { 83 | "text/plain": " volume open low high close \\\n2005-05-02 13:00:00 19004800.0 11.811200 11.475000 11.811200 11.775000 \n2005-05-03 13:00:00 22736000.0 11.775000 11.568800 11.825000 11.727500 \n2005-05-04 13:00:00 27260800.0 11.750000 11.750000 11.971200 11.903800 \n2005-05-05 13:00:00 31670400.0 12.000000 11.925000 12.125000 12.125000 \n2005-05-06 13:00:00 29177600.0 12.188800 12.187500 12.475000 12.341300 \n... ... ... ... ... ... \n2013-12-20 12:00:00 26875500.0 17.250000 16.799999 17.290001 16.910000 \n2013-12-23 12:00:00 11520400.0 17.020000 16.870001 17.170000 17.059999 \n2013-12-26 12:00:00 15294800.0 17.150000 16.889999 17.190001 16.920000 \n2013-12-27 12:00:00 15114200.0 17.000000 16.820000 17.020000 16.930000 \n2013-12-30 12:00:00 10598500.0 16.950001 16.950001 17.250000 17.080000 \n\n adjclose dividends splits \n2005-05-02 13:00:00 8.541433 0.0 0.0 \n2005-05-03 13:00:00 8.506978 0.0 0.0 \n2005-05-04 13:00:00 8.634863 0.0 0.0 \n2005-05-05 13:00:00 8.795320 0.0 0.0 \n2005-05-06 13:00:00 8.952221 0.0 0.0 \n... ... ... ... \n2013-12-20 12:00:00 14.712623 0.0 0.0 \n2013-12-23 12:00:00 14.843129 0.0 0.0 \n2013-12-26 12:00:00 14.721321 0.0 0.0 \n2013-12-27 12:00:00 14.730024 0.0 0.0 \n2013-12-30 12:00:00 14.860531 0.0 0.0 \n\n[2158 rows x 8 columns]", 84 | "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
volumeopenlowhighcloseadjclosedividendssplits
2005-05-02 13:00:0019004800.011.81120011.47500011.81120011.7750008.5414330.00.0
2005-05-03 13:00:0022736000.011.77500011.56880011.82500011.7275008.5069780.00.0
2005-05-04 13:00:0027260800.011.75000011.75000011.97120011.9038008.6348630.00.0
2005-05-05 13:00:0031670400.012.00000011.92500012.12500012.1250008.7953200.00.0
2005-05-06 13:00:0029177600.012.18880012.18750012.47500012.3413008.9522210.00.0
...........................
2013-12-20 12:00:0026875500.017.25000016.79999917.29000116.91000014.7126230.00.0
2013-12-23 12:00:0011520400.017.02000016.87000117.17000017.05999914.8431290.00.0
2013-12-26 12:00:0015294800.017.15000016.88999917.19000116.92000014.7213210.00.0
2013-12-27 12:00:0015114200.017.00000016.82000017.02000016.93000014.7300240.00.0
2013-12-30 12:00:0010598500.016.95000116.95000117.25000017.08000014.8605310.00.0
\n

2158 rows × 8 columns

\n
" 85 | }, 86 | "metadata": {}, 87 | "execution_count": 4 88 | } 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "metadata": { 94 | "id": "AmUEfE0uNgTe", 95 | "colab_type": "code", 96 | "outputId": "69ce0a23-598f-4219-acb7-cf5928332d1f", 97 | "colab": { 98 | "base_uri": "https://localhost:8080/", 99 | "height": 446 100 | } 101 | }, 102 | "source": [ 103 | "abev = Ticker('ABEV3.SA')\n", 104 | "abev.history(period='60d', interval = \"30m\")" 105 | ], 106 | "execution_count": 15, 107 | "outputs": [ 108 | { 109 | "output_type": "execute_result", 110 | "data": { 111 | "text/plain": " open close volume low high\n2020-04-03 13:00:00 11.94 11.75 697300 11.72 11.94\n2020-04-03 13:30:00 11.69 11.52 1381000 11.50 11.80\n2020-04-03 14:00:00 11.51 11.42 3739800 11.40 11.61\n2020-04-03 14:30:00 11.42 11.39 1658000 11.31 11.43\n2020-04-03 15:00:00 11.38 11.28 1299500 11.27 11.42\n... ... ... ... ... ...\n2020-06-30 19:00:00 14.24 14.18 1374200 14.11 14.24\n2020-06-30 19:30:00 14.18 14.28 2202600 14.15 14.30\n2020-07-01 13:00:00 14.26 14.35 722000 14.26 14.44\n2020-07-01 13:30:00 14.35 14.47 3082500 14.24 14.50\n2020-07-01 13:59:30 14.48 14.48 0 14.48 14.48\n\n[829 rows x 5 columns]", 112 | "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
openclosevolumelowhigh
2020-04-03 13:00:0011.9411.7569730011.7211.94
2020-04-03 13:30:0011.6911.52138100011.5011.80
2020-04-03 14:00:0011.5111.42373980011.4011.61
2020-04-03 14:30:0011.4211.39165800011.3111.43
2020-04-03 15:00:0011.3811.28129950011.2711.42
..................
2020-06-30 19:00:0014.2414.18137420014.1114.24
2020-06-30 19:30:0014.1814.28220260014.1514.30
2020-07-01 13:00:0014.2614.3572200014.2614.44
2020-07-01 13:30:0014.3514.47308250014.2414.50
2020-07-01 13:59:3014.4814.48014.4814.48
\n

829 rows × 5 columns

\n
" 113 | }, 114 | "metadata": {}, 115 | "execution_count": 15 116 | } 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "metadata": { 122 | "id": "I6gp8Bd9TgwX", 123 | "colab_type": "code", 124 | "outputId": "e8f6acb9-cc6e-4898-8007-88070ab0b402", 125 | "colab": { 126 | "base_uri": "https://localhost:8080/", 127 | "height": 35 128 | } 129 | }, 130 | "source": [ 131 | "len(set(list(petr.index.date)))" 132 | ], 133 | "execution_count": 0, 134 | "outputs": [ 135 | { 136 | "output_type": "execute_result", 137 | "data": { 138 | "text/plain": [ 139 | "60" 140 | ] 141 | }, 142 | "metadata": { 143 | "tags": [] 144 | }, 145 | "execution_count": 91 146 | } 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "metadata": { 152 | "id": "OzmoSDYLRbmn", 153 | "colab_type": "code", 154 | "outputId": "295878de-50d2-4191-9a6e-20422e6192a5", 155 | "colab": { 156 | "base_uri": "https://localhost:8080/", 157 | "height": 446 158 | } 159 | }, 160 | "source": [ 161 | "abev = abev.history(period='7d', interval = \"1m\")\n", 162 | "abev" 163 | ], 164 | "execution_count": 16, 165 | "outputs": [ 166 | { 167 | "output_type": "execute_result", 168 | "data": { 169 | "text/plain": " open close high volume low\n2020-06-23 13:10:00 14.26 14.23 14.32 0.0 14.23\n2020-06-23 13:11:00 14.23 14.23 14.25 64200.0 14.21\n2020-06-23 13:12:00 14.22 14.19 14.23 93700.0 14.18\n2020-06-23 13:13:00 14.19 14.18 14.19 24300.0 14.16\n2020-06-23 13:14:00 14.18 14.18 14.18 4400.0 14.16\n... ... ... ... ... ...\n2020-07-01 13:56:00 14.42 14.43 14.43 71900.0 14.40\n2020-07-01 13:57:00 14.41 14.44 14.44 107600.0 14.41\n2020-07-01 13:58:00 14.43 14.47 14.50 179700.0 14.42\n2020-07-01 13:59:00 14.43 14.47 14.50 179700.0 14.42\n2020-07-01 13:59:21 14.47 14.47 14.47 0.0 14.47\n\n[2571 rows x 5 columns]", 170 | "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
openclosehighvolumelow
2020-06-23 13:10:0014.2614.2314.320.014.23
2020-06-23 13:11:0014.2314.2314.2564200.014.21
2020-06-23 13:12:0014.2214.1914.2393700.014.18
2020-06-23 13:13:0014.1914.1814.1924300.014.16
2020-06-23 13:14:0014.1814.1814.184400.014.16
..................
2020-07-01 13:56:0014.4214.4314.4371900.014.40
2020-07-01 13:57:0014.4114.4414.44107600.014.41
2020-07-01 13:58:0014.4314.4714.50179700.014.42
2020-07-01 13:59:0014.4314.4714.50179700.014.42
2020-07-01 13:59:2114.4714.4714.470.014.47
\n

2571 rows × 5 columns

\n
" 171 | }, 172 | "metadata": {}, 173 | "execution_count": 16 174 | } 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "metadata": { 180 | "id": "lVUaf4K-U0EX", 181 | "colab_type": "code", 182 | "outputId": "0d421a4b-5cfb-4558-b294-2c66c27d5fa8", 183 | "colab": { 184 | "base_uri": "https://localhost:8080/", 185 | "height": 35 186 | } 187 | }, 188 | "source": [ 189 | "len(set(list(abev.index.date)))" 190 | ], 191 | "execution_count": 17, 192 | "outputs": [ 193 | { 194 | "output_type": "execute_result", 195 | "data": { 196 | "text/plain": "7" 197 | }, 198 | "metadata": {}, 199 | "execution_count": 17 200 | } 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": { 206 | "id": "VlPqRuQlzPp5", 207 | "colab_type": "text" 208 | }, 209 | "source": [ 210 | "## Informações financeiras" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "metadata": { 216 | "id": "ZNvwlD-sU1XK", 217 | "colab_type": "code", 218 | "outputId": "bbf36f9d-c910-43b3-826c-094fb2de0167", 219 | "colab": { 220 | "base_uri": "https://localhost:8080/", 221 | "height": 1000 222 | } 223 | }, 224 | "source": [ 225 | "petr = Ticker(\"PETR4.SA\") # Coleta dados\n", 226 | "petr.income_statement() # Chama função de Demonstração de resultados\n", 227 | "petr = petr.income_statement().transpose() # Transpõe a matriz\n", 228 | "petr.columns = petr.iloc[0,:] # Renomeia colunas\n", 229 | "petr = petr.iloc[2:,:-1] # Seleciona dados\n", 230 | "petr = petr.iloc[:, ::-1] # Inverte colunas\n", 231 | "petr" 232 | ], 233 | "execution_count": 18, 234 | "outputs": [ 235 | { 236 | "output_type": "execute_result", 237 | "data": { 238 | "text/plain": "asOfDate 2019-12-31 2018-12-31 \\\nBasicAverageShares 1.30445e+10 1.30445e+10 \nBasicEPS 0.78 0.55 \nCostOfRevenue 4.5732e+10 6.1517e+10 \nDepreciationAmortizationDepletionIncomeStatement 1.58e+08 NaN \nDilutedAverageShares 1.30445e+10 1.30445e+10 \nDilutedEPS 0.78 0.55 \nDilutedNIAvailtoComStockholders 1.0151e+10 7.173e+09 \nEBIT 1.8687e+10 1.6304e+10 \nEBITDA NaN NaN \nEarningsFromEquityInterest 1.53e+08 5.23e+08 \nExciseTaxes NaN NaN \nGainOnSaleOfPPE 6.046e+09 4.19e+08 \nGainOnSaleOfSecurity -2.82e+09 -3.63e+09 \nGeneralAndAdministrativeExpense 5.682e+09 5.288e+09 \nGrossProfit 3.0857e+10 3.4067e+10 \nImpairmentOfCapitalAssets 2.848e+09 2.005e+09 \nInterestExpense 6.684e+09 4.206e+09 \nInterestExpenseNonOperating 6.684e+09 4.206e+09 \nInterestIncome 5e+06 5.63e+08 \nInterestIncomeNonOperating 5e+06 5.63e+08 \nMinorityInterests -2.12e+08 -2.41e+08 \nNetIncome 1.0151e+10 7.173e+09 \nNetIncomeCommonStockholders 1.0151e+10 7.173e+09 \nNetIncomeContinuousOperations 7.803e+09 7.414e+09 \nNetIncomeDiscontinuousOperations 2.56e+09 8.43e+08 \nNetIncomeFromContinuingAndDiscontinuedOperation 1.0151e+10 7.173e+09 \nNetIncomeFromContinuingOperationNetMinorityInte... 7.591e+09 7.173e+09 \nNetIncomeIncludingNoncontrollingInterests 1.0363e+10 7.414e+09 \nNetInterestIncome -6.314e+09 -2.636e+09 \nNetNonOperatingInterestIncomeExpense -6.314e+09 -2.636e+09 \nNormalizedEBITDA 3.3145e+10 3.5647e+10 \nNormalizedIncome 7.3453e+09 1.16571e+10 \nOperatingExpense 1.2355e+10 1.2541e+10 \nOperatingIncome 1.8502e+10 2.1526e+10 \nOperatingRevenue 7.6589e+10 9.5584e+10 \nOtherGandA 2.239e+09 2.678e+09 \nOtherIncomeExpense -1.85e+08 -6.792e+09 \nOtherNonOperatingIncomeExpenses -7.16e+08 -2.043e+09 \nOtherOperatingExpenses 8.44e+08 1.228e+09 \nOtherSpecialCharges 1.52e+09 2.04e+09 \nOtherTaxes 6.19e+08 7.52e+08 \nPretaxIncome 1.2003e+10 1.2098e+10 \nProvisionForDoubtfulAccounts NaN 0 \nReconciledCostOfRevenue 3.1054e+10 6.1517e+10 \nReconciledDepreciation 1.4836e+10 1.2028e+10 \nResearchAndDevelopment 5.76e+08 6.42e+08 \nSalariesAndWages 3.443e+09 2.61e+09 \nSellingAndMarketingExpense 4.476e+09 4.631e+09 \nSellingGeneralAndAdministration 1.0158e+10 9.919e+09 \nSpecialIncomeCharges 3.198e+09 -3.685e+09 \nTaxEffectOfUnusualItems 1.323e+08 -2.83090e+09 \nTaxProvision 4.2e+09 4.684e+09 \nTaxRateForCalcs 0.35 0.387 \nTotalExpenses 5.8087e+10 7.4058e+10 \nTotalOperatingIncomeAsReported 2.0614e+10 NaN \nTotalOtherFinanceCost -3.65e+08 -1.007e+09 \nTotalRevenue 7.6589e+10 9.5584e+10 \nTotalUnusualItems 3.78e+08 -7.315e+09 \nTotalUnusualItemsExcludingGoodwill 3.78e+08 -7.315e+09 \nWriteOff 6.046e+09 5.9e+07 \n\nasOfDate 2017-12-31 2016-12-31 \nBasicAverageShares 1.30445e+10 1.30445e+10 \nBasicEPS -0.01 -0.370884 \nCostOfRevenue 6.0147e+10 5.5417e+10 \nDepreciationAmortizationDepletionIncomeStatement NaN NaN \nDilutedAverageShares 1.30445e+10 1.30445e+10 \nDilutedEPS -0.01 -0.370884 \nDilutedNIAvailtoComStockholders -9.1e+07 -4.838e+09 \nEBIT 7.409e+09 2.37e+09 \nEBITDA NaN NaN \nEarningsFromEquityInterest 6.73e+08 -2.18e+08 \nExciseTaxes NaN 2.149e+10 \nGainOnSaleOfPPE 1.498e+09 2.93e+08 \nGainOnSaleOfSecurity -3.523e+09 -3.358e+09 \nGeneralAndAdministrativeExpense 5.074e+09 6.308e+09 \nGrossProfit 2.868e+10 2.5988e+10 \nImpairmentOfCapitalAssets 1.191e+09 6.193e+09 \nInterestExpense 5.412e+09 6.035e+09 \nInterestExpenseNonOperating 5.412e+09 6.035e+09 \nInterestIncome 6.04e+08 5.52e+08 \nInterestIncomeNonOperating 6.04e+08 5.52e+08 \nMinorityInterests -2.6e+08 -4.89e+08 \nNetIncome -9.1e+07 -4.838e+09 \nNetIncomeCommonStockholders -9.1e+07 -4.838e+09 \nNetIncomeContinuousOperations 1.69e+08 -4.349e+09 \nNetIncomeDiscontinuousOperations NaN NaN \nNetIncomeFromContinuingAndDiscontinuedOperation -9.1e+07 -4.838e+09 \nNetIncomeFromContinuingOperationNetMinorityInte... -9.1e+07 -4.838e+09 \nNetIncomeIncludingNoncontrollingInterests 1.69e+08 -4.349e+09 \nNetInterestIncome -6.192e+09 -5.854e+09 \nNetNonOperatingInterestIncomeExpense -6.192e+09 -5.854e+09 \nNormalizedEBITDA 2.5262e+10 2.7657e+10 \nNormalizedIncome 2.90936e+09 4.36679e+09 \nOperatingExpense 1.6618e+10 1.2259e+10 \nOperatingIncome 1.2062e+10 1.3729e+10 \nOperatingRevenue 8.8827e+10 1.02895e+11 \nOtherGandA 3.176e+09 3.572e+09 \nOtherIncomeExpense -3.873e+09 -1.154e+10 \nOtherNonOperatingIncomeExpenses NaN NaN \nOtherOperatingExpenses 4.591e+09 7.51e+08 \nOtherSpecialCharges 8.98e+08 1.393e+09 \nOtherTaxes 1.843e+09 7.14e+08 \nPretaxIncome 1.997e+09 -3.665e+09 \nProvisionForDoubtfulAccounts NaN NaN \nReconciledCostOfRevenue 6.0147e+10 5.5417e+10 \nReconciledDepreciation 1.3307e+10 1.3965e+10 \nResearchAndDevelopment 5.72e+08 5.23e+08 \nSalariesAndWages 1.898e+09 2.736e+09 \nSellingAndMarketingExpense 4.538e+09 3.963e+09 \nSellingGeneralAndAdministration 9.612e+09 1.0271e+10 \nSpecialIncomeCharges -1.023e+09 -7.964e+09 \nTaxEffectOfUnusualItems -1.54564e+09 -2.11721e+09 \nTaxProvision 1.828e+09 6.84e+08 \nTaxRateForCalcs 0.34 0.187 \nTotalExpenses 7.6765e+10 6.7676e+10 \nTotalOperatingIncomeAsReported NaN NaN \nTotalOtherFinanceCost 1.384e+09 3.71e+08 \nTotalRevenue 8.8827e+10 8.1405e+10 \nTotalUnusualItems -4.546e+09 -1.1322e+10 \nTotalUnusualItemsExcludingGoodwill -4.546e+09 -1.1322e+10 \nWriteOff 4.32e+08 6.71e+08 ", 239 | "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
asOfDate2019-12-312018-12-312017-12-312016-12-31
BasicAverageShares1.30445e+101.30445e+101.30445e+101.30445e+10
BasicEPS0.780.55-0.01-0.370884
CostOfRevenue4.5732e+106.1517e+106.0147e+105.5417e+10
DepreciationAmortizationDepletionIncomeStatement1.58e+08NaNNaNNaN
DilutedAverageShares1.30445e+101.30445e+101.30445e+101.30445e+10
DilutedEPS0.780.55-0.01-0.370884
DilutedNIAvailtoComStockholders1.0151e+107.173e+09-9.1e+07-4.838e+09
EBIT1.8687e+101.6304e+107.409e+092.37e+09
EBITDANaNNaNNaNNaN
EarningsFromEquityInterest1.53e+085.23e+086.73e+08-2.18e+08
ExciseTaxesNaNNaNNaN2.149e+10
GainOnSaleOfPPE6.046e+094.19e+081.498e+092.93e+08
GainOnSaleOfSecurity-2.82e+09-3.63e+09-3.523e+09-3.358e+09
GeneralAndAdministrativeExpense5.682e+095.288e+095.074e+096.308e+09
GrossProfit3.0857e+103.4067e+102.868e+102.5988e+10
ImpairmentOfCapitalAssets2.848e+092.005e+091.191e+096.193e+09
InterestExpense6.684e+094.206e+095.412e+096.035e+09
InterestExpenseNonOperating6.684e+094.206e+095.412e+096.035e+09
InterestIncome5e+065.63e+086.04e+085.52e+08
InterestIncomeNonOperating5e+065.63e+086.04e+085.52e+08
MinorityInterests-2.12e+08-2.41e+08-2.6e+08-4.89e+08
NetIncome1.0151e+107.173e+09-9.1e+07-4.838e+09
NetIncomeCommonStockholders1.0151e+107.173e+09-9.1e+07-4.838e+09
NetIncomeContinuousOperations7.803e+097.414e+091.69e+08-4.349e+09
NetIncomeDiscontinuousOperations2.56e+098.43e+08NaNNaN
NetIncomeFromContinuingAndDiscontinuedOperation1.0151e+107.173e+09-9.1e+07-4.838e+09
NetIncomeFromContinuingOperationNetMinorityInterest7.591e+097.173e+09-9.1e+07-4.838e+09
NetIncomeIncludingNoncontrollingInterests1.0363e+107.414e+091.69e+08-4.349e+09
NetInterestIncome-6.314e+09-2.636e+09-6.192e+09-5.854e+09
NetNonOperatingInterestIncomeExpense-6.314e+09-2.636e+09-6.192e+09-5.854e+09
NormalizedEBITDA3.3145e+103.5647e+102.5262e+102.7657e+10
NormalizedIncome7.3453e+091.16571e+102.90936e+094.36679e+09
OperatingExpense1.2355e+101.2541e+101.6618e+101.2259e+10
OperatingIncome1.8502e+102.1526e+101.2062e+101.3729e+10
OperatingRevenue7.6589e+109.5584e+108.8827e+101.02895e+11
OtherGandA2.239e+092.678e+093.176e+093.572e+09
OtherIncomeExpense-1.85e+08-6.792e+09-3.873e+09-1.154e+10
OtherNonOperatingIncomeExpenses-7.16e+08-2.043e+09NaNNaN
OtherOperatingExpenses8.44e+081.228e+094.591e+097.51e+08
OtherSpecialCharges1.52e+092.04e+098.98e+081.393e+09
OtherTaxes6.19e+087.52e+081.843e+097.14e+08
PretaxIncome1.2003e+101.2098e+101.997e+09-3.665e+09
ProvisionForDoubtfulAccountsNaN0NaNNaN
ReconciledCostOfRevenue3.1054e+106.1517e+106.0147e+105.5417e+10
ReconciledDepreciation1.4836e+101.2028e+101.3307e+101.3965e+10
ResearchAndDevelopment5.76e+086.42e+085.72e+085.23e+08
SalariesAndWages3.443e+092.61e+091.898e+092.736e+09
SellingAndMarketingExpense4.476e+094.631e+094.538e+093.963e+09
SellingGeneralAndAdministration1.0158e+109.919e+099.612e+091.0271e+10
SpecialIncomeCharges3.198e+09-3.685e+09-1.023e+09-7.964e+09
TaxEffectOfUnusualItems1.323e+08-2.83090e+09-1.54564e+09-2.11721e+09
TaxProvision4.2e+094.684e+091.828e+096.84e+08
TaxRateForCalcs0.350.3870.340.187
TotalExpenses5.8087e+107.4058e+107.6765e+106.7676e+10
TotalOperatingIncomeAsReported2.0614e+10NaNNaNNaN
TotalOtherFinanceCost-3.65e+08-1.007e+091.384e+093.71e+08
TotalRevenue7.6589e+109.5584e+108.8827e+108.1405e+10
TotalUnusualItems3.78e+08-7.315e+09-4.546e+09-1.1322e+10
TotalUnusualItemsExcludingGoodwill3.78e+08-7.315e+09-4.546e+09-1.1322e+10
WriteOff6.046e+095.9e+074.32e+086.71e+08
\n
" 240 | }, 241 | "metadata": {}, 242 | "execution_count": 18 243 | } 244 | ] 245 | } 246 | ], 247 | "metadata": { 248 | "colab": { 249 | "name": "Como extrair dados de ações da Bovespa sem gastar nada com Python.ipynb", 250 | "provenance": [] 251 | }, 252 | "kernelspec": { 253 | "name": "python3", 254 | "display_name": "Python 3" 255 | } 256 | }, 257 | "nbformat": 4, 258 | "nbformat_minor": 0 259 | } 260 | --------------------------------------------------------------------------------