📅 2024-01-16 — Session: Debugged and Enhanced Backtrader Trading Strategy

🕒 15:55–16:40
🏷️ Labels: Backtrader, Debugging, Data Processing, Trading Strategy, Visualization
📂 Project: Dev
⭐ Priority: MEDIUM

Session Goal

The session aimed to debug and enhance a trading strategy using Backtrader, focusing on data fetching, error handling, and visualization.

Key Activities

  • Debugging OLSResiduals Indicator: Addressed issues with an unpopulated prices array by troubleshooting data feed loading, verifying the window period, and refining data fetching methods.
  • Implementing Robust Data Fetching: Improved the trading strategy by implementing direct data slicing for price fetching and ensuring valid log prices calculations.
  • Adjusting Code for Historical Data Access: Modified the next method and used the get method to fetch historical data accurately.
  • Handling OLS Residuals: Calculated OLS residuals from price data, handling non-positive values and ensuring error management.
  • Manual Construction of Prices Array: Created a prices array from historical close prices to resolve data fetching issues.
  • Plotting Simulation Results: Used Matplotlib to plot Backtrader simulation results, including saving plots in headless environments.
  • Advanced Plotting Techniques: Explored advanced plotting techniques, integrating financial data from Yahoo Finance, and customizing plot settings.

Achievements

  • Successfully debugged the OLSResiduals indicator and improved data fetching methods.
  • Enhanced error handling and data processing in the trading strategy.
  • Implemented advanced plotting techniques for better visualization of trading results.

Pending Tasks

  • Further testing of the modified trading strategy to ensure robustness.
  • Exploration of additional data sources for integration into Backtrader.