Welcome to The QuantConnect Research Page

Refer to this page for documentation https://www.quantconnect.com/docs#Introduction-to-Jupyter

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

QuantBook Basics

Start QuantBook

  • Load "QuantConnect.csx" with all the basic imports
  • Create a QuantBook instance

In [ ]:
#load "QuantConnect.csx"
using QuantConnect.Data.Custom;
using QuantConnect.Data.Market;
var qb = new QuantBook();

Selecting Asset Data

Checkout the QuantConnect docs to learn how to select asset data.


In [ ]:
var spy = qb.AddEquity("SPY");
var eur = qb.AddForex("EURUSD");
var btc = qb.AddCrypto("BTCUSD");
var fxv = qb.AddData<FxcmVolume>("EURUSD_Vol", Resolution.Hour);

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.


In [ ]:
// Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution
var h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily);

In [ ]:
// Gets historical data from the subscribed assets, from the last 30 days with daily resolution
var h2 = qb.History(qb.Securities.Keys, TimeSpan.FromDays(360), Resolution.Daily);

In [ ]:
// Gets historical data from the subscribed assets, between two dates with daily resolution
var h3 = qb.History(btc.Symbol, new DateTime(2014,1,1), DateTime.Now, Resolution.Daily);

In [ ]:
// Only fetchs historical data from a desired symbol
var h4 = qb.History(spy.Symbol, 360, Resolution.Daily);

In [ ]:
// Only fetchs historical data from a desired symbol
var h5 = qb.History<QuoteBar>(eur.Symbol, TimeSpan.FromDays(360), Resolution.Daily);

In [ ]:
// Fetchs custom data
var h6 = qb.History<FxcmVolume>(fxv.Symbol, TimeSpan.FromDays(360));