Back

Python QuandlImporterAlgorithm

Hi! 

I want to develop a futures strategy. I've cloned the QuandlImporterAlgorithm to get continuous futures from the SCF data set.  However, there is an error because the object doesn't have a 'close' attribute but 'settle' instead. I've found the solution written in C#, i.e. writing a subclass. How would something like this look like in Python? I'd greatly appreciate your help.

Update Backtest








In Python, we have to create a totally new class, following the example in the docs:

class QuandlFuture(PythonData):
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource(str("https://www.quandl.com/api/v3/datasets/") + str(config.Symbol) + str(".csv?order=asc&api_key=" + str(Config.Get("quandl-auth-token"))), SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
quandl_future = QuandlFuture()
quandl_future.Symbol = config.Symbol
# Example Line Format:
# Date,Open,High,Low,Settle,Volume,Prev. Day Open Interest
# 2005-01-03,43.1,43.1,41.25,42.12,69484.0,165451.0
if not (line.strip() and line[0].isdigit()): return None
try:
data = line.split(',')
value = float(data[4])
if value == 0: return None
quandl_future.Time = datetime.strptime(data[0], "%Y-%m-%d")
quandl_future.Value = decimal.Decimal(value)
quandl_future["Settle"] = value
return quandl_future;
except ValueError:
return None

In this case, we need to know which column keeps the desired field.

 

 

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.


This helps a lot. Thank you so much!

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