Real-time risk management
It's time to use what you've learned about neural networks to perform (almost!) real-time risk management.
A 14-day rolling window of asset returns provides enough data to create a time series of minimum volatility portfolios using Modern Portfolio Theory, as you saw in Chapter 2. These minimum_vol
portfolio weights are the training values for a neural network. This is a (1497 x 4) matrix.
The input is the matrix of weekly average_asset_returns
, corresponding to each efficient portfolio. This is a (1497 x 4) matrix.
Create a Sequential neural network with the proper input dimension and two hidden layers. Training this network would take too long, so you'll use an available pre_trained_model
of identical type to predict portfolio weights for a new asset price vector.
This exercise is part of the course
Quantitative Risk Management in Python
Exercise instructions
- Create a Sequential neural network with two hidden layers, one input layer and one output layer.
- Use the
pre_trained_model
to predict what the minimum volatility portfolio would be, when new asset dataasset_returns
is presented.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create neural network model
model = ____()
model.add(Dense(128, input_dim = ____, activation = 'relu'))
model.____(____(64, activation = 'relu'))
model.____(____(____, activation = 'relu'))
# Use the pre-trained model to predict portfolio weights given new asset returns
asset_returns = np.array([0.001060, 0.003832, 0.000726, -0.002787])
asset_returns.shape = (1,4)
print("Predicted minimum volatility portfolio: ", pre_trained_model.____(asset_returns))