Key Concepts

Getting Started

Introduction

Quantitative trading is a method of trading where computer programs execute a set of defined trading rules in an automated fashion. Quants take a scientific approach to trading, applying concepts from mathematics, time series analysis, statistics, computer science, and machine learning. Compared to discretionary traders, quants can respond faster to new information and are at less risk to their emotions during trades. Since quants can concurrently trade many strategies while discretionary traders only have the mental bandwidth to trade a small number of concurrent strategies, quant traders can have more diversified portfolios.

Learn Programming

We aim to make it as easy as possible to use QuantConnect, but you still need to be able to program. The following table provides some resources to get you started:

LanguageTypeNameProducer
C# Video C# Fundamentals for Absolute BeginnersMicrosoft
C# Text C# Jump Start - Advanced ConceptsMicrosoft
C# Video Top 20 C# QuestionsMicrosoft
C# Text C# Tutorialtutorialspoint
Python Text Introduction to Financial PythonQuantConnect
Python Text/Video Introduction to PythonGoogle
Python Interactive Code Academy - PythonCode Academy
Python Text Python Pandas Tutorialtutorialspoint

Enroll in Bootcamp

Bootcamp is an online coding experience where QuantConnect team and community members teach you to write your first algorithms. Bootcamp gives you step-by-step instructions on practical and beginner-friendly topics, so it's a great way to learn LEAN. The lessons cover many topics that you use as you write your own algorithms, including universe selection, indicators, and consolidators. To get started, check out the course library.

Example Algorithm

The following snippet demonstrates how to implement an algorithm that buys and holds an S&P 500 index ETF:

using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;

namespace QuantConnect.Algorithm.CSharp
{
    // Define a trading algorithm that is a subclass of QCAlgorithm
    public class MyAlgorithm : QCAlgorithm
    {
        public override void Initialize()
        {
            // Set the start and end dates
            SetStartDate(2018, 1, 1);
            SetEndDate(2022, 6, 1);

            // Set the starting cash balance to $100,000 USD
            SetCash(100000);

            // Add data for the S&P500 index ETF
            AddEquity("SPY");
        }

        // OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        // Arguments:
        //     - Slice object keyed by symbol containing the stock data
        public override void OnData(Slice slice)
        {
            // Allocate 100% of the portfolio to SPY
            if (!Portfolio.Invested)
            {
                SetHoldings("SPY", 1);
            }
        }
    }
}
from AlgorithmImports import *

# Define a trading algorithm that is a subclass of QCAlgorithm
class MyAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        # Set start and end dates
        self.SetStartDate(2018, 1, 1)
        self.SetEndDate(2022, 6, 1)

        # Set the starting cash balance to $100,000 USD
        self.SetCash(100000)

        # Add data for the S&P500 index ETF
        self.AddEquity("SPY")

    def OnData(self, slice: Slice) -> None:
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        Arguments:
            slice: Slice object keyed by symbol containing the stock data
        '''
        # Allocate 100% of the portfolio to SPY
        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: