コード例 #1
0
    def test_degenerate_col(self):
        batch, height, width, degenerate = 6, 7, 8, 4
        x = get_degenerate_sample(batch, height, width, degenerate, 69)
        inputs = [x[..., 0] for x in tf.split(x, width, axis=-1)]

        normaliser = preprocessing.MeanVarianceNormaliser()
        outputs = normaliser.fit_transform(inputs)

        for step, op in enumerate(outputs):
            assert_near(tf.reduce_mean(op, 0), 0.)

            expected_var = 0. if step == degenerate else 1.
            assert_near(tf.math.reduce_variance(op, 0), expected_var)

        assert_near(normaliser.inverse_transform(outputs), inputs)
コード例 #2
0
    def test_low_variance(self):
        batch, height, width = 2**20, 3, 2
        x = get_low_variance_sample(batch, height, width, 69)
        inputs = [x[..., 0] for x in tf.split(x, width, axis=-1)]

        normaliser = preprocessing.MeanVarianceNormaliser()
        outputs = normaliser.fit_transform(inputs)

        for op in outputs:
            tf.debugging.assert_type(op, FLOAT_DTYPE)

            # test with FLOAT_DTYPE
            mean, variance = tf.nn.moments(op, 0)
            assert_near(mean, 0.)
            assert_near(variance, 1., atol=1e-2)

            # test with tf.float64
            mean, variance = tf.nn.moments(tf.cast(op, tf.float64), 0)
            assert_near(mean, 0., atol=1e-8)
            assert_near(variance, 1., atol=1e-8)

        assert_near(normaliser.inverse_transform(outputs), inputs)
コード例 #3
0
    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,
                            activation=tf.keras.activations.softplus),
                        risk_measure=hedge_models.ExpectedShortfall(alpha),
                        normaliser=preprocessing.MeanVarianceNormaliser(),
                        feature_function="log_martingale",
                        price_type="arbitrage")

if driver.cost is not None or not driver.risk_neutral:
    driver.add_liability_free(
        hedge_models.LinearFeatureHedge(
            timesteps=timesteps,
            instrument_dim=book.instrument_dim,
            mappings=[approximators.IdentityFeatureMap] \
                * (1 + (driver.cost is not None))),
        risk_measure=hedge_models.ExpectedShortfall(alpha),
        normaliser=preprocessing.MeanVarianceNormaliser(),
        feature_function="log_martingale")

train_size, test_size = int(2**18), int(2**18)