O'Reilly logo
live online training icon Live Online training

Introduction to Quantitative Financial Risk Management with R

Evaluate risk vs. reward in stocks, consumer credit, and non-traditional markets

Ted Kwartler

The course covers three financial markets and how to identify investment opportunities within each. First, participants will assess real stock data, then evaluate consumer credit and finally quantify aspects of a non-traditional investment market.

In this entry-level workshop, you will learn how to download equity data, perform evaluations and visualize stocks using R. The course will explain basic trading indicators and visualizations giving attendees a foundation for more sophisticated analyses on their own. Next participants will model a consumer credit market to quantify risk versus reward thereby identifying the most lucrative opportunities. Lastly, we will explore a non-traditional market, simulate the reward in the market and put our findings to an actual test in a highly speculative and unregulated environment.

As a statistical programming language R is excellent for algorithmic trading, particularly non-high frequency trading. Further, R’s forgiving syntax means students can focus on concepts, trading indicators and application rather than esoteric coding. Using R in this course will help retail investors and financial professionals create trading workflows and evaluate risk.

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

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

  • What a stock indicator is and how to interpret it
  • Common visualizations used by quantitative equity traders
  • Basic risk modeling in consumer credit
  • Simulating the return in an unregulated investment market

And you’ll be able to:

  • Download stock data directly into R
  • Build financial indications to identify stock buying opportunities
  • Perform a “backtest” to evaluate an indicator before putting it into practice
  • Build common stock visualizations mimicking online and paid services
  • Model risk in consumer credit, visualize the risk vs reward in the market and make selections based on this perspective
  • Structure an unregulated investment market for evaluation instead of speculation

This training course is for you because...

  • You’re a retail investor looking to improve returns
  • You work with financial information provided by professionals
  • You want to improve your financial acumen and investment opportunities
  • You want to apply your statistical and data science acumen in an investment workflow


  • Basic knowledge of R, R-Studio & git
  • Familiarity with data structures in R, particularly data frames and XTS (time series)
  • Basics of ggplot2 visualization will improve learning outcomes

Recommended preparation:

Recommended follow-up:

About your instructor

  • Ted Kwartler is a data-driven professional, author and instructor. He has held leadership roles at amazon.com, Liberty Mutual Insurance and was an early employee at DataRobot. He is also an adjunct professor at Harvard University’s Extension School where he teaches Data Science for Business. In addition, he teaches a seminar on Natural Language Processing (NLP) at St Gallen University, Switzerland. Ted holds an MBA from the University of Notre Dame with citations in marketing and analytics. As a result, his teaching and data science focuses on practical business and finance applications.


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

Introduction (10 minutes)

  • Intro, review key terms & perform a “git pull” to ensure all participants have scripts, ppt, and data.

Obtaining Stock Data & Basic Visualization (15 minutes)

  • Presentation: What is the financial market? Types of investing strategies.
  • Presentation: What is an API? API access to stock data in R
  • Exercise: Manipulate a time series object 1_TTR.R
  • Presentation: How to understand basic financial plots
  • Exercise: Make basic & dynamic plots of the data 1_TTR.R
  • Q&A

Creating the first indicator (15 minutes)

  • Presentation: Explain what a technical trading rule/indicator is
  • Presentation: Learn what a lagged simple moving is
  • Exercise: Calculate 3 SMAs to understand the “smoothing” effect on time series data 2_TTR.R
  • Exercise: Visualize the SMA of an equity 2_TTR.R
  • Q&A

Applying the SMA indicator (15 minutes)

  • Exercise: Calculate 50 & 200 day SMAs 3_TTR.R
  • Presentation: Calculate the investment return with SMAs “death” and “golden” cross pattern
  • Exercise: Structure the SMAs as a trading indicator 3_TTR.R
  • Presentation: Explain what a back-test is for evaluating an indicator
  • Exercise: Visualize the historical performance using a back-test 3_TTR.R
  • Q&A
  • Break (5 minutes)

Creating the MACD indicator (20 minutes)

  • Presentation: Walk through the moving avg convergence divergence indicator
  • Exercise: Manually calculate a standard moving average convergence divergence indicator 4_TTR.R
  • Exercise: Functional construction of the MACD 4_TTR.R
  • Exercise: Apply the MACD signal as an indicator 4_TTR.R
  • Exercise: Visualize the stock & MACD in a dynamic plot 4_TTR.R
  • Exercise: Perform a back-test to understand & visualize the return using this indicator 4_TTR.R
  • Debrief on MACD visuals & backtest
  • Q&A

Creating & Applying the RSI indicator (20 minutes)

  • Presentation: Learn what a relative strength indicator is
  • Exercise: Functional construction of the RSI 5_TTR.R
  • Presentation: Interpret RSI as an indication
  • Exercise: Visualize the RSI in a dynamic plot 5_TTR.R

Compounding two or more indicators (10 minutes)

  • Exercise: Calculate the MACD & RSI 5_TTR.R
  • Exercise: Apply both as a single indicator for buying/selling actions 5_TTR.R
  • Presentation: After back-test & visualizing debrief on results
  • Q&A
  • Break (5 minutes)

Consumer credit modeling (20 minutes)

  • Presentation: Explain the investment scenario
  • Presentation: Basics of a logistic regression
  • Exercise: 6_CreditModeling.R Create a logistic regression modeling loan default probability

Predicting loan defaults (20 minutes)

  • Exercise: Apply the logistic regression to new loans 7_CreditModeling.R
  • Presentation: Model KPI & realistic investment scenario review
  • Exercise: Evaluate the training, test partitions 7_CreditModeling.R
  • Presentation: Introduce CAPM
  • Exercise: Build a dynamic capital asset pricing visual to evaluate the investment opportunities 7_CreditModeling.R
  • Q&A

Simulating a non-traditional market opportunity (15 minutes)

  • Presentation: Review the trading card market as an investment vehicle
  • Presentation: Structure problem for analysis
  • Exercise: Examine how to sample with probability 8_nonTraditional_Mkt.R
  • Exercise: Simulate market buying opportunity to quantify risk 8_nonTraditional_Mkt.R
  • Q&A