Window Change by Year
Calculate the change of every series over the same months of every year, such as February to October, with the rank of every year’s change and the last earlier year with a change at least as large (“the largest since”).
Where get_level_significance measures one window, from the start date to the latest value, this compares the same window across years: “US consumer prices rose 3.3% from February to October, the most since 2022” is the Change, Rank and Largest Since of the latest year. Through the Toolkit it measures the prices of the tickers (a seasonal pattern, such as the return from May to October); with Econometrics(data=...) any series, such as the consumer price indices of Economics.
The formula is as follows:
\[\text{Change} (y) = (x(\text{to\_month},\; y) - x(\text{from\_month},\; y)) / | x(\text{from\_month},\; y) |\] \[\text{Rank} (y) = \text{the position of Change} (y) \text{among the changes of every year},\;\; \text{1 for the largest}\] \[\text{Largest Since} (y) = \text{the last year}\; s < y \;\text{with Change} (s) \geq \text{Change} (y)\]Where x(m, y) is the value of month m in year y, the last value of the month for a daily series. A window that ends in an earlier month than it starts (November to February) runs into the next year and is labelled by the year it ends; the same month for both gives the change over twelve months. A year without the value of either month has no change, so the current year is empty until its last month is published. Largest Since is NaN when no earlier year had a change as large. With Econometrics(data=..., changes="difference") the Change is x(to_month, y) - x(from_month, y), in percentage points for a rate.
Also known as: same period each year, seasonal change, year-to-date comparison, change from February to October, largest since, fastest since, seasonality.
Window Change by Year in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_window_change_by_year as shown below.
from financetoolkit import Economics, Econometrics
economics = Economics(start_date='2019-01-01', end_date='2026-10-31')
consumer_price_index = economics.get_consumer_price_index(
countries=['United States', 'Euro Area']
)
econometrics = Econometrics(data=consumer_price_index)
econometrics.get_window_change_by_year(from_month=2, to_month=10)['United States']
Or, after setting up the Finance Toolkit MCP, ask:
How much did US consumer prices rise from February to October in each year from 2019 to 2026, and how does each year rank?
Which returns:
| Year | Start Value | End Value | Change | Rank | Largest Since |
|---|---|---|---|---|---|
| 2019 | 115.923 | 118.019 | 0.0181 | 5 | nan |
| 2020 | 118.629 | 119.414 | 0.0066 | 7 | 2019 |
| 2021 | 120.618 | 126.843 | 0.0516 | 1 | nan |
| 2022 | 130.112 | 136.668 | 0.0504 | 2 | 2021 |
| 2023 | 137.965 | 141.098 | 0.0227 | 4 | 2022 |
| 2024 | 142.315 | 144.763 | 0.0172 | 6 | 2023 |
| 2025 | 146.331 | nan | nan | nan | nan |
| 2026 | 149.863 | 154.782 | 0.0328 | 3 | 2022 |
Using Your Own Data
get_window_change_by_year runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_window_change_by_year()
Parameters
get_window_change_by_year accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
from_month | int | The month the window starts, 1 (January) to 12 (December). Defaults to 1. | 1 |
to_month | int | The month the window ends, 1 to 12. Defaults to 12, which with from_month=1 is the change from January to December. | 12, which with from_month=1 is the change from January to December |
column | str | The historical data column to measure. Defaults to “Close”, the traded close of the tickers and the series themselves with data=. | "Return" |
spread_over | str | None | The name of a series to subtract from every other series, so the spreads over it are measured instead. Defaults to None. | None |
ratio | bool | Whether to divide every other series by the spread_over series instead of subtracting it (named “ | False |
include_benchmark | bool | Whether to include “Benchmark” among the assets. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the class (4 unless set otherwise). | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |