folder_name = r"results\experiment-4" # ============================================================================== # === train gradient models rate = 0.02 drift = 0.05 number_of_tests = 2**7 test_drivers = [] for num in range(number_of_tests): print(f"dimension {dimension} at test {num + 1} ".ljust(80, "="), end="") start = perf_counter() volatility = tf.random.uniform((dimension, ), 0.2, 0.3) init_instruments, init_numeraire, book = random_books.random_empty_book( 13 / 52, dimension, rate, drift, volatility, num) # random_books.add_butterfly(init_instruments, book, spread=20) random_books.add_calls(init_instruments, book) warmup_driver = gradient_driver.GradientDriver( timesteps=timesteps, frequency=0, init_instruments=init_instruments, init_numeraire=init_numeraire, book=book, learning_rate_min=1e-7, learning_rate_max=1e-2) warmup_driver.set_exploration(100.0, 15.0) warmup_driver.add_testcase(name="value network",
import sys import os from time import perf_counter import utils import derivatives import random_books import gradient_models import gradient_driver import hedge_models tf.get_logger().setLevel('ERROR') timesteps = 13 init_instruments, init_numeraire, book = random_books.random_empty_book( timesteps / 52, 1, 0.02, 0.05, 0.2) init_numeraire = tf.ones_like(init_numeraire) spread = 10 itm = derivatives.PutCall(book.maturity, init_instruments - spread / 2, book.instrument_simulator.rate, book.instrument_simulator.volatility, 1) atm = derivatives.PutCall(book.maturity, init_instruments, book.instrument_simulator.rate, book.instrument_simulator.volatility, 1) otm = derivatives.PutCall(book.maturity, init_instruments + spread / 2, book.instrument_simulator.rate, book.instrument_simulator.volatility, 1) book.add_derivative(itm, 0, 1) book.add_derivative(atm, 0, -2)
volatility = 0.2 train_size, test_size, timesteps = int(2**18), int(2**18), 14 alpha = 0.95 dimension = 1 frequency = 4 units = 15 layers = 4 activation = tf.keras.activations.softplus num_trials = 8 lst_of_drivers = [] risk_measure = partial(hedge_models.ExpectedShortfall, alpha=alpha) init_instruments, init_numeraire, book = random_books.random_empty_book( timesteps / 250, dimension, rate, drift, volatility, 69) random_books.add_rko(init_instruments, book, 5) driver = utils.HedgeDriver(timesteps=timesteps, frequency=frequency, init_instruments=init_instruments, init_numeraire=init_numeraire, book=book, cost=1 / 100 if cost else None, risk_neutral=not cost, learning_rate=1e-1) driver.add_testcase("deep network", hedge_models.NeuralHedge( timesteps=timesteps, instrument_dim=book.instrument_dim,
import hedge_models import sys # ============================================================================== # === hyperparameters train_size, test_size, timesteps = int(2**2), int(2**14), 7 hedge_multiplier = 5 * int(sys.argv[1]) frequency = 0 # only > 0 for continuous, else 0 alpha = 0.95 folder_name = r"figures\delta-pnl-plots" case_name = "call" # ============================================================================== # === sample data init_instruments, init_numeraire, book = random_books.random_empty_book( timesteps / 250, 1, 0.0, 0.05, 0.2, seed=69) # NOTE timesteps / 52 for DGA # random_books.add_calls(init_instruments, book) random_books.add_butterfly(init_instruments, book, 10) # random_books.add_dga_calls(init_instruments, book) # random_books.add_rko(init_instruments, book, 10.0) driver = utils.HedgeDriver(timesteps=timesteps * hedge_multiplier, frequency=frequency, init_instruments=init_instruments, init_numeraire=init_numeraire, book=book, cost=None, risk_neutral=True, learning_rate=1e-1)
# -*- coding: utf-8 -*- import tensorflow as tf import random_books import utils import hedge_models import derivatives # ============================================================================== # === hyperparameters train_size, test_size, timesteps = int(2**10), int(2**20), 30 alpha = 0.95 # ============================================================================== # === sample data init_instruments, init_numeraire, book = random_books.random_empty_book( 1.0, 1, 0.05, 0.1, 0.2, seed=69) derivative = derivatives.PutCall(book.maturity, 105.0, book.numeraire_simulator.rate, book.instrument_simulator.volatility, 1) book.add_derivative(derivative, 0, 1.0) driver = utils.HedgeDriver( timesteps=timesteps, frequency=0, # no need for frequency init_instruments=init_instruments, init_numeraire=init_numeraire, book=book, cost=None, risk_neutral=False, learning_rate=1e-1)