IPCA Data
indexes(start, end)
Retrieves the IPCA index values for a specified date range.
Makes an API call to the IBGE's data portal using the format: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/YYYYMM-YYYYMM/variaveis/2266?localidades=N1[all]
Example: For the date range "01-01-2024" to "31-03-2024", the API URL will be: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/202401-202403/variaveis/2266?localidades=N1[all]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
DateScalar
|
The start date of the date range |
required |
end
|
DateScalar
|
The end date of the date range |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns 'Period' and 'Value' |
Examples:
>>> from pyield import ipca
>>> # Get the IPCA indexes for the first quarter of 2025
>>> ipca.indexes(start="01-01-2025", end="01-03-2025")
shape: (3, 2)
┌────────┬─────────┐
│ Period ┆ Value │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞════════╪═════════╡
│ 202501 ┆ 7111.86 │
│ 202502 ┆ 7205.03 │
│ 202503 ┆ 7245.38 │
└────────┴─────────┘
Source code in pyield/ipca/historical.py
last_indexes(num_months=1)
Retrieves the last IPCA index values for a specified number of months.
Makes an API call to the IBGE's data portal using the format: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-N/variaveis/2266?localidades=N1[all]
Example: For the last 2 months, the API URL will be: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-2/variaveis/2266?localidades=N1[all]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_months
|
int
|
Number of months to retrieve. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns 'Period' and 'Value' |
Examples:
>>> from pyield import ipca
>>> # Get the last month's IPCA index
>>> df = ipca.last_indexes(1)
>>> # Get the last 3 months' IPCA indexes
>>> df = ipca.last_indexes(3)
Source code in pyield/ipca/historical.py
last_rates(num_months=1)
Retrieves the last IPCA monthly rates for a specified number of months.
Makes an API call to the IBGE's data portal using the format: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-N/variaveis/63?localidades=N1[all]
Example: For the last 2 months, the API URL will be: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-2/variaveis/63?localidades=N1[all]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_months
|
int
|
Number of months to retrieve. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns 'Period' and 'Value' |
Raises:
| Type | Description |
|---|---|
ValueError
|
If num_months is 0 |
Examples:
>>> from pyield import ipca
>>> # Get the last month's IPCA rate
>>> df = ipca.last_rates(1)
>>> # Get the last 3 months' IPCA rates
>>> df = ipca.last_rates(3)
Source code in pyield/ipca/historical.py
projected_rate()
Retrieves the current IPCA projection from the ANBIMA website.
This function makes an HTTP request to the ANBIMA website, extracts HTML tables containing economic indicators, and specifically processes the IPCA projection data.
Process
- Accesses the ANBIMA indicators webpage
- Extracts the third table that contains the IPCA projection
- Locates the row labeled as "IPCA1"
- Extracts the projection value and converts it to decimal format
- Extracts and formats the reference month of the projection
- Extracts the date and time of the last update
Returns:
| Name | Type | Description |
|---|---|---|
IndicatorProjection |
IndicatorProjection
|
An object containing: - last_updated (dt.datetime): Date and time of the last data update - reference_period (str): Reference period of the projection as a string in "MMM/YY" brazilian format (e.g., "set/25") - projected_value (float): Projected IPCA value as a decimal number |
Raises:
| Type | Description |
|---|---|
RequestException
|
If there are connection issues with the ANBIMA site |
ValueError
|
If the expected data is not found in the page structure |
Example
from pyield import ipca
Retrieve the current IPCA projection from ANBIMA
ipca.projected_rate() IndicatorProjection(last_updated=..., reference_period=..., projected_value=...)
Notes
- The function requires internet connection to access the ANBIMA website
- The structure of the ANBIMA page may change, which could affect the function
Source code in pyield/ipca/projected.py
rates(start, end)
Retrieves the IPCA monthly rates for a specified date range.
Makes an API call to the IBGE's data portal using the format: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/YYYYMM-YYYYMM/variaveis/63?localidades=N1[all]
Example: For the date range "01-01-2024" to "31-03-2024", the API URL will be: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/202401-202403/variaveis/63?localidades=N1[all]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
DateScalar
|
The start date of the date range |
required |
end
|
DateScalar
|
The end date of the date range |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns 'Period' and 'Rate' |
Examples:
>>> from pyield import ipca
>>> # Get the IPCA rates for the first quarter of 2025
>>> ipca.rates("01-01-2025", "01-03-2025")
shape: (3, 2)
┌────────┬────────┐
│ Period ┆ Value │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞════════╪════════╡
│ 202501 ┆ 0.0016 │
│ 202502 ┆ 0.0131 │
│ 202503 ┆ 0.0056 │
└────────┴────────┘