Gross Leverage

Calculate the gross leverage of the portfolio, the value of its long and short positions together as a multiple of its net value:

\[\text{Gross Leverage} = \frac{\sum\left|\text{value of every position}\right|}{\sum \;\text{value of every position}}\]

A portfolio of long positions has a gross leverage of 1; short positions raise it, e.g. to 1.6 for a 130/30 portfolio. Over weeks, months, quarters or years the values at the end of the period are shown. The measure is defined in pyfolio (Quantopian).

Also known as: gross exposure, leverage ratio.

Example

Install the Finance Toolkit with pip install financetoolkit -U, then call get_gross_leverage:

from financetoolkit import Portfolio

portfolio = Portfolio(example=True, api_key="FINANCIAL_MODELING_PREP_KEY")

portfolio.get_gross_leverage(period="yearly")

Which returns:

DateGross ValueNet ValueGross Leverage
20002,392.282,392.281
20014,798.284,798.281
20025,422.305,422.301
20038,204.568,204.561
200410,365.3010,365.301
200513,539.3013,539.301
200616,209.0016,209.001
200719,071.4019,071.401
200812,108.2012,108.201
200920,985.5020,985.501
201025,801.1025,801.101
201126,933.1026,933.101
201234,851.3034,851.301
201349,217.5049,217.501
201454,772.7054,772.701
201561,747.1061,747.101
201678,378.2078,378.201
2017117,708.00117,708.001
2018125,233.00125,233.001
2019206,431.00206,431.001
2020328,089.00328,089.001
2021435,818.00435,818.001
2022337,393.00337,393.001
2023547,989.00547,989.001
2024739,785.00739,785.001
2025908,218.00908,218.001
2026892,993.00892,993.001

27 rows

Parameters

get_gross_leverage accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period whose last values are shown. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”."weekly"
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Portfolio’s rounding.2
show_columnsstr | list[str] | NoneThe 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

References

  • Library Shares similar logic as pyfolio’s gross_lev
Share