Skip to main content

A python package for testing strategies

Project description

strategy tester

Installation

pip install -r requirements.txt

Usage

Here a snippet of the strategy tester:

from strategy_tester import StrategyTester
import pandas as pd
import pandas_ta as ta
from pandas_ta_supplementary_libraries import *
import numpy as np

class SimpleStrategy(Strategy):

    def indicators(strategy):
        # Set all indicators here
        strategy.in_long = False
        strategy.in_short = False
        ma = Indicator("ma", ta.sma, args=(strategy.close, 100))

    def condition(strategy):
        strategy.conditions = ma,

    def trade_calc(strategy, row):
        if row.close > row.ma:
            if strategy.in_short:
                strategy.exit("short")
                strategy.in_short = False
            strategy.entry("long", "long")
            strategy.in_long = True
        elif row.close < row.ma:
            if strategy.in_long:
                strategy.exit("long")
                strategy.in_long = False
            strategy.entry("short", "short")
            strategy.in_short = True

strategy = SimpleStrategy(data)
# Run the strategy tester
strategy.run()
# Get back test results
backtest = strategy.backtest()
# Get list of trades
list_of_trades = strategy.list_of_trades()
# Get list of open positions
list_of_open_positions = strategy.open_positions
# Get list of closed positions
list_of_closed_positions = strategy.closed_positions

Repository

Github pypi

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

strategy_tester-0.1.4.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

strategy_tester-0.1.4-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file strategy_tester-0.1.4.tar.gz.

File metadata

  • Download URL: strategy_tester-0.1.4.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.2

File hashes

Hashes for strategy_tester-0.1.4.tar.gz
Algorithm Hash digest
SHA256 20e751409cb0cce2c0463359a0770a182e1b021ff11ea847d853d923f6325e9b
MD5 a8d2c52e81753e8d64c79b78ecff42cf
BLAKE2b-256 8742382bd42e4655192c0fb7a5db5da6bc5068090475c230c43154035cdf89ce

See more details on using hashes here.

File details

Details for the file strategy_tester-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for strategy_tester-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6f36de0ef7f98ece2c01ab69bf58f568f54c7799f26dbdb7153882988abaa3a0
MD5 5b6606854a2748cf729d0f435ebefad8
BLAKE2b-256 e8cd7543bbd8d98591edefa0d9c3945998b89637cd1767098fce44a038b75ed8

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