O'Reilly logo
live online training icon Live Online training

Algorithmic risk management in trading and investing

Analyze and manage your financial risks using Python

Topic: Business
Deepak Kanungo

The key to success in risky investments is proactively and systematically managing expected losses so that they don’t overwhelm expected profits in the long run. Value at risk (VaR) and expected shortfall (ES) are risk measures used extensively by financial institutions, regulators, and corporate treasurers in nonfinancial institutions. Similarly, volatility and beta—foundational risk measures upon which modern portfolio theory (MPT) is built—are used extensively by institutional and individual investors. It’s imperative to understand the drawbacks of using these measures to manage risks in portfolios.

Join expert Deepak Kanungo to explore the concepts, processes, and tools for developing algorithmic risk-management strategies such as the Kelly criterion—which is used by great investors like Warren Buffett and Edward Thorpe but isn’t taught in academia or professional training organizations like the CFA. You’ll dive into the advantages and disadvantages of algorithmic risk management, learn how to import, analyze, and visualize data from the market, apply the Kelly Criterion to size trades, and more—all using Python and its libraries.

Note: Live trading is out of the scope of the course.

What you'll learn-and how you can apply it

By the end of this live, hands-on, online course, you’ll understand:

  • The advantages and disadvantages of algorithmic risk management
  • The strengths and weaknesses of VaR, adjusted VaR, and conditional VaR/ES
  • Why maximizing expected value of trades and investments risks ruin and why volatility and beta are inadequate measures of risk
  • The pros and cons of the Kelly criterion and Markowitz’s capital allocation strategies
  • The importance of sizing your trades and investments
  • The concepts, process, and tools for developing risk-management strategies

And you’ll be able to:

  • Import, analyze, and visualize data from the market using the pandas library as well as fundamental and alternative sources available for free on the web
  • Estimate Var and ES using Monte Carlo simulations
  • Analyze past trades to estimate your edge and odds
  • Apply the Kelly criterion to size trades
  • Build a portfolio of stocks using MPT
  • Analyze and design your own specific risk-management strategies in Python

This training course is for you because...

  • You’re an investor, trader, financial analyst, or risk manager who wants to develop algorithmic risk management strategies.


  • General knowledge of Python and pandas DataFrames
  • A basic understanding of probability and statistics
  • Create an empty Google Colab document before the course

Recommended preparation:

Recommended follow-up:

About your instructor

  • Deepak Kanungo is the founder and CEO of Hedged Capital LLC, an AI-powered trading and advisory firm that uses probabilistic models and technologies. In 2005, Deepak invented a project portfolio management system using Bayesian inference, the foundation of all probabilistic programming languages. Previously, Deepak was a financial advisor at Morgan Stanley, a Silicon Valley fintech entrepreneur, and a director in the Global Planning Department at Mastercard International. He was educated at Princeton University (astrophysics) and the London School of Economics (finance and information systems).


The timeframes are only estimates and may vary according to how the class is progressing

Quantifying risks in trading and investing (55 minutes)

  • Group discussion: What’s your investing, trading, and Python experience?
  • Lecture: Risk measures such as volatility, beta, VaR, adjusted VaR, and ES; algorithmic characteristics of a good risk measure
  • Hands-on exercises: Set up Colab notebook; create pandas DataFrames to import data; calculate, analyze, and visualize various risk measures
  • Q&A
  • Break (5 minutes)

Using Monte Carlo simulations to estimate VaR and ES (55 minutes)

  • Lecture: Methods to estimate VaR, modified VaR, and ES; strengths and weaknesses
  • Hands-on exercise: Use pandas DataFrames and Monte Carlo simulations to estimate VaR and ES for stocks and portfolios
  • Q&A
  • Break (5 minutes)

Applying the Kelly criterion and MPT to trading and investing (50 minutes)

  • Lecture: The Kelly criterion; how it differs from the Markowitz mean-variance theory; its strengths and weaknesses
  • Hands-on exercises: Use pandas DataFrames to analyze and visualize portfolios using MPT; use Monte Carlo simulations to demonstrate how the Kelly position sizing outperforms other capital allocation strategies

Wrap-up and Q&A (10 minutes)