| Overall Statistics |
|
Total Trades 5 Average Win 0.07% Average Loss -0.05% Compounding Annual Return 52.960% Drawdown 0.100% Expectancy -0.211 Net Profit 0.121% Sharpe Ratio 11.225 Probabilistic Sharpe Ratio 0% Loss Rate 67% Win Rate 33% Profit-Loss Ratio 1.37 Alpha 0.306 Beta 1.261 Annual Standard Deviation 0.014 Annual Variance 0 Information Ratio 97.356 Tracking Error 0.003 Treynor Ratio 0.121 Total Fees $39.36 |
class CalibratedVerticalCoil(QCAlgorithm):
signal = None
amount = None
orderstat = None
takeprofit = None
#numperiods = 10
#b = 0
def Initialize(self):
self.SetStartDate(2019, 11, 1) # Set Start Date
self.SetEndDate(2019, 11, 2)
self.SetCash(100000) # Set Strategy Cash
# self.AddEquity("SPY", Resolution.Minute)
self.AddForex("USDCAD", Resolution.Minute, Market.FXCM )
self.SetBrokerageModel(BrokerageName.FxcmBrokerage , AccountType.Cash)
self.Consolidate("USDCAD", Resolution.Tick, TickType.Trade, self.OnDataConsolidated)
self.slowA = ExponentialMovingAverage(50)
self.slowB = ExponentialMovingAverage(50)
self.superslowA = ExponentialMovingAverage(720)
self.superfastA = ExponentialMovingAverage(2)
self.superslowB = ExponentialMovingAverage(720)
self.superfastB = ExponentialMovingAverage(2)
self.fastA = ExponentialMovingAverage(100)
self.fastB = ExponentialMovingAverage(100)
self.mybar = None
self.SetBenchmark("USDCAD")
self.Securities["USDCAD"].SetLeverage(1)
#self.consolidator5 = QuoteBarConsolidator(5)
#self.slow5min = ExponentialMovingAverage(73)
#self.fast5min = ExponentialMovingAverage(2)
#self.SubscriptionManager.AddConsolidator("USDCAD", self.consolidator5)
#self.RegisterIndicator("USDCAD", self.slow5min, self.consolidator5)
#self.RegisterIndicator("USDCAD", self.fast5min, self.consolidator5)
self.SetWarmUp(700)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data'''''
tolerance = 0.0005
if self.fastA is None :
return
self.Debug(str(self.fastA))
if self.IsWarmingUp: return
#if not self.slow5min.IsReady or not self.fast5min.IsReady:
# return
#if self.slow5min.Current.Value < self.fast5min.Current.Value:
# self.Liquidate()
#if self.slow5min.Current.Value > self.fast5min.Current.Value:
# self.SetHoldings("USDCAD", 1.0)
if self.superfastA.Current.Value < self.superslowA.Current.Value:
if self.signal == 2 or self.signal == None:
self.Debug("Covering Short And/Or Buying! Time is:"+str(self.Time)+"Signal is:" +str(self.signal))
orderprice = self.Securities["USDCAD"].Price
self.amount = round(0.90 * self.Portfolio.GetBuyingPower("USDCAD", OrderDirection.Sell), -3)
self.LimitOrder("USDCAD", -self.amount, orderprice)
#self.Liquidate()
#self.SetHoldings("USDCAD", -1.0)
self.signal = 1
if self.superfastB.Current.Value > self.superslowB.Current.Value:
if self.signal == 1 or self.signal == None:
self.Debug("Shorting! Time: "+str(self.Time))
self.amount = round(0.90 * self.Portfolio.GetBuyingPower("USDCAD", OrderDirection.Buy), -3)
orderprice = self.Securities["USDCAD"].Price
self.LimitOrder("USDCAD", self.amount, orderprice)
#self.Liquidate()
self.SetHoldings("USDCAD", 1.0)
#self.Liquidate()
#if self.signal == None or self.signal == 1:
#self.SetHoldings("USDCAD", 1.0)
self.signal = 2
self.takeprofit = orderprice * 1.001
self.Debug("Created Buy Limit Order: " +str(self.amount)+"Price:"+str(orderprice)+str())
slippage = self.mybar.Ask.Close / self.mybar.Bid.Close
#self.Debug("Slippage is:"+str(slippage))
if self.takeprofit is None:
return
else:
if self.Securities["USDCAD"].Price >= self.takeprofit :
self.Liquidate()
self.PlotIndicator("EMAA", self.slowA, self.fastA, self.superfastA, self.superslowA)
self.PlotIndicator("EMAB", self.slowB, self.fastB, self.superfastB, self.superslowB)
#self.Plot("EREMA", EREMA)
def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
self.orderstat = OrderStatus.Filled
if orderEvent.Status == OrderStatus.Filled:
self.Log("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent)+"///RESULTS:"+str(self.Portfolio["USDCAD"].LastTradeProfit)+"TotalProfit:"+ str(self.Portfolio.TotalProfit))
def OnDataConsolidated(self, bar):
self.mybar = bar
self.fastA.Update(bar.Time, bar.Ask.Close)
self.slowA.Update(bar.Time, bar.Ask.Close)
self.fastB.Update(bar.Time, bar.Bid.Close)
self.slowB.Update(bar.Time, bar.Bid.Close)
self.superslowB.Update(bar.Time, bar.Bid.Close)
self.superfastB.Update(bar.Time, bar.Bid.Close)
self.superslowA.Update(bar.Time, bar.Bid.Close)
self.superfastA.Update(bar.Time, bar.Bid.Close)
return
# Create a class to group our indicators
# Set the constructer __init__ that takes the parameter self
def __init__(self):
return
# Save the indicator to self.ema