Hi!

I've managed to attach custom data to my code using csv from google drive. It works correctly in a simple Buy and Hold strategy. Unfortunately, when I want to add rolling window to my data, I get this error:

  1. Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'converter.Data'>) method. Please checkout the API documentation.
  2. at OnData
  3. self.prevPrices[symbol].Add( data[symbol] )
  4. at Python.Runtime.PythonException.ThrowLastAsClrException()
  5. at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 56

Do you have any idea what could be causing this and how to solve this issue? I found out that this type of error has been mentioned before: https://www.quantconnect.com/forum/discussion/11553/rolling-window-not-working-lean-locally/p1 but without any final solution.
 

  1. # region imports
  2. from AlgorithmImports import *
  3. class MyCustomDataType(PythonData):
  4. def GetSource(self,
  5. config: SubscriptionDataConfig,
  6. date: datetime,
  7. isLive: bool) -> SubscriptionDataSource:
  8. return SubscriptionDataSource("http//link=csv", SubscriptionTransportMedium.RemoteFile)
  9. def Reader(self,
  10. config: SubscriptionDataConfig,
  11. line: str,
  12. date: datetime,
  13. isLive: bool) -> BaseData:
  14. if not (line.strip()):
  15. return None
  16. index = MyCustomDataType()
  17. index.Symbol = config.Symbol
  18. try:
  19. data = line.split(',')
  20. index.Time = datetime.strptime(data[0], "%Y%m%d %H:%M")
  21. print (index.Time)
  22. index.EndTime = index.Time + timedelta(days=1)
  23. index.Value = float (data[4])
  24. index["open"] = float(data[1])
  25. index["close"] = float(data[6])
  26. except ValueError as a:
  27. print (a)
  28. # Do nothing
  29. return None
  30. return index
  31. class CustomIndexStrategy(QCAlgorithm):
  32. def Initialize(self):
  33. self.Pair_1 = self.AddData(MyCustomDataType, "EURSEK_DAILY", Resolution.Daily).Symbol
  34. self.holdingDays = 1
  35. self.SetStartDate (2020, 1, 1)
  36. self.SetEndDate(2022,7,1)
  37. self.SetCash(10000)
  38. self.symbols = [self.Pair_1]
  39. self.prevPrices = { symbol : RollingWindow[QuoteBar](7) for symbol in self.symbols }
  40. self.ticketPair1 = None
  41. self.ticketPair2 = None
  42. def OnData(self,data):
  43. for symbol in self.symbols:
  44. if data.ContainsKey(symbol):
  45. self.prevPrices[symbol].Add( data[symbol] )
  46. if not all([ window.IsReady for window in self.prevPrices.values() ]):
  47. return
  48. Pair1_window = self.prevPrices[self.Pair_1]
  49. Pair1_1D = Pair1_window[1].Close
  50. Pair1_0D = Pair1_window[0].Close
  51. #if self.ticketPair1 is None and self.Securities[self.Pair_1].Exchange.ExchangeOpen is True and Pair1_0D < Pair1_1D < Pair1_2D < Pair1_3D < Pair1_4D < Pair1_5D < Pair1_6D :
  52. if not self.Portfolio.Invested and Pair1_0D < Pair1_1D < Pair1_2D < Pair1_3D:
  53. self.MarketOrder(self.Pair_1, 1)
+ Expand

Author

Sebastian Wozniczka

September 2022