About CFD Data

The CFD Data by OANDA serves 269 contracts for differences (CFD). The data starts as early as May 2002 and is delivered on any frequency from tick to daily. This dataset is created by QuantConnect processing raw tick data from OANDA.


OANDA was co-founded by Dr. Stumm, a computer scientist and Dr. Olsen, an economist, in 1997. The company was born out of the belief that the Internet and technology would open up the markets for both currency data and trading. OANDA uses innovative computer and financial technology to provide Internet-based forex trading and currency information services to everyone, from individuals to large corporations, from portfolio managers to financial institutions. OANDA is a market maker and a trusted source for currency data. It has access to one of the world's largest historical, high-frequency, filtered currency databases.

About QuantConnect

QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.

Algorithm Example

class SMAPairsTrading(QCAlgorithm):

    def Initialize(self) -> None:
        self.SetStartDate(2018, 7, 1)   
        self.SetEndDate(2019, 3, 31)
        self.AddCfd('XAUUSD', Resolution.Hour);
        self.AddCfd('XAGUSD', Resolution.Hour);

        self.pair = [ ]
        self.spreadMean = SimpleMovingAverage(500)
        self.spreadStd = StandardDeviation(500)
    def OnData(self, slice: Slice) -> None:
        spread = self.pair[1].Price - self.pair[0].Price
        self.spreadMean.Update(self.Time, spread)
        self.spreadStd.Update(self.Time, spread) 
        upperthreshold = self.spreadMean.Current.Value + self.spreadStd.Current.Value
        lowerthreshold = self.spreadMean.Current.Value - self.spreadStd.Current.Value

        if spread > upperthreshold:
            self.SetHoldings(self.pair[0].Symbol, 1)
            self.SetHoldings(self.pair[1].Symbol, -1)
        if spread < lowerthreshold:
            self.SetHoldings(self.pair[0].Symbol, -1)
            self.SetHoldings(self.pair[1].Symbol, 1)
    def OnSecuritiesChanged(self, changes: SecurityChanges) -> None:
        self.pair = [x for x in changes.AddedSecurities]
        #1. Call for 500 bars of history data for each symbol in the pair and save to the variable history
        history = self.History([x.Symbol for x in self.pair], 500)
        #2. Unstack the Pandas data frame to reduce it to the history close price
        history = history.close.unstack(level=0)
        #3. Iterate through the history tuple and update the mean and standard deviation with historical data 
        for tuple in history.itertuples():
            self.spreadMean.Update(tuple[0], tuple[2]-tuple[1])
            self.spreadStd.Update(tuple[0], tuple[2]-tuple[1])

Example Applications

The CFD price data enables you to trade CFD assets in your algorithm. Examples include the following strategies: