Quick Tips: Code Reuse, the Pipe Character, Dry Runs
Thu Aug 29 2024This article's tips:
- Quick Tip 1: Reuse code for multiple variants of a strategy
- Quick Tip 2: Chain multiple commands with the pipe ( | ) character
- Quick Tip 3: Dry run your Zipline or Moonshot strategy
Quick Tip 1: Reuse code for multiple variants of a strategy
Need to run multiple variants of a trading strategy, such as a large-cap variant and a mid-cap variant, or a long variant and a short variant? Don’t resort to copying and pasting the same code into multiple files, which is error-prone and hard to maintain. Moonshot and Zipline offer a better approach: use inheritance to create multiple variants of the same strategy without code duplication.
Learn more about code reuse in Zipline or Moonshot.
Quick Tip 2: Chain multiple commands with the pipe ( | ) character
The pipe character ( | ) allows you to chain two or more commands together, sending the output of one command as the input to the next command. Using Moonshot with pipes, you can send your trading strategy’s orders to the broker for execution or to the logs for troubleshooting or review.
Quick Tip 3: Dry run your Zipline or Moonshot strategy
With Zipline's "dry run" option, you can write orders to a file instead of sending them to your broker. This lets you troubleshoot your strategy without placing orders, manually inspect orders before placing them, or generate orders for manual execution outside QuantRocket. Learn more about dry runs with Zipline.
Similar functionality is available for Moonshot.
About QuantRocket
QuantRocket is a Python-based platform for researching, backtesting, and trading quantitative strategies. It provides a JupyterLab environment, offers a suite of data integrations, and supports multiple backtesters: Zipline, the open-source backtester that originally powered Quantopian; Alphalens, an alpha factor analysis library; Moonshot, a vectorized backtester based on pandas; and MoonshotML, a walk-forward machine learning backtester. Built on Docker, QuantRocket can be deployed locally or to the cloud and has an open architecture that is flexible and extensible.
Learn more or install QuantRocket now to get started.