Back

How to refer to multiple Quandl symbols?

I can add multiple Quandl symbols in Initialize(), but how can I compare the 2 symbols in OnData()? I notice about "How Do I Ensure There Is Always Data?" code, but it seems to work for TradeBar only.

What solution available?
Update Backtest








Hey, something like this:


OnDatal(Quandl _symbol1)
{
s1 = _symbol1.Value;
}

OnDatal(Quandl _symbol2)
{
s2 = _symbol2.Value;
}

OnDatal(TradeBars data)
{
someFunc = s1/s2;
}
0

Welcome @Chee -- I'd recommend something like this:


int quandlCount = 4;
Dictionary<string, Quandl> _quandls = new Dictionary<string, Quandl>()

public void OnData(Quandl object) {
_quandls[object.Symbol] = object;
if (_quandls.Count != quandlCount) return;


//Use _quandls.
}
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


That's better with multiple symbols :)
0

I am trying to implement something similar, using two different Quandl data sources to be used in a calculation to trigger buy / sell orders. Can anyone clarify what would be in the "object" field? I feel like I am missing something obvious.

namespace QuantConnect
{
/*
* QuantConnect University: Futures Example
*
* QuantConnect allows importing generic data sources! This example demonstrates importing a futures
* data from the popular open data source Quandl.
*
* QuantConnect has a special deal with Quandl giving you access to Stevens Continuous Futurs (SCF) for free.
* If you'd like to download SCF for local backtesting, you can download it through Quandl.com.
*/
public class VolatilityETN : QCAlgorithm
{
string shortTerm = "VXX";
string longTerm = "VXZ";
decimal IVTS = new decimal();
string VIX = "YAHOO/INDEX_VIX";
string VXV = "CBOEFE/INDEX_VXV";



DateTime sampledToday = DateTime.Now;

//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
SetStartDate(2004, 1, 1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(25000);
AddSecurity(SecurityType.Equity, shortTerm, Resolution.Minute);
AddSecurity(SecurityType.Equity, longTerm, Resolution.Minute);

AddData(VXV, Resolution.Daily);
AddData(VIX, Resolution.Daily);
}


int quandlCount = 2;
Dictionary _quandls = new Dictionary();

public void OnData(Quandl object)
{
_quandls[object.Symbol] = object;
if (_quandls.Count != quandlCount) return;
//Use _quandls.
}




//Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
public void OnData(TradeBars data)
{
// add logic to have orders placed once / day

// IVTS = VIX / VXV

// Add buy/sell logic


}
}
}
0

@Reuben, you can actually do this an even better way now thanks to the "Slice" concept we recently introduced. All data is routed through a single event handler called a "time slice" -- I've attached a simple example using two quandl data types. ///
/// Event - v3.0 DATA EVENT HANDLER: Basic template for user to override for receiving all subscription data in a single event
///

/// TradeBars bars = slice.Bars;
/// Ticks ticks = slice.Ticks;
/// TradeBar spy = slice["SPY"];
/// List aaplTicks = slice["AAPL"]
/// Quandl oil = slice["OIL"]
/// dynamic anySymbol = slice[symbol];
/// DataDictionary allQuandlData = slice.Get
/// Quandl oil = slice.Get("OIL")
/// The current slice of data keyed by symbol string
public void OnData(Slice data)
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


I <3 slice... beautiful application of dynamics + static typing to make life easier.
1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This is awesome! Thanks.
0

Sorry for dredging this up again, but the quandl data invoked in the example code Michael provided contains multiple columns. What column does the property '.Value' represent, and how does it know which column to associate with?

0

Value is assumed to be Close, if there's no close it won't have a Value and you'll have to set it. See QCU algorithm "How do I import futures data?" for an example of using "Settlement" column as the Value column which we use for the trade price.

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


I see, thanks for the example Jared!
0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed