Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
29.091%
Drawdown
3.500%
Expectancy
0
Net Profit
2.359%
Sharpe Ratio
1.727
Probabilistic Sharpe Ratio
61.467%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.225
Beta
-0.15
Annual Standard Deviation
0.103
Annual Variance
0.011
Information Ratio
-1.164
Tracking Error
0.116
Treynor Ratio
-1.189
Total Fees
$0.00
import numpy as np
from datetime import timedelta, datetime
import decimal

class RegressionChannelAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetCash(1000000)
        self.SetStartDate(2019,10,20)
        self.SetEndDate(2019,11,20)
        slowperiod = 1000
        self.SetBenchmark('SPY')
        self.SetWarmUp(slowperiod)
        self.AddForex("AUDUSD", Resolution.Hour, Market.Oanda)
        self.AddForex("NZDUSD", Resolution.Hour, Market.Oanda)
        
    def OnData(self, data):
        if self.IsWarmingUp: return
        
        if not (data.ContainsKey("NZDUSD")):
            return
        
        NZDUSD = self.Securities["NZDUSD"].AskPrice - self.Securities["NZDUSD"].BidPrice
        AUDUSD = self.Securities["AUDUSD"].AskPrice - self.Securities["AUDUSD"].BidPrice
        spreadDelta = decimal.Decimal(NZDUSD - AUDUSD)
        liquidate = decimal.Decimal(2)
        golong = decimal.Decimal(5)
        liquidate2 = decimal.Decimal(2)
        
        #if this is negative then short audusd and buy nzdusd, if this is positive then buy audusd and short nzdusd ?
        
        if not self.Portfolio["NZDUSD"].IsLong and not self.Portfolio["AUDUSD"].IsShort:
            if spreadDelta < 0:
                self.SetHoldings("AUDUSD", -2)
                self.SetHoldings("NZDUSD", 2)
                self.Log("spreadDelta less than 0: " + str(spreadDelta))
        if self.Portfolio["NZDUSD"].IsLong and self.Portfolio["AUDUSD"].IsShort:
            self.Log("Is spreadDelta greater than 2?: " + str(spreadDelta))
            self.Log("Is spreadDelta greater than 2?: " + str(spreadDelta > liquidate))
            if spreadDelta > liquidate:
                self.SetHoldings("AUDUSD", 0)
                self.SetHoldings("NZDUSD", 0)
                self.Log("spreadDelta greater than 2: " + str(spreadDelta))
        if not self.Portfolio["NZDUSD"].IsShort and not self.Portfolio["AUDUSD"].IsLong:
            if spreadDelta >golong:
                self.SetHoldings("AUDUSD", 2)
                self.SetHoldings("NZDUSD", -2)
                self.Log("spreadDelta greater than 5: " + str(spreadDelta))
        if self.Portfolio["NZDUSD"].IsShort and self.Portfolio["AUDUSD"].IsLong:
            if spreadDelta < liquidate2:
                self.SetHoldings("AUDUSD", 0)
                self.Log("spreadDelta less than 2: " + str(spreadDelta))
                self.SetHoldings("NZDUSD", 0)