Using Python to “Buy Low and Sell High”

Introduction to Bollinger Bands

Bollinger Bands are a type of technical analysis indicator created by John Bollinger. The bands serve as a trading envelope that provide a feel for a relative measurement for high and low points that can be used as overbought and oversold levels.

Bollinger Bands typically include two boundary lines (upper and lower bands) and one moving average line (simple moving average).

Using an “overbought and oversold” strategy, Bollinger Bands can be viewed as creating a ceiling and a floor that a stock price would bounce between. When the stock price hits the floor (lower band), it may indicate that the…

Evaluating a Stock’s Risk with Python

Photo by Nicholas Cappello on Unsplash

One of the most commonly used and talked about risk measures in investing is the Sharpe Ratio. Unlike the Coefficient of Variation, which measures the risk per unit of return, the Sharpe Ratio tells an analyst the return per unit of risk. In other words, how much extra return you will receive per unit of risk that you take on.

Any Sharpe Ratio above 1.00 generally means the portfolio or stock is acceptable to hold because you are receiving an excess return per unit of risk. Anything above 2.00 or 3.00 is considered very good. The opposite can be said…

One of the most popular technical indicators

Photo by Maxim Hopman on Unsplash

Introduction to Relative Strength Index (RSI)

The Relative Strength Index (RSI) is a popular technical indicator and momentum oscillator, developed by J. Welles Wilder in 1978. The RSI compares the size and rate of a securities recent gains and losses (usually in a 14 day period) and signals to a trader if a security is consider “overbought” or “oversold”.

The RSI values are measured within the 0–100 range, with a value of 70 and above signaling a security is overbought and values of 30 and below being oversold. Values above 70 may signal a good time to sell and exit your position. …

The Moving Average Convergence Divergence Indicator

Photo by Yiorgos Ntrahas on Unsplash


The Moving Average Convergence Divergence (MACD) is a popular technical indicator associated with trend following and momentum. The MACD indicator involves a few calculations and a few trend lines:

  1. MACD Line — This line is the difference between the 26-day exponential moving average line and the 12-day exponential moving average line (an exponential moving average line places more emphasis on the more recents days in the calculation window).
  2. The Signal Line — This is the 9-day exponential moving average line of the MACD line.
  3. The Histogram (Bonus)— While not necessary, a histogram showing the magnitude of the separation between the…

Code for positive expected value decisions

Introduction to Pot Odds and Equity

Pot Odds

Pot odds, simply put, are the relationships between the total pot size and the bet that you must call to see the next card. Pot odds explain the amount of money you will win for every dollar you put into it yourself.

To calculate pot odds, simply divide the amount of money you must call by the total pot size if you were to call. For example, if the pot size is $100 and you must put in $50 to call, you would do: $50/($100 + $50). Which would give you pot odds of 1/3, or about 33%.

Hand Equity

Your hand’s…

Clustering in Python

Summary: In this post I will discuss the details of unsupervised machine learning and its applications. Code examples will be shown to demonstrate certain techniques.

What is Unsupervised Learning?

Unsupervised learning is a branch of machine learning that is used to find underlying patterns in data and is often used in exploratory data analysis. Unsupervised learning does not use labeled data like supervised learning, but instead focuses on the data’s features. Labeled training data has a corresponding output for each input. When using unsupervised learning, we are not concerned with the targeted outputs because the goal of the algorithm is to find relationships within…

Does it work?

Simple Linear Regression

I will briefly touch on simple linear regression in this post, but I do have an article specifically about simple linear regression using Python that can be found here and it may be a bit more detailed and helpful.

Linear regression can be used to find a relationship between two or more variables of interest and allows us to make predictions once these relationships are found. In simple linear regression, there are only two variables: one dependent variable and one independent variable.

Simple linear regression will provide a line of best fit, or the regression line. …

Its easier than you think…

What is a moving average?

A moving average is one of the most basic technical indicators used to analyze stocks. “Moving average” is a broad term and there are many variations used by analysts to smooth out price data and analyze trends.

Moving averages will require a time period for calculations. For example, an investor may choose a 50-day moving average, where the past 50 days in the data will be used to calculate the average. …

Coding a line of best fit

Simple linear regression is a concept that you may be familiar with already from middle school or high school. If you have ever heard of a slope and an intercept, or y = mx + b, then you have already learned about simple linear regression!

What is Simple Linear Regression?

Simple linear regression is a statistical method that we can use to find a relationship between two variables and make predictions. The two variables used are typically denoted as y and x. The independent variable, or the variable used to predict the dependent variable is denoted as x. …

I recently finished up an introductory course for data science at my university and for my final project, I decided I wanted to work with stock market data. I wanted to place my focus on the algorithmic trading and needed a quick and easy way to gather stock data that was easily useable.

I came across a library called yfinance and it made my project a lot easier!

I would highly recommend reading through the documentation. Its a quick read that will aid you with any projects involving stock data.

Before we begin, we will need to install the yfinance

Aidan Wilson

Data Science and Economics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store