TradeTesterR is an open-source R framework that brings institutional-quality backtesting capabilities to individual traders, academic researchers, and educational institutions. By combining sophisticated functionality with transparent, understandable architecture, this framework enables both practical strategy development and effective financial education.
The current landscape of backtesting software presents a stark dichotomy:
- Commercial platforms (TradeStation, MetaTrader, NinjaTrader) offer comprehensive features but require substantial licensing fees and lock users into proprietary ecosystems
- Existing R solutions like quantstrat present steep learning curves with complex architectures that deter many users
- Simple alternatives sacrifice essential features like realistic order execution and sophisticated position management
TradeTesterR bridges this gap by providing:
- π Educational Transparency: Every step of the trading process is visible and verifiable
- π° Free & Open Source: No licensing fees or platform lock-in
- π Progressive Complexity: Start simple, grow sophisticated
- π Realistic Simulation: Professional-grade execution modeling
Separates strategy logic from execution mechanics, teaching and enforcing the crucial distinction between when decisions are made and when trades execute:
- Strategy timeframe for signal generation (e.g., daily bars)
- Execution timeframe for realistic fills (e.g., minute bars)
- Prevents look-ahead bias while maintaining code clarity
- Market, limit, stop, and stop-limit orders
- Realistic order execution with slippage modeling
- Partial fills and order rejection handling
- Position pyramiding and scaling options
- Fixed and trailing stop losses/take profits
- Time-based exits and position reductions
- Signal-based exits with customizable logic
- Multiple simultaneous exit conditions
- Fixed dollar amount sizing
- Percentage of equity sizing
- Volatility-based position sizing
- Kelly criterion implementation
- Support for futures contracts and leverage
- Every trade is traceable through the system
- Inspect signals, orders, and positions at any point
- Detailed execution logs and trade analysis
- No "black box" calculations
- Comprehensive performance metrics
- Walk-forward optimization capabilities
- Parameter stability analysis
- Monte Carlo simulation support
- Multi-dimensional parameter visualization
- Clear, documented code structure
- Progressive learning path
- Extensive examples from simple to complex
- Visible market mechanics for teaching
# Install from GitHub
# install.packages("devtools")
devtools::install_github("alb3rtazzo/TradeTesteR")library(TradeTesterR)
# Load your data
price_data <- fread("your_data.csv")
# Define a simple strategy
my_strategy <- function(price) {
# Calculate indicators
price[, SMA20 := SMA(Close, 20)]
price[, SMA50 := SMA(Close, 50)]
# Generate signals
price[, BuySignal := SMA20 > SMA50 & shift(SMA20) <= shift(SMA50)]
price[, SellSignal := SMA20 < SMA50 & shift(SMA20) >= shift(SMA50)]
# Set entry parameters
price[BuySignal == TRUE, EntryPrice := shift(Open, 1, type="lead")]
price[BuySignal == TRUE, EntryType := "Market"]
return(price)
}
# Run backtest
results <- backtest(
data = my_strategy(price_data),
initial_equity = 10000,
position_size = 1000,
instrument_type = "stocks"
)
# Analyze results
print(results$metrics)
plot(results$equity_curve)- Getting Started - Basic setup and first strategy
- Strategy Development - Building trading logic
- Order Types & Execution - Understanding order mechanics
- Position Management - Sizing and risk control
- Exit Strategies - Professional exit techniques
- Optimization - Parameter tuning and walk-forward analysis
- Bollinger Band Mean Reversion
- Dual Moving Average Crossover
- RSI Divergence Strategy
- Multi-Timeframe Analysis
- Portfolio Strategies
TradeTesterR implements progressive disclosure through a layered architecture:
- Simple Strategy Interface: Basic functions and indicators for rapid prototyping
- Signal Generation: Data transformations and entry/exit rules
- Order Management: Backtest function and position tracking
- Execution Simulation: Dual timeframe engine and transaction costs
Users can work at any layer based on their expertise and requirements.
We welcome contributions! Please see our Contributing Guide for details.
- Additional strategy examples
- New position sizing algorithms
- Enhanced visualization tools
- Performance optimizations
- Documentation improvements
TradeTesterR is designed for educational institutions:
- Free for academic use
- Transparent for teaching market mechanics
- Suitable for research and thesis work
- No licensing restrictions for students
If you use TradeTesterR in academic work, please cite:
Pallotta, A. (2025). TradeTesterR: An Open-Source Backtesting Framework
for Accessible Quantitative Finance. Available at:
https://github.com/alb3rtazzo/TradeTesterR
This project is licensed under the GPL-3 License - see the LICENSE file for details.
- β Use freely for any purpose
- β Modify and distribute
- β Use in commercial applications
- β Cannot close-source derivatives
- β Cannot resell as proprietary software
- π§ Email: pallottaalberto@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
This framework emerged from PhD research on democratizing quantitative finance tools. Special thanks to the R community and all contributors who help make professional trading tools accessible to everyone.
"In an era where algorithmic and systematic trading increasingly dominate markets, democratizing access to development tools becomes essential for maintaining market diversity and opportunity." - TradeTesterR Philosophy
