Skip to content

Stock market backtesting tool written entirely in Python. Currently using the yfinance API library as the primary data source.

Notifications You must be signed in to change notification settings

rstickles16/StratLab

Repository files navigation

What is StratLab?

StratLab is a Python library designed to backtest stock market strategies. The library currently uses the yfinance (Yahoo Finance) API as a means for extracting financial data, which is then manipulated utilizing Pandas dataframes and Numpy functions. There are also options to extract the backtested results directly into excel files.

How do you install it?

Run the following command in your terminal

pip install StratLab

How do you use it?

Step 1: Initialize backtest

# This imports the StratLab library and intializes the Backtest.
# The to_excel argument writes an excel file to your desktop with an analysis of the backtest.
import StratLib as sl

bt = sl.Backtest(to_excel=True)

Step 2: Add condition for trade

# This example creates a condition in the backtest for when
# ^NDX (Nasdaq 100 Index) price is above its 200D moving average...
bt.add_condition(
  name='200 SMA Bullish',
  ticker_1='^NDX',
  study_1='price',
  operator='>',
  ticker_2='^NDX',
  study_2='sma',
  study_2_period=200
)

Step 3: Add holding for the condition(s)

# This example tells the backtest to hold ^NDX (Nasdaq 100 Index)
# when the "200 SMA Bullish" condition is True...
bt.add_holding(
  conditions=['200 SMA Bullish'],
  flags=['True'],
  holdings_list=['^NDX']
)

Step 4: Run the backtest

bt.run()

About

Stock market backtesting tool written entirely in Python. Currently using the yfinance API library as the primary data source.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages