TradePruf is a flexible and extensible backtesting framework that allows you to test trading strategies across multiple asset classes including stocks, cryptocurrencies, and ETFs. It provides detailed performance metrics, portfolio management capabilities, and interactive visualizations.
This project was developed in a very short period with heavy use of AI assistance. While the code is functional and well-structured, it should be used for educational and research purposes only. Trading financial instruments involves substantial risk of loss. Past performance is not indicative of future results.
- Multiple asset classes support (Stocks, Crypto, ETFs)
- Built-in trading strategies:
- Simple Moving Average (SMA) Crossover
- Exponential Moving Average (EMA)
- Relative Strength Index (RSI)
- Moving Average Convergence Divergence (MACD)
- Bollinger Bands
- ATR Trailing Stop
- Portfolio backtesting with custom allocation
- Detailed performance metrics:
- Total/Annual Returns
- Sharpe Ratio
- Maximum Drawdown
- Win Rate
- Trade Statistics
- Interactive visualizations:
- Equity curves
- Drawdown analysis
- Monthly returns heatmap
- Asset allocation
- Flexible data granularity (1m to 1wk)
- Position sizing and risk management
- Extensible strategy framework
- Clone the repository:
git clone https://github.com/arman-bd/tradepruf.git
cd tradepruf
- Create and activate a virtual environment using uv:
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
uv pip install -e ".[dev]"
# Basic backtest
tradepruf backtest --symbol BTC-USD --asset-type crypto --strategy sma
# With visualization
tradepruf backtest \
--symbol AAPL \
--asset-type stock \
--strategy macd \
--start-date 2023-01-01 \
--end-date 2024-01-01 \
--charts interactive
- Create a portfolio configuration file:
{
"initial_capital": 100000,
"position_size": 0.1,
"max_positions": 10,
"start_date": "2023-01-01",
"end_date": "2024-01-01",
"interval": "1h",
"assets": [
{
"symbol": "BTC-USD",
"type": "crypto",
"strategy": "sma",
"params": {
"short_window": 20,
"long_window": 50
}
},
{
"symbol": "ETH-USD",
"type": "crypto",
"strategy": "rsi",
"params": {
"period": 14,
"oversold": 30,
"overbought": 70
}
},
{
"symbol": "AAPL",
"type": "stock",
"strategy": "macd"
}
]
}
- Run the backtest:
tradepruf backtest-portfolio --portfolio portfolios/btc-eth-aapl.json --charts interactive --enhanced-analysis
Result
Portfolio Configuration
βββββββββββββββββββ³ββββββββββββββ
β Parameter β Value β
β‘ββββββββββββββββββββββββββββββββ©
β Initial Capital β $100,000.00 β
β Position Size β 0.20 β
β Max Positions β 5 β
β Start Date β 2023-01-01 β
β End Date β 2024-01-01 β
β Interval β 1h β
βββββββββββββββββββ΄ββββββββββββββ
Assets
βββββββββββ³βββββββββ³βββββββββββ³βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Symbol β Type β Strategy β Extra Params β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β BTC-USD β crypto β sma β {"short_window": 20, "long_window": 50} β
β ETH-USD β crypto β rsi β {"period": 14, "oversold": 30, "overbought": 70} β
β AAPL β stock β macd β "N/A" β
βββββββββββ΄βββββββββ΄βββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββ
================================================================================
=== Starting portfolio backtest with 3 assets ===
================================================================================
Fetched 8676 bars for BTC-USD
Date range: 2023-01-01 00:00:00+00:00 to 2023-12-31 23:00:00+00:00
Fetched 8675 bars for ETH-USD
Date range: 2023-01-01 00:00:00+00:00 to 2023-12-31 23:00:00+00:00
Fetched 1742 bars for AAPL
Date range: 2023-01-03 09:30:00-05:00 to 2023-12-29 15:30:00-05:00
================================================================================
=== Generating signals ===
================================================================================
Generated SMA Crossover signals: Buy=111, Sell=110
Generated signals for BTC-USD using SMA Crossover
Generated RSI values: Min=2.86, Max=98.35
Generated RSI signals: Buy=117, Sell=116
Generated signals for ETH-USD using RSI Strategy
Generated MACD signals: Buy=71, Sell=71
Generated signals for AAPL using MACD Strategy
Portfolio Backtest Results
βββββββββββββββββ³βββββββββββ
β Metric β Value β
β‘βββββββββββββββββββββββββββ©
β Total Return β 24.12% β
β Annual Return β 24.20% β
β Sharpe Ratio β 0.12 β
β Max Drawdown β 38.12% β
β Total Trades β 299 β
β Win Rate β 47.83% β
β Average Win β $443.41 β
β Average Loss β $-253.45 β
β Volatility β 177.96% β
βββββββββββββββββ΄βββββββββββ
Asset Performance Summary
βββββββββββ³ββββββββββββββββ³βββββββββ³βββββββββ³βββββββββββββ³βββββββββββ
β Asset β Strategy β Type β Trades β P&L β Win Rate β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β BTC-USD β SMA Crossover β crypto β 111 β $16,305.44 β 35.1% β
β ETH-USD β RSI Strategy β crypto β 117 β $5,112.17 β 65.8% β
β AAPL β MACD Strategy β stock β 71 β $2,705.18 β 38.0% β
βββββββββββ΄ββββββββββββββββ΄βββββββββ΄βββββββββ΄βββββββββββββ΄βββββββββββ
Analysis Dashboard Analysis Dashboard contains some interactive charts and tables to help you understand the performance of your portfolio. Here are some screenshots of the dashboard:
Create your own strategy by extending the base Strategy class:
from strategies.base import Strategy, SignalType
class MyCustomStrategy(Strategy):
def __init__(self, param1: int = 10, param2: float = 2.0):
super().__init__("My Custom Strategy")
self.param1 = param1
self.param2 = param2
def generate_signals(self, data: pd.DataFrame) -> pd.Series:
signals = pd.Series(SignalType.HOLD, index=data.index)
# Your strategy logic here
return signals
interactive
: Display charts in browserhtml
: Save interactive charts as HTML filespng
: Save static chart imagesnone
: No visualization (default)
- Total Return
- Annual Return
- Sharpe Ratio
- Maximum Drawdown
- Win Rate
- Average Win/Loss
- Total Trades
- Volatility
- Per-asset Performance
- Add more technical indicators
- Implement portfolio optimization
- Add transaction costs and slippage
- Real-time trading capabilities
- Enhanced risk management features
- Machine learning strategy support
- More visualization options
- Performance optimization for large datasets
- Limited to yfinance data
- No support for options or futures
- Basic position sizing
- No margin trading simulation
- Historical data limitations
MIT License - see LICENSE for details
Contributions are welcome! Please feel free to submit a Pull Request.
- YFinance for market data
- Plotly and Matplotlib for visualizations
- Click for CLI interface
- Rich for terminal formatting
- All the AI tools that helped in development
This software is for educational purposes only. Trading financial instruments carries a high level of risk and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade, you should carefully consider your investment objectives, level of experience, and risk appetite.
Note: This project was developed with the assistance of AI tools. While efforts have been made to ensure accuracy and reliability, users should conduct their own testing and validation before using in any real-world applications.