First off I want to state that I have already read the Documentation on Importing custom data and it sadly has not helped me.
I am having trouble implementing a csv file in my algorithm that consists of the columns INDEX,DATETIME,CLOSE.
I want to Access the DATETIME on a minute basis and buy/sell an FX Pair when the CLOSE in my csv has a certain value
I have tried the AddData() method but I think since it requires a “ticker string” argument and my data is not data from a specific ticker it has not been successful.
class Futures_CSV(QCAlgorithm):
def Initialize(self):
self.SetCash(100000)
self.SetStartDate(2021, 6, 1)
self.SetTimeZone('America/New_York')
#CAD Futureshttps://www.quantconnect.com/project/8692527#
self.symbol = self.AddData(Difference, "Difference", Resolution.Minute).Symbol
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.AddForex("USDCAD", Resolution.Minute, Market.Oanda)
def OnData(self, data):
if data.ContainsKey(self.symbol):
self.Plot("Difference", "CLOSE", data[self.symbol].Close)
#Entry
if self.symbol <= -0.0015 and not self.Portfolio.Invested:
self.SetHoldings("USDCAD", -10)
elif self.symbol >= 0.0015 and not self.Portfolio.Invested:
self.SetHoldings("USDCAD", 10)
else:
pass
#Exit
if self.Portfolio["USDCAD"].IsLong and difference.Value <= 0:
self.Liquidate()
elif self.Portfolio["USDCAD"].IsShort and difference.Value >= 0:
self.Liquidate()
else:
pass
class Difference(PythonData):
def GetSource(self, config, date, isLive):
source = "https://raw.githubusercontent.com/LeonidNID/test/master/Difference_MINUTES_SHORTENED.csv?token=ALPEJH5MWEXBOP4PF6JDAM3A3XO2O"
return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);
def Reader(self, config, line, date, isLive):
# If first character is not digit, pass
if not (line.strip() and line[0].isdigit()): return None
data = line.split(',')
difference = Difference()
difference.Symbol = config.Symbol
difference.Time = datetime.strptime(data[1], '%Y-%m%-dT%h:%M:%s')
difference.Value = float(data[2])
difference["CLOSE"] = float(data[2])
return difference
This is my buggy code I have now (This throws up the error: in main.py:line 23 TypeError : Cannot get managed object)
I hope one of the more experienced members can help me, thanks in advance!
Vladimir
Leonid,
I think there is no data in your source
https://raw.githubusercontent.com/LeonidNID/test/master/Difference_MINUTES_SHORTENED.csv?token=ALPEJH5MWEXBOP4PF6JDAM3A3XO2O
404: Not Found
Leonid
Hello Vladimir,
That might have been a problem because my source was private, now I have a public repository from which I import my data but still get the same error
Louis Szeto
Hi Leonid
Please check carefully on your code vs documentation. data[self.symbol].Close, self.symbol, difference.Value should all refer to data[self.symbol].Value or data[self.symbol].GetProperty('Close')
Also, strptime format should be '%Y-%m-%dT%H:%M:%S'. Please check these careless mistakes carefully
Cheers
Louis
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.
Leonid
Hi Louis,
Okay that worked, thank you for your answer!
And sorry for that “carelessness”, I am pretty much brand new to programming and have nobody to help me.
Louis Szeto
No worries, I've there too. QC has a good Debug tool to check, practice more to get familiar ;)
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.
Leonid
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!