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?
+ Expand
import numpy as np
from numpy import corrcoef
class LogicalTanCaribou(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 3, 1) # Set Start Date
#self.SetEndDate(2021, 1, 30)
self.SetCash(1000) # Set Strategy Cash
self.currencies = ['EURUSD', 'USDJPY', 'GBPUSD', 'USDCAD', 'AUDUSD', 'NZDUSD', 'EURJPY']
for ticker in self.currencies:
self.AddForex(ticker, Resolution.Hour)
self.df = self.History([self.Symbol("EURUSD"), self.Symbol("USDJPY"), self.Symbol("GBPUSD"),
self.Symbol("USDCAD"), self.Symbol("AUDUSD"), self.Symbol("NZDUSD"),
self.Symbol("EURJPY")], 100)
if not self.df.empty:
eurusd_quotebars = self.df.loc["EURUSD"]
usdjpy_quotebars = self.df.loc["USDJPY"]
gbpusd_quotebars = self.df.loc["GBPUSD"]
usdcad_quotebars = self.df.loc["USDCAD"]
audusd_quotebars = self.df.loc["AUDUSD"]
nzdusd_quotebars = self.df.loc["NZDUSD"]
eurjpy_quotebars = self.df.loc["EURJPY"]
corr = corrcoef([eurusd_quotebars['close'], usdjpy_quotebars['close'], gbpusd_quotebars['close'],
usdcad_quotebars['close'], audusd_quotebars['close'], nzdusd_quotebars['close'],
eurjpy_quotebars['close']])
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!