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
where the profit and loss function is defined as
where
Hereby,
- 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.
To install Hedging Gym, run the following command:
pip install hedging-gym
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)