```\ndef _calculate_leverage(\n    _position_value: uint256, _debt_value: uint256, _margin_value: uint256\n) -> uint256:\n    if _position_value <= _debt_value:\n        # bad debt\n        return max_value(uint256)\n\n\n    return (\n        PRECISION\n        * (_debt_value + _margin_value)\n        / (_position_value - _debt_value)\n        / PRECISION\n    )\n```\n