Skip to main content

HedgingGym is a reinforcement learning environment for training and testing hedging strategies.

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hedging_gym-0.0.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

hedging_gym-0.0.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file hedging_gym-0.0.1.tar.gz.

File metadata

  • Download URL: hedging_gym-0.0.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for hedging_gym-0.0.1.tar.gz
Algorithm Hash digest
SHA256 237bef47d0e23f2d491ca6d4a721f9f53e05b0cb47ba9053179dda22bdd4ce29
MD5 7f0cbef66098c40d74974b23a4fe7e2a
BLAKE2b-256 d48bb20f62901e4263946df3cc05487154cf21b66a3a7fcda80b8dec5d1109f8

See more details on using hashes here.

File details

Details for the file hedging_gym-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hedging_gym-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for hedging_gym-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6059825e084da620c58fa5fb931b96316dd369e6330596e09d293bf0c5a8878
MD5 54a75f8e81cc341bdc913b7aaeaaa2b6
BLAKE2b-256 4ad75f8fd9533c9b348b244361c43ea688af7757db54ca80b36d8f4f52e2168c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page