Assessing the riskiness of a single stock in Python

Bernard Brenyah
DS Biz
Published in
2 min readSep 24, 2017
Balancing Risk & Reward Image Credit: Trinityp3

For financiers and investment analysts, the trade-off between risk and returns of financial securities are of utmost importance. In the last blog post, we looked at assessing the rates of returns for single financial instruments and a portfolio made up of more than one securities. This blog post will look at the concept of risk and how they can be ascertained with the help of Python.

What is risk as a concept in Finance and how is it even measured? Investopedia defines Equity risk as one that:

“Covers the risk involved in the volatile price changes of shares of stock. Changes in prices because of market differences, political changes, natural calamities, diplomatic changes or economic conflicts may cause volatile foreign investment conditions that may expose businesses and individuals to foreign investment risk”

Basically, Investors don’t like surprises. A highly volatile stock is one whose prices changes faster than a typical English summer (so they keep saying). An equity’s risk is thus embedded in the volatility of its prices. So what’s the best measure of price volatilities (risk) in the world of Finance? Standard Deviation!

The standard deviation of the returns on an equity (like stocks) represents the best measure of the equity’s risk. A highly volatile (risky) stock has more wide ranges in prices and vice versa.

Great, let’s now pull some daily real-world stock data and check for their volatilities with Python.

Here’s also a simple script based on the tutorial for visualizing the volatility of daily returns of three stocks stacked against each other:

As it can be seen in the output (image below), the spread of daily returns of Tesla (TSLA) is the most volatile as it is the stock with the most widely ‘spreads’ of daily returns. Followed by Facebook and Apple with the least spreads.

Histogram of Daily Returns of Apple, Facebook and Tesla

In this post, we have looked at the riskiness of single stocks with real-world data from Yahoo Finance. The next post will build on this concept of risk with respect to a portfolio of various stocks. Until then, happy coding!

--

--