Neural network risk management

Quantitative Risk Management in Python

Jamsheed Shorish

Computational Economist

Real-time portfolio updating

  • Risk management
    • Defined risk measures (VaR, CVaR)
    • Estimated risk measures (parameteric, historical, Monte Carlo)
    • Optimized portfolio (e.g. Modern Portfolio Theory)
  • New market information => update portfolio weights
    • Problem: portfolio optimization costly
    • Solution: $\text{weights} = f(\text{prices})$
    • Evaluate $f$ in real-time
    • Update $f$ only occasionally
Quantitative Risk Management in Python

Neural networks

  • Neural Network: $\text{output} = f(\text{input})$
    • Neuron: interconnected processing node in function
  • Initially developed 1940s-1950s
  • Early 2000s: application of neural networks to "big data"
    • Image recognition, processing
    • Financial data
    • Search engine data
  • Deep Learning: neural networks as part of Machine Learning
    • 2015: Google releases open-source Tensorflow deep learning library for Python
Quantitative Risk Management in Python

Neural network structure

  • Layers: connected processing neurons
    • Input layer

input layer of neural network

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer

hidden layer of neural network

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer
    • Output layer
  • Training: learn relationship between input and output

image of input, hidden and output layers

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer
    • Output layer
  • Training: learn relationship between input and output
    • Asset prices => Input layer

image with asset prices feeding into neural network

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer
    • Output layer
  • Training: learn relationship between input and output
    • Asset prices => Input layer
    • Input + hidden layer processing

image with weight edges in neural network

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer
    • Output layer
  • Training: learn relationship between input and output
    • Asset prices => Input layer
    • Input + hidden layer processing
    • Hidden + output layer processing

image of weights from hidden to output layer

Quantitative Risk Management in Python

Neural network structure

  • Neural network structure
    • Input layer
    • Hidden layer
    • Output layer
  • Training: learn relationship between input and output
    • Asset prices => Input layer
    • Input + hidden layer processing
    • Hidden + output layer processing
    • Output => portfolio weights

image of output layer presented as portfolio weights

Quantitative Risk Management in Python

Using neural networks for portfolio optimization

  • Training
    • Compare output and pre-existing "best" portfolio weights
    • Goal: minimize "error" between output and weights
    • Small error => network is trained
  • Usage
    • Input: new, unseen asset prices
    • Output: predicted "best" portfolio weights for new asset prices
    • Best weights = risk management
Quantitative Risk Management in Python

Creating neural networks in Python

 

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense
model = Sequential() model.add(Dense(10, input_dim=4, activation='sigmoid')) model.add(Dense(4))
Quantitative Risk Management in Python

Training the network in Python

  • Historical asset prices: training_input matrix
  • Historical portfolio weights: training_output vector
  • Compile model with:
    • given error minimization ('loss')
    • given optimization algorithm ('optimizer')
  • Fit model to training data
    • epochs: number of training loops to update internal parameters
model.compile(loss='mean_squared_error', optimizer='rmsprop')

model.fit(training_input, training_output, epochs=100)
Quantitative Risk Management in Python

Risk management in Python

  • Usage: provide new (e.g. real-time) asset pricing data
    • New vector new_asset_prices given to input layer
  • Evaluate network using model.predict() on new prices
    • Result: predicted portfolio weights
  • Accumulate enough data over time => re-train network
    • Test network on previous data => backtesting
# new asset prices are in the vector new_asset_prices
predicted = model.predict(new_asset_prices)
Quantitative Risk Management in Python

Let's practice!

Quantitative Risk Management in Python

Preparing Video For Download...