예제 #1
0
    def test_basic(self, dataloader_dummy, network_dummy):
        weights_table = generate_weights_table(network_dummy, dataloader_dummy)

        assert isinstance(weights_table, pd.DataFrame)
        assert len(weights_table) == len(dataloader_dummy.dataset)
        assert set(weights_table.index.to_list()) == set(dataloader_dummy.dataset.timestamps)
        assert weights_table.columns.to_list() == dataloader_dummy.dataset.asset_names
예제 #2
0
    def test_errors(self, dataloader_dummy, network_dummy):
        with pytest.raises(TypeError):
            generate_weights_table('FAKE', dataloader_dummy)

        with pytest.raises(TypeError):
            generate_weights_table(network_dummy, 'FAKE')
예제 #3
0
# Let us now use the above created objects. We first generate a table with all metrics over all
# samples and for all benchmarks. This is done via :code:`generate_metrics_table`.
metrics_table = generate_metrics_table(benchmarks, dataloader_test, metrics)

# %%
# And then we plot it with :code:`plot_metrics`.
plot_metrics(metrics_table)

# %%
# Each plot represents a different metric. The x-axis represents the timestamps in our
# test set. The different colors are capturing different models. How is the value of a metric
# computed? We assume that the investor predicts the portfolio at time x and buys it. He then
# holds it for :code:`horizon` timesteps. The actual metric is then computed over this time horizon.

# %%
# Finally, we are also interested in how the allocation/prediction looks like at each time step.
# We can use the :code:`generate_weights_table` function to create a :code:`pd.DataFrame`.
weight_table = generate_weights_table(network, dataloader_test)

# %%
# We then call the :code:`plot_weight_heatmap` to see a heatmap of weights.
plot_weight_heatmap(weight_table,
                    add_sum_column=True,
                    time_format=None,
                    time_skips=25)

# %%
# The rows represent different timesteps in our test set. The columns are all the assets in our
# universe. The values represent the weight in the portfolio. Additionally, we add a sum column
# to show that we are really generating valid allocations.