Your task is to implement an RSI-based trading strategy using Nautilus Trader. You will convert a Pine Script RSI algorithm into a working Nautilus Trader strategy, run backtests, optimize parameters, and deliver results.
-
Implement the RSI Strategy (
strategies/rsi_algo_template.py)- Complete all TODO sections in the strategy template
- Implement indicator calculations (RSI)
- Implement entry logic (when RSI crosses below threshold)
- Implement exit logic (when RSI crosses above threshold)
- Optionally implement pyramid logic for adding to positions
-
Run Backtests
- Execute backtests with your implemented strategy
- Analyze performance metrics (Sharpe ratio, total return, max drawdown, etc.)
-
Optimize Parameters
- Find optimal parameter values (RSI period, entry/exit thresholds)
- Implement your own optimization method (grid search, random search, Bayesian optimization, etc.)
-
Deliver Results
- Completed strategy implementation
- Backtest results with optimized parameters
- Brief summary of your approach and findings
The following scaffolding is provided to help you get started. You may use it at your discretion, but be aware that some parts may be incomplete or have issues that you'll need to navigate around.
-
strategies/rsi_algo_template.py: Strategy template with TODO sections- Contains skeleton code and helper methods
- You must implement the core trading logic
- Some scaffolding may need fixes or adjustments
-
strategies/indicators.py: Custom indicator helper functions (ALTERNATIVE)- RSI, EMA, MACD, ATR implementations using pandas
- Note: Nautilus Trader has built-in indicators that are RECOMMENDED to use
- See
strategies/rsi_algo_template.pyfor examples of both approaches - Built-in indicators: https://nautilustrader.io/docs/latest/api_reference/indicators/
-
config/backtest_gc.yaml: Configuration file- Defines strategy parameters, venue, and data paths
- You may need to adjust paths or parameters
-
run_backtest.py: Backtest runner script- Loads config and runs backtests
- May have issues - you may need to fix data loading or other components
- Use as a reference or build your own runner
-
optimize_params.py: Parameter optimization skeleton- NOT IMPLEMENTED - you must implement your own optimization method
- Provides structure and helper functions
- Choose your optimization approach (grid search, random search, Bayesian, etc.)
-
data/: Data directory (data files available via Google Drive)- The
data/directory structure is provided - Download data files from: Google Drive Link
- Download
gc_1m.parquetandgc_1m.csvfrom the link above - Place the data files in the
data/directory after downloading - Gold futures (GC) 1-minute OHLCV data for backtesting
- The
-
requirements.txt: Python dependencies- Install with:
pip install -r requirements.txt
- Install with:
- Some code may be incomplete or broken - You may encounter errors that you'll need to debug and fix
- You're not required to use all scaffolding - Feel free to modify, rewrite, or ignore parts as needed
- Data loading may need adjustment - The data format and loading approach may require fixes but it should be fine for the most part
- Configuration may need changes - Paths, parameters, or structure may need adjustment for your setup
- Optimization is NOT implemented - You must implement your own optimization method from scratch
Your ability to navigate around issues and adapt the scaffolding is part of the assessment.
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install requirements
pip install -r requirements.txtImportant: Download the data files from the Google Drive link:
- Download data files from: Google Drive Link
- Download both
gc_1m.parquetandgc_1m.csvfiles - Place the data files in the
data/directory - Ensure the files are named exactly:
gc_1m.parquetandgc_1m.csv - Verify the files are in the correct location:
data/gc_1m.parquet
Run integration tests to verify everything is set up correctly:
# Basic integration tests (tests scaffolding structure)
python tests/test_integration.py
# Working implementation tests (tests with minimal algo logic)
python tests/test_working_implementation.pyOr with pytest:
pytest tests/test_integration.py -vTest Files:
test_integration.py: Tests that all scaffolding components can be imported and initializedtest_working_implementation.py: Tests with a working RSI implementation to verify end-to-end functionality
These tests verify:
- Data file exists and is readable
- Configuration loads correctly
- Instruments can be created
- Data can be loaded and converted to bars
- Strategy can be initialized
- Backtest engine can be set up
- Working implementation: RSI calculation, strategy execution, trade generation
- Components work together end-to-end
Note:
test_working_implementation.pyincludes a minimal working RSI strategy implementation to prove everything works- The actual
rsi_algo_template.pystill has TODOs for you to implement - These tests help verify your setup and may reveal issues with the scaffolding that you'll need to fix
- Read
strategies/rsi_algo_template.pyto understand the structure - Indicators: Choose between Nautilus built-in indicators (recommended) or custom pandas-based indicators
- Built-in: See https://nautilustrader.io/docs/latest/api_reference/indicators/
- Custom: Check
strategies/indicators.pyfor available helper functions
- Review
config/backtest_gc.yamlfor configuration options - Examine
run_backtest.pyto understand how backtests are run
Start with strategies/rsi_algo_template.py:
- TODO 1: Compute RSI indicator from price data
- TODO 2: Implement long entry logic (RSI crosses below entry threshold)
- TODO 3: Implement pyramid logic (optional - adding to positions)
- TODO 4: Implement exit logic (RSI crosses above exit threshold)
- BONUS: Implement RSI divergence detection
Try running a backtest:
python run_backtest.pyIf you encounter errors, debug and fix them. This is expected and part of the challenge.
Implement your optimization method in optimize_params.py:
- Choose an approach (grid search, random search, Bayesian optimization, etc.)
- Define parameter ranges to explore
- Run optimization to find best parameters
- Document your approach
Review backtest performance:
- Sharpe ratio
- Total return
- Maximum drawdown
- Win rate
- Number of trades
The strategy should implement the following logic (from Pine Script RSI Algo V4):
- Entry: Enter long when RSI crosses below
long_entrythreshold (oversold condition) - Exit: Exit long when RSI crosses above
long_exitthreshold (overbought condition) - Pyramid: Optionally add to positions when conditions are met (if enabled)
- Position Sizing: Use
base_qtyfor initial positions, respectmax_positionlimit
The data file (data/gc_1m.parquet) contains:
- timestamp: Datetime index
- open, high, low, close: Price data (float)
- volume: Volume data (int)
Data is 1-minute bars for Gold Futures (GC) continuous contract.
Refer to the official documentation for API details:
- Strategies: https://nautilustrader.io/docs/latest/strategies/
- Backtesting: https://nautilustrader.io/docs/latest/backtesting/
- Data: https://nautilustrader.io/docs/latest/data/
Issue: Import errors or missing modules
- Solution: Ensure virtual environment is activated and dependencies are installed
- Check
requirements.txtfor all required packages
Issue: Data file not found
- Solution: Download data files from Google Drive Link and place them in the
data/directory - Verify
data/gc_1m.parquetexists after downloading the data files - Check path in
config/backtest_gc.yamlis correct
Issue: Strategy not executing or no trades
- Solution: Debug your implementation
- Check that indicators are calculated correctly
- If using built-in indicators: Ensure
indicator.initializedis True before accessing values - If using custom indicators: Ensure you have enough data (len(prices) >= period)
- If using built-in indicators: Ensure
- Verify entry/exit logic is working
- Review logs for errors
Issue: Optimization script errors
- Solution: You must implement the optimization method yourself
- The skeleton is provided but not functional
Issue: Configuration errors
- Solution: Review
config/backtest_gc.yamlstructure - Adjust paths, parameters, or structure as needed
Upon completion, provide:
-
Completed strategy (
strategies/rsi_algo_template.py)- All TODOs implemented
- Strategy executes without errors
- Generates trades and produces results
-
Optimization implementation (
optimize_params.py)- Your chosen optimization method implemented
- Documentation of approach
- Results with optimal parameters
-
Backtest results
- Performance metrics with optimized parameters
- Summary of findings
-
Brief report (optional but recommended)
- Implementation approach
- Key decisions and trade-offs
- Results and analysis
- Any issues encountered and how you resolved them
- Start simple: Get basic entry/exit working before adding complexity
- Test incrementally: Verify each component works before moving on
- Read the docs: Nautilus Trader documentation is comprehensive
- Debug systematically: Use logging and print statements to understand execution flow
- Don't be afraid to modify scaffolding: Adapt code to your needs
- Focus on correctness: A simple working strategy is better than a complex broken one
If you have questions about:
- Nautilus Trader API: Refer to official documentation
- Strategy logic: Review the template comments and Pine Script reference
- Data format: Check the parquet file structure
- Implementation approach: Use your best judgment and adapt as needed
Good luck!