📅 2024-01-16 — Session: Debugged and Enhanced Backtrader Trading Strategy
🕒 15:55–16:40
🏷️ Labels: Backtrader, Debugging, Data Processing, Trading Strategy, Python
📂 Project: Dev
⭐ Priority: MEDIUM
Session Goal
The primary goal of this session was to debug and enhance a trading strategy using Backtrader, focusing on the OLSResiduals
indicator and data fetching methods.
Key Activities
- Debugging OLSResiduals Indicator: Addressed an issue with an unpopulated
prices
array in thenext
method by checking data feed loading and refining data fetching methods. - Improving Data Fetching: Implemented robust data fetching techniques, including direct data slicing for price fetching and ensuring valid log prices calculations.
- Handling Data Feed Issues: Explored solutions for empty data feeds in the
ResidualsStrategy
class, emphasizing data loading timing and method usage. - Adjusting Historical Data Access: Modified the Backtrader code to use the
get
method for historical data access and adjusted thenext
method for theOLSResiduals
indicator. - Error Handling in Price Data Processing: Calculated OLS residuals from price data, handling non-positive values and ensuring error management during logarithm calculations.
- Manual Construction of Prices Array: Constructed a prices array from historical close prices in the strategy, ensuring proper error handling.
- Advanced Plotting Techniques: Implemented advanced plotting techniques in Backtrader, including plotting multiple data feeds and customizing observers.
Achievements
- Successfully debugged the
OLSResiduals
indicator and improved data fetching methods. - Enhanced error handling in price data processing.
- Developed advanced plotting capabilities for Backtrader simulations.
Pending Tasks
- Further testing of the updated trading strategy to ensure robustness.
- Integration of additional financial data sources for comprehensive analysis.