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
Project details
Release history Release notifications | RSS feed
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 hashes)
Built Distribution
Close
Hashes for strategy_tester-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f36de0ef7f98ece2c01ab69bf58f568f54c7799f26dbdb7153882988abaa3a0 |
|
MD5 | 5b6606854a2748cf729d0f435ebefad8 |
|
BLAKE2b-256 | e8cd7543bbd8d98591edefa0d9c3945998b89637cd1767098fce44a038b75ed8 |