Back to Lean

BasicCSharpQuantBookTemplate

Research/BasicCSharpQuantBookTemplate.ipynb

2.4.0.11.4 KB
Original Source

Welcome to The QuantConnect Research Page

Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#

Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicCSharpQuantBookTemplate.ipynb

QuantBook Basics

Start QuantBook

  • Load "../QuantConnect.csx" with all the basic imports
  • Create a QuantBook instance
C#
// We need to load assemblies at the start in their own cell
#load "../Initialize.csx"
C#
#load "../QuantConnect.csx"

using QuantConnect;
using QuantConnect.Data;
using QuantConnect.Research;
using QuantConnect.Algorithm;

var qb = new QuantBook();

// Selecting asset data
var spy = qb.AddEquity("SPY");
var eur = qb.AddForex("EURUSD");
var btc = qb.AddCrypto("BTCUSD");

Historical Data Requests

We can use the QuantConnect API to make Historical Data Requests. The data will be presented as multi-index pandas.DataFrame where the first index is the Symbol.

For more information, please follow the link.

C#
// Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution
var h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily);
Console.WriteLine(string.Join(",", h1.SelectMany(slice => slice.Keys).Distinct()))