Hello everybody, I'm working on a basic pairs trading strategy on the forex market, a little bit different than the one which Quantconnect provides on the bootcamp. 

I'm stuck in the phase where I'm trying to select the highest correlated pair among the ones that I'm working with. From the below numpy array how can I select the two currencies based on their correlation value?

  1. import numpy as np
  2. from numpy import corrcoef
  3. class LogicalTanCaribou(QCAlgorithm):
  4. def Initialize(self):
  5. self.SetStartDate(2021, 3, 1) # Set Start Date
  6. #self.SetEndDate(2021, 1, 30)
  7. self.SetCash(1000) # Set Strategy Cash
  8. self.currencies = ['EURUSD', 'USDJPY', 'GBPUSD', 'USDCAD', 'AUDUSD', 'NZDUSD', 'EURJPY']
  9. for ticker in self.currencies:
  10. self.AddForex(ticker, Resolution.Hour)
  11. self.df = self.History([self.Symbol("EURUSD"), self.Symbol("USDJPY"), self.Symbol("GBPUSD"),
  12. self.Symbol("USDCAD"), self.Symbol("AUDUSD"), self.Symbol("NZDUSD"),
  13. self.Symbol("EURJPY")], 100)
  14. if not self.df.empty:
  15. eurusd_quotebars = self.df.loc["EURUSD"]
  16. usdjpy_quotebars = self.df.loc["USDJPY"]
  17. gbpusd_quotebars = self.df.loc["GBPUSD"]
  18. usdcad_quotebars = self.df.loc["USDCAD"]
  19. audusd_quotebars = self.df.loc["AUDUSD"]
  20. nzdusd_quotebars = self.df.loc["NZDUSD"]
  21. eurjpy_quotebars = self.df.loc["EURJPY"]
  22. corr = corrcoef([eurusd_quotebars['close'], usdjpy_quotebars['close'], gbpusd_quotebars['close'],
  23. usdcad_quotebars['close'], audusd_quotebars['close'], nzdusd_quotebars['close'],
  24. eurjpy_quotebars['close']])
+ Expand

Author

SIG_94

May 2021