| Overall Statistics |
|
Total Trades 152 Average Win 1.12% Average Loss -0.82% Compounding Annual Return 267.335% Drawdown 14.900% Expectancy 0.431 Net Profit 29.695% Sharpe Ratio 3.085 Loss Rate 39% Win Rate 61% Profit-Loss Ratio 1.36 Alpha 3.353 Beta -144.037 Annual Standard Deviation 0.352 Annual Variance 0.124 Information Ratio 3.039 Tracking Error 0.352 Treynor Ratio -0.008 Total Fees $0.00 |
import decimal
import pandas as pd
from datetime import datetime, timedelta
class FXMomentumAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 7)
self.SetEndDate(2019, 3, 20)
self.SetCash(100000)
# create a dictionary to store momentum indicators for all symbols
self.data = {}
self.period = 7
slowperiod = 60
self.symbol2 = ["NZDJPY"] #need to add EURAUD buy and AUDCHF sell...
self.symbols = ["GBPJPY"]
self.symbol3 = ["EURJPY"] #for nzdchf pair remember to do psar < bolband < price and viceversa
#"NZDJPY", "GBPJPY", "EURJPY". keeping my eye on ranked in order of sharpe ratio.
# warm up the MOM indicator
self.SetWarmUp(slowperiod)
for symbol in self.symbols:
self.AddForex(symbol, Resolution.Minute, Market.Oanda)
#self.atr = self.ATR(symbol, period, Resolution.Hour)
self.psar = self.PSAR(symbol, 0.017, 0.005, 0.2, Resolution.Hour) #lowering the start value has raised my win% and lowered my trade count., don't change the start value any lower than 0.013
#best values for nzdchf so far are psar 0.015-7 , 0.015, 0.2 and BB 20, 1.75
#best values for shorting are 0.01, 0.01, 0.2 for psar and 20, 2, for bolb
self.Bolband = self.BB(symbol, 20, 2, MovingAverageType.Simple, Resolution.Hour) #initial values 13,2 raising this has raised my profit/loss :D
self.chfSpr = False
if self.Securities[symbol].AskPrice - self.Securities[symbol].BidPrice <= 0.05:
self.chfSpr = True
for symbols2 in self.symbol2:
self.AddForex(symbols2, Resolution.Minute, Market.Oanda)
#self.atr2 = self.ATR(symbol, period, Resolution.Hour) #first i need to practice shorting in down markets cause its COMING!!
self.psar2 = self.PSAR(symbols2, 0.01, 0.015, 0.2, Resolution.Hour) #initial values 0.015 and 0.005,try lowering these one at a time i guess.
self.Bolband2 = self.BB(symbols2, 20, 2, MovingAverageType.Simple, Resolution.Hour) #initial values 13,2 raising this has raised my profit/loss :D, lowering the 2 to 1.60 has gotten me into more trades
self.jpySpr = False
if self.Securities[symbols2].AskPrice - self.Securities[symbols2].BidPrice <= 0.05:
self.jpySpr = True
for symbols3 in self.symbol3:
self.AddForex(symbols3, Resolution.Minute, Market.Oanda)
#self.atr = self.ATR(symbol, period, Resolution.Hour)
self.psar3 = self.PSAR(symbols3, 0.006, 0.02, 0.2, Resolution.Hour) #lowering the start value has raised my win% and lowered my trade count., don't change the start value any lower than 0.013
#best values for nzdchf so far are psar 0.015-7 , 0.015, 0.2 and BB 20, 1.75
#best values for shorting are 0.01, 0.01, 0.2 for psar and 20, 2, for bolb
self.Bolband3 = self.BB(symbols3, 20, 2, MovingAverageType.Simple, Resolution.Hour) #initial values 13,2 raising this has raised my profit/loss :D
self.eurSpr = False
if self.Securities[symbols3].AskPrice - self.Securities[symbols3].BidPrice <= 0.05:
self.eurSpr = True
def OnData(self, data):
for symbol in self.symbols:
if not self.psar.IsReady:
return
for symbols2 in self.symbol2:
if not self.psar2.IsReady:
return
for symbols3 in self.symbol3:
if not self.psar3.IsReady:
return
if self.IsWarmingUp: return
holdings = self.Portfolio[symbol].Quantity
holdings2 = self.Portfolio[symbols2].Quantity
for symbol in self.symbols:
#self.Log("holdings are : " + str(holdings))
if not self.Portfolio[symbol].IsLong and self.chfSpr:
if self.psar.Current.Value <= self.Bolband.MiddleBand.Current.Value <= self.Securities[symbol].Price:
#self.Log("holdings should be 0: " + str(holdings) + " and invested should be False:" + str(self.Portfolio[symbol].Invested))
self.SetHoldings(symbol, 2.5)
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("Market Order " + str(self.Securities[symbol].Price) + " for " + str(self.Securities[symbol]))
elif self.Portfolio[symbol].IsLong and self.chfSpr:
if self.psar.Current.Value >= self.Bolband.UpperBand.Current.Value >= self.Securities[symbol].Price:
#self.Log("holdings should be below 0: " + str(holdings) + " and invested should be True:" + str(self.Portfolio[symbol].Invested))
#self.MarketOrder(symbol, 150000)
self.Liquidate()
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("PSAR below price, buying " + str(self.Securities[symbol].Price) + " for " + str(self.Securities[symbol]))
for symbols2 in self.symbol2:
#self.Log("holdings are : " + str(holdings2))
if not self.Portfolio[symbols2].IsLong and self.jpySpr:
if self.psar2.Current.Value <= self.Securities[symbols2].Price <= self.Bolband2.MiddleBand.Current.Value:
#self.Log("holdings should be 0: " + str(holdings2) + " and invested should be False:" + str(self.Portfolio[symbols2].Invested))
self.SetHoldings(symbols2, 2.5)
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("Market Order " + str(self.Securities[symbols2].Price) + " for " + str(self.Securities[symbols2]))
elif self.Portfolio[symbols2].IsLong and self.jpySpr:
self.Log("not short, checking for shorting condition")
if self.psar2.Current.Value >= self.Securities[symbols2].Price >= self.Bolband2.UpperBand.Current.Value:
#self.Log("holdings should be below 0: " + str(holdings2) + " and invested should be True:" + str(self.Portfolio[symbols2].Invested))
#self.MarketOrder(symbols2, -150000)
self.Liquidate()
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("PSAR below price, buying " + str(self.Securities[symbols2].Price) + " for " + str(self.Securities[symbols2]))
for symbols3 in self.symbol3:
#self.Log("holdings are : " + str(holdings2))
if not self.Portfolio[symbols3].IsLong and self.eurSpr:
if self.psar3.Current.Value <= self.Securities[symbols3].Price <= self.Bolband3.MiddleBand.Current.Value:
#self.Log("holdings should be 0: " + str(holdings2) + " and invested should be False:" + str(self.Portfolio[symbols2].Invested))
self.SetHoldings(symbols3, 2.5)
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("Market Order " + str(self.Securities[symbols2].Price) + " for " + str(self.Securities[symbols2]))
elif self.Portfolio[symbols3].IsLong and self.eurSpr:
self.Log("not short, checking for shorting condition")
if self.psar3.Current.Value >= self.Securities[symbols3].Price >= self.Bolband3.UpperBand.Current.Value:
#self.Log("holdings should be below 0: " + str(holdings2) + " and invested should be True:" + str(self.Portfolio[symbols2].Invested))
#self.MarketOrder(symbols2, -150000)
self.Liquidate()
self.Log("Settled Cash: " + str(self.Portfolio.Cash))
#self.Log("PSAR below price, buying " + str(self.Securities[symbols2].Price) + " for " + str(self.Securities[symbols2]))