Price to Earnings Ratio (PE)
Calculate the price earnings ratio (P/E), a valuation ratio that compares a company’s stock price to its earnings per share.
The price earnings ratio is a widely used valuation metric that helps investors assess the relative value of a company’s stock. A higher P/E ratio may indicate that the market has high expectations for the company’s future growth, while a lower P/E ratio may suggest that the company is undervalued.
The formula is as follows:
\[\text{Price to Earnings Ratio} (P / E) = \text{Share Price} / \text{Earnings per Share} (\text{EPS})\]The P/E is compared with the company’s own history, its peers and the market, and is read together with growth: a high P/E is the market paying for expected growth. For cyclical companies it is misleading at the extremes, lowest at peak earnings and highest in a downturn, so analysts often use normalized or forward earnings (get_forward_price_earnings_ratio). A negative or tiny EPS gives a negative or extreme P/E that should be left out of averages.
Also known as: PE ratio, P/E ratio, price-earnings ratio, earnings multiple.
Price to Earnings Ratio (PE) in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_price_to_earnings_ratio as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["COST", "WMT", "TGT"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.ratios.get_price_to_earnings_ratio()
Or, after setting up the Finance Toolkit MCP, ask:
How did the price-to-earnings ratios of Costco, Walmart and Target compare from 2021 to 2025?
Which returns:
| 2021 | 2022 | 2023 | 2024 | 2025 | |
|---|---|---|---|---|---|
| COST | 50.3805 | 34.7419 | 46.6265 | 55.3169 | 47.3603 |
| TGT | 16.4167 | 24.9133 | 15.9285 | 15.2594 | nan |
| WMT | 29.683 | 33.1872 | 27.4726 | 37.5653 | nan |
Parameters
get_price_to_earnings_ratio accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
show_daily | bool | Whether to show daily values: the close of each trading day against the statement figures of the latest period that has ended on or before that day (also when it ended before the start date), so no figures are used before their period closes. Defaults to False. | True |
include_dividends | bool | Whether to deduct preferred dividends from net income. Defaults to False. | True |
diluted | bool | Whether to use diluted shares in the calculation. Defaults to True. | False |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the ratios. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
compound | bool | Whether the growth is the compound annual growth rate over the lag (e.g. lag=5 for the five-year CAGR) instead of the total change. Defaults to False. | False |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
trailing | int | The number of periods to sum flows (income and cash flow statement items) over, with balance sheet items averaged over the same number of period ends. E.g. 4 with quarterly data gives the trailing twelve months (TTM) and 3 with annual data a three-year cumulative figure. Defaults to None, which uses the trailing twelve months (4 quarters) with quarterly data and single years with annual data. | 4 |