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.3.tar.gz
(32.7 kB
view hashes)
Built Distribution
Close
Hashes for strategy_tester-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ac4b405f1fde54458bb7e192085dd4d147836775c942795a07513012e00caee |
|
MD5 | 2a32814be85dc8fae0de88e9e6dfd54b |
|
BLAKE2b-256 | 3922b9d45a0293cf535b9d11b6c67de3f79ec52166e602f659a91b781398b6a1 |