Buy and Hold Equities Boot Camp: Key Steps on QuantConnect

 9 min video

 3 min read

YouTube video ID: 5KpolDcRJic

PDF

The “Buy and Hold with Equities Boot Camp” is designed to teach the fundamentals of building a QuantConnect algorithm. Participants begin by clicking the start button, then follow a lesson layout that shows the task at the top, documentation on the left, code in the middle, and results at the bottom. The boot camp covers setting cash, defining a date range, selecting equity data, managing data normalization and leverage, checking holdings, and finally placing market orders.

Task 1 – Setting Starting Cash

The first step is to define the capital that the backtest will use. QuantConnect provides the SetCash() method, which takes a numeric amount and stores it in a cash book. By default the cash book uses U.S. dollars, but it can hold an array of different currencies, enabling forex backtesting. As the presenter notes, “QuantConnect allows you to set a starting cash that your algorithm will use in backtesting.”

Task 2 – Setting a Date Range

Next, the historical window for the simulation is specified with SetStartDate(year, month, day) and SetEndDate(year, month, day). The example sets the range from January 1 2017 to October 31 2017, ensuring that all subsequent data requests and calculations are confined to that period.

Task 3 – Manually Selecting Data (Equities)

Selecting the assets to trade is the most fundamental operation on QuantConnect. For U.S. equities the AddEquity(ticker, resolution) method is used. The method accepts a ticker symbol, a resolution enum (tick, second, minute, hour, daily), and optional parameters, and it returns a Security object for later reference. In the boot camp the minute‑resolution data for SPY is added, and the same resolution is requested for IWM. Submitting the code sends it to QuantConnect’s cloud clusters for backtesting.

Task 4 – Data Normalization and Leverage

QuantConnect’s data is adjusted by default to account for splits and dividends, which can produce many decimal places. To work with raw prices, the SetDataNormalizationMode('raw') helper is called on the security object; in raw mode splits and dividends are paid directly into the portfolio. The boot camp demonstrates this by changing SPY’s normalization mode to raw. It also shows how to set leverage with security.SetLeverage(amount), setting IWM’s leverage to 1.

Task 5 – Checking Holdings and Printing Quantity

Holdings are consolidated in the Portfolio object, which offers helpers such as Invested, TotalUnrealizedProfit, and TotalPortfolioValue. These can be accessed by ticker through a dictionary‑like interface. The exercise switches the previously added equity from SPY to IBM, then prints the number of IBM shares owned. The quantity attribute provides the share count, which must be converted to a string before passing to self.Debug() for console output.

Task 6 – Placing Orders and Using Portfolio Helpers

The final task combines all prior steps to execute a trade. After adding IWM at minute resolution and setting its data normalization mode to raw, the algorithm stores the returned security object. Inside the OnData method, a market order for 100 shares of IWM is placed with self.MarketOrder(ticker, quantity). To avoid multiple orders, the code checks Portfolio.Invested before submitting. The average fill price is retrieved via AveragePrice and printed using self.Debug(), again converting the numeric value to a string. The boot camp wraps up by reviewing data addition, normalization, portfolio access, holdings inspection, and order decision logic.

Mechanisms & Explanations

The boot camp follows a clear algorithm setup flow: start the lesson, view the summary, complete each task (cash, date range, data selection, normalization, leverage, holdings check, order placement), submit the answer, and move to the next task. Each method—SetCash, SetStartDate, SetEndDate, AddEquity, SetDataNormalizationMode, SetLeverage, Portfolio helpers, self.MarketOrder, and self.Debug—plays a specific role in constructing a functional backtesting algorithm on QuantConnect.

  Takeaways

  • The boot camp walks users through setting cash, date range, data selection, normalization, leverage, holdings checks, and order placement on QuantConnect.
  • Starting cash is defined with SetCash(), which defaults to USD but supports multiple currencies via a cash book.
  • The historical period is set using SetStartDate() and SetEndDate(), illustrated with a range from Jan 1 2017 to Oct 31 2017.
  • Adding equities with AddEquity() returns a security object, allows resolution selection (e.g., minute for SPY and IWM), and supports raw data mode via SetDataNormalizationMode('raw').
  • Market orders are placed with self.MarketOrder(), leveraging Portfolio.Invested to avoid duplicate trades and using AveragePrice and Debug for output.

Frequently Asked Questions

Who is QuantConnect on YouTube?

QuantConnect is a YouTube channel that publishes videos on a range of topics. Browse more summaries from this channel below.

Does this page include the full transcript of the video?

Yes, the full transcript for this video is available on this page. Click 'Show transcript' in the sidebar to read it.

Helpful resources related to this video

If you want to practice or explore the concepts discussed in the video, these commonly used tools may help.

Links may be affiliate links. We only include resources that are genuinely relevant to the topic.

PDF