Calculate the Gain-to-Pain Ratio of an investment portfolio or asset’s returns.

The Gain-to-Pain Ratio, popularized by Jack Schwager, divides the sum of all returns by the sum of the absolute value of all losses, summarizing the entire return history into a single measure of return earned per unit of pain endured.

The formula is as follows:

\[\text{Gain-to-Pain Ratio} = \operatorname{SUM}(\text{Returns}) / \operatorname{SUM}(| \text{Losses} |)\]

Gain-to-Pain Ratio in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_gain_to_pain_ratio as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["GCUSD", "SIUSD", "HGUSD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.performance.get_gain_to_pain_ratio()

Or, after setting up the Finance Toolkit MCP, ask:

What was the gain-to-pain ratio of gold, silver and copper in each year from 2021 to 2025?

Which returns:

  GCUSD SIUSD HGUSD
2021 -0.0617 -0.0653 0.1797
2022 0.0115 0.0413 -0.0663
2023 0.1812 0.0233 0.0337
2024 0.3038 0.1403 0.0446
2025 0.5152 0.5701 0.2573

Parameters

get_gain_to_pain_ratio accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."quarterly"
within_periodboolWhether to calculate the Gain-to-Pain Ratio within the specified period or for the entire period. Thus whether to look at the Gain-to-Pain Ratio within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to True.False
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the ratios. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
Share