mathengem / Algorithmic-Trading-Backtesting-in-python

Code snippet show casing backtesting a strategy in python on historical stock market data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

=======

Algorithmic Trading (Backtesting in python)

Code snippet show casing backtesting a strategy in python on historical stock market data.

Intro
The goal of this article is to describe how to back-test a technical indicator-based strategy on python. I will specifically use a Bollinger band-based strategy to create signals and positions.

Description of strategy
Create 20-day (+/- 2 standard deviations) Bollinger bands on the adjusted close price. Buy, when the price crosses the lower band from the top and hold until the price crosses the upper band from below the next time. Sell when the price crosses the upper band from below and hold until the price crosses the lower band from the top the next time.

Here are the steps to create your own back-testing code.

  1. Import necessary libraries
  2. Download OHLCV Data
  3. Calculate daily returns
  4. Create strategy-based data columns
  5. Create strategy indicators
  6. Create signals and positions
  7. Analyze results

About

Code snippet show casing backtesting a strategy in python on historical stock market data.


Languages

Language:Jupyter Notebook 100.0%