Skip to main content

Hedging Gym

Hedging Gym is a reinforcement learning environment for training and testing hedging strategies. It is built on top of OpenAI's Gym framework and is designed to simulate real-world financial markets.

The hedging environment specifics are based on the following paper: Delta hedging with Deep Reinforcement Learning by Giurca and Borovkova (2021).

The rewards function is defined as

r_t(s_t, a_t) = PL_t(s_t, a_t) - \frac{\lambda}{2} PL_t(s_t, a_t)^2

where the profit and loss function is defined as

PL_t(s_t, a_t) = \delta V_t + \Delta (\delta S_t) - c(\delta \Delta_t)

where $V_t$ is the option value, $S_t$ is the stock price, $\Delta$ is the delta used to hedged the position, and $c$ is the cost function that represents the transaction costs for the underlying between $t - 1$ and $t$. The cost function is defined as

c(\delta \Delta_t) = \xi \times \textit{Ticksize} \times (\delta \Delta_t + 0.01(\delta \Delta)^2)

Hereby, $\xi \in \mathbb{R}^{+}$ is the level of market friction, $\textit{Ticksize}\times\left(\left|\delta \Delta_{t}\right|\right)$ is a cost relative to the midpoint of crossing a two ticks wide bid-ask spread (for $\xi=1$ ) and $\xi \times \textit{Ticksize} \times 0.01\left(\delta \Delta_{t}\right)^{2}$ is a simplified version of market impact.

Features

  • Simulates Black-Scholes environment for call option hedging, supports both discrete and continuous action spaces.
  • Simulates Heston environment for option hedging, for both discrete and continuous action spaces.
  • Simulates Exchange option environment (Margrabe Environment) for option hedging, for only in continuous action spaces.

Installation

To install Hedging Gym, run the following command:

pip install hedging-gym

Usage

Here is an example of how to create a Hedging Gym environment:

import gymnasium

# Initialize the environment
env = gymnasium.make(
        "CallHedgingBSCont-v0",
        s0=s0,
        strike=strike,
        expiry=expiry,
        r=r,
        mu=mu,
        sigma=sigma,
        n_steps=n_steps,
    )

# Reset the environment
obs, info = env.reset(seed=SEED)

# Take a step
action = np.array([bs_delta_0], dtype=np.float32)
obs, reward, done, info = env.step(action)

Release files for hedging-gym 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hedging-gym 0.0.2
File Size Uploaded
hedging_gym-0.0.2.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hedging-gym 0.0.2
File Interpreter ABI Platform
hedging_gym-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 34.7 kB

Release files / hedging_gym-0.0.2.tar.gz

Download URL hedging_gym-0.0.2.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4c38ca17b4c9e360e45420f41d2d0dd8c97b100c70545c11a4a8132eb249805c
BLAKE2b-256 checksum
How to use checksums
bd03a1d2cd91d25c63441bbfa83c28aa2100f29756d878b01fb77d6bd3ed3eb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.6

Release files / hedging_gym-0.0.2-py3-none-any.whl

Download URL hedging_gym-0.0.2-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5cdd9823d1d638b0c294666772da3392295bda93cdf237da5e532f129c04587
BLAKE2b-256 checksum
How to use checksums
ff5f6ebe1532c8fe69b6c4253c107fbffd76d14c283d4fa91647054b154a3999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page