User Documentation
This section is intended for end-users of the Trading Strategy Tester. It provides a comprehensive guide on how to install, configure, and use the system effectively. Whether you're a trader looking to backtest your strategies or a developer interested in extending the functionality, this documentation will help you get started.
What is the Trading Strategy Tester?
The Trading Strategy Tester is a powerful tool designed to test and evaluate trading strategies using historical market data. It allows users to define various trading conditions, apply different technical indicators, and assess strategy performance through backtesting. It also provides visualizations and metrics to help users understand the effectiveness of their strategies.
What can you do with it?
- Backtest Strategies: Evaluate the performance of your trading strategies using historical data.
- Visualize Results: Generate graphs and charts to visualize the performance of your strategies.
- Performance Metrics: View detailed performance metrics, including profit, drawdown, win rate, and more.
- Technical Indicators: Use a variety of built-in technical indicators to enhance your strategies. List of available indicators can be found here.
Getting Started
To get started with the Trading Strategy Tester first install the package. You can do this using pip:
pip install trading-strategy-tester
This will install the latest version of the Trading Strategy Tester along with its dependencies. With this installed, you can start using the tool to backtest your trading strategies.
On the following links you can find some examples of how to use the package for backtesting strategies, and using technical indicators.
Executing Strategies
Once you have created your strategy using the Strategy
class, you can execute it using the execute()
method.
Let's use the RSI strategy from the previous example:
from trading_strategy_tester import Strategy
from trading_strategy_tester.conditions import CrossOverCondition, CrossUnderCondition
from trading_strategy_tester.trading_series import RSI, CONST
from trading_strategy_tester import PositionTypeEnum, Contracts
from datetime import datetime
strat = Strategy(
ticker="AAPL",
position_type= PositionTypeEnum.LONG_SHORT_COMBINED,
buy_condition= CrossOverCondition(
first_series=RSI('AAPL', length=14),
second_series=CONST(30)
),
sell_condition=CrossUnderCondition(
first_series=RSI('AAPL'),
second_series=CONST(70)
),
start_date=datetime(2015, 1, 1),
end_date=datetime(2020, 1, 1),
order_size=Contracts(value=1)
)
# Execute the strategy
strat.execute()
After executing the strategy, you can retrieve the trades, graphs, and statistics generated by the strategy using the following methods:
# Get dictionry of executed trades
trades = strat.get_trades()
# Get dictionary with statistics about the strategy
statistics = strat.get_statistics()
# Get dictionary with graphs generated by the strategy
graphs = strat.get_graphs()
Graphs are returned in the form of a dictionary with 3 keys: PRICE
, BUY
, and SELL
. PRICE
is a graph with price of the ticker, volume and entry and exit points of the strategy. BUY
and SELL
are lists of graphs with the buy and sell signals of the strategy that are generated based of the conditions defined in the strategy. Each condition has its own graph with the signals generated by the condition. You can display the graphs using show()
method of the graph object. For example:
graphs['PRICE'].show()