Hi folks,
I'm currently trying to use an external csv file saved within DropBox, to trigger intraday trading. I've cut the dataset down, as well as the code, to try to identify the issues why the code is not triggering any trading activity.
The csv file contains two rows [cut down] and no headers. Col 1 = datetime to mark the minute-level stamp that attached to the trigger [set to =1] in Col2. Example = “10/0½019 , 14:45:00” Where the comma separates the data.
I wish to use this timestamp in strftime format to trigger an intraday trade within the routine. Project attachedbut code reproduced below in case tat doesnt show. Since the csv file does contain the datestamp example above, I would expect the routine to create a link within OnData [since I have also subscribed to minutely bars]. But no such link is made and the OnData does nothing. Any ideas why this is not making the trade?
#region imports
from AlgorithmImports import *
#endregion
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 9)
self.SetEndDate(2019, 1, 11)
self.SetCash(100000)
self.snap = self.AddEquity("SNAP", Resolution.Minute).Symbol
self.trade = self.AddData(TradeSignal, "trade_signal", Resolution.Minute).Symbol
# self.Schedule.On(self.DateRules.EveryDay(self.snap),
# self.TimeRules.BeforeMarketClose(self.snap, 15),
# self.ExitPositions)
def OnData(self, data):
if self.trade in data:
self.SetHoldings(self.snap, 1)
# def ExitPositions(self):
# self.Liquidate()
class TradeSignal(PythonData):
def GetSource(self, config, date, isLive):
source = "https://www.dropbox.com/s/biu232j0ep33n9g/TickerUniverse.csv?dl=1"
return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);
def Reader(self, config, line, date, isLive):
data = line.split(',')
signal = TradeSignal()
try:
signal.Symbol = config.Symbol
signal.Time = datetime.strptime(data[0], "%d/%m/%Y %H:%M:%S")
signal.Trade = data[1]
except ValueError:
return None
return signal
Alun Thomas
Solved - FYI. When opening .csv files in Excel, the YYMMDD format might be misleading. I wasn't getting hits because I was setting strptime according to how I saw dates appear in Excel, which is UK format. When opening in VSCode, those same datetimes were formatted in reverse. Don't open .csv files in Excel.
Alun Thomas
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!