Exemplo n.º 1
0
    derivative = BachelierBinary(maturity, strike, sigma)
numeraire_simulator = simulators.ConstantBankAccount(0.0)

book = books.DerivativeBook(maturity, instrument_simulator,
                            numeraire_simulator)

book.add_derivative(derivative, 0, 1.0)

init_instruments = tf.constant([spot], FLOAT_DTYPE)
init_numeraire = tf.constant([1.0], FLOAT_DTYPE)

driver = utils.HedgeDriver(
    timesteps=timesteps,
    frequency=0,  # no need for frequency for non-path dependent derivatives.
    init_instruments=init_instruments,
    init_numeraire=init_numeraire,
    book=book,
    cost=1 / 100 if cost else None,
    risk_neutral=True,
    learning_rate=1e-1)
driver.verbose = 2

risklevels = [0.05, 0.5, 0.95] if not cost else [0.95]
for alpha in risklevels:
    driver.add_testcase(f"deep network {alpha}",
                        hedge_models.NeuralHedge(
                            timesteps=timesteps,
                            instrument_dim=book.instrument_dim,
                            internal_dim=0,
                            num_layers=4,
                            num_units=5,
Exemplo n.º 2
0
    risk_measure = partial(hedge_models.MeanVariance, aversion=1.0)
else:
    risk_measure = partial(hedge_models.ExpectedShortfall, alpha=alpha)

for num in range(num_trials):
    print(f"dimension {dimension} at test {num + 1} ".ljust(80, "="), end="")
    start = perf_counter()

    init_instruments, init_numeraire, book = random_books.random_empty_book(
        timesteps / 250, dimension, rate, drift, volatility, num)
    random_books.add_rko(init_instruments, book, spread)

    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(name="continuous-time",
                        model=hedge_models.FeatureHedge(),
                        risk_measure=risk_measure(),
                        normaliser=None,
                        feature_function="delta",
                        price_type="arbitrage")

    driver.add_testcase("deep network",
                        hedge_models.NeuralHedge(
                            timesteps=timesteps,
                            instrument_dim=book.instrument_dim,
Exemplo n.º 3
0
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)

driver.add_testcase(case_name,
                    hedge_models.FeatureHedge(),
                    risk_measure=hedge_models.ExpectedShortfall(alpha),
                    normaliser=None,
                    feature_function="delta",
                    price_type="arbitrage")

driver.train(sample_size=train_size, epochs=0, batch_size=2**2)
driver.test(test_size)

print(
Exemplo n.º 4
0
    risk_measure = partial(hedge_models.ExpectedShortfall, alpha=alpha)


for num in range(num_trials):
    print(f"dimension {dimension} at test {num + 1} ".ljust(80, "="), end="")
    start = perf_counter()

    init_instruments, init_numeraire, book = random_books.random_empty_book(
        timesteps / 12, dimension, rate, drift, volatility, num)
    random_books.add_dga_calls(init_instruments, book)

    driver = utils.HedgeDriver(
        timesteps=timesteps * hedge_multiplier,
        frequency=0, # no need for 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(
        name="continuous-time",
        model=hedge_models.FeatureHedge(),
        risk_measure=risk_measure(),
        normaliser=None,
        feature_function="delta",
        price_type="arbitrage")

    driver.add_testcase(
        "deep network",
Exemplo n.º 5
0
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)

driver.add_testcase("delta",
                    hedge_models.FeatureHedge(),
                    risk_measure=hedge_models.ExpectedShortfall(alpha),
                    normaliser=None,
                    feature_function="delta",
                    price_type="arbitrage")

driver.train(train_size, 1, int(2**10))
driver.test(test_size)