Skip to main content

Python library dedicated to simplifying the process of backtesting complex stock market strategies.

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

StratLab-1.0.24.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

StratLab-1.0.24-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file StratLab-1.0.24.tar.gz.

File metadata

  • Download URL: StratLab-1.0.24.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for StratLab-1.0.24.tar.gz
Algorithm Hash digest
SHA256 95625d013eb4fed7727d6b056377adc7b4f242965cbbfb48fccd78d97b61a2df
MD5 140be6c5604c3b9b05b0bb6c8ba2660d
BLAKE2b-256 6ccacc461e04c6cda461a3e53278162d8b7e92afcafe748e471725fa448a8913

See more details on using hashes here.

File details

Details for the file StratLab-1.0.24-py3-none-any.whl.

File metadata

  • Download URL: StratLab-1.0.24-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for StratLab-1.0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee5aced0728ab5d02a7032b98982e39cc99642ffc02f97a4376189fc6980855
MD5 9b4bad9c52435424ff2dad2d813d6eda
BLAKE2b-256 de8e0768df92baa887539723aad9c6f7ccd95f3e9f65806635821368a3fc56bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page