Overall Statistics |
Total Trades 83 Average Win 0.08% Average Loss -0.08% Compounding Annual Return -8.514% Drawdown 1.000% Expectancy -0.184 Net Profit -0.478% Sharpe Ratio -3.757 Probabilistic Sharpe Ratio 14.816% Loss Rate 59% Win Rate 41% Profit-Loss Ratio 0.97 Alpha -0.025 Beta 0.083 Annual Standard Deviation 0.025 Annual Variance 0.001 Information Ratio 3.927 Tracking Error 0.194 Treynor Ratio -1.155 Total Fees $83.00 |
from datetime import datetime, timedelta from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Indicators") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * from QuantConnect.Data.Market import * from QuantConnect.Data.Consolidators import * class DataConsolidationAlgorithm(QCAlgorithm): def Initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.SetStartDate(2016,1,1) #Set Start Date self.SetEndDate(2016,1,20) #Set End Date # Find more symbols here: http://quantconnect.com/data #self.AddForex("EURUSD", Resolution.Minute, Market.Oanda) self.AddEquity("SPY", Resolution.Minute) thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30)) thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler self.SubscriptionManager.AddConsolidator("SPY", thirtyMinuteConsolidator) self.macd = self.MACD("SPY", 12, 26, 9, MovingAverageType.Exponential) self.RegisterIndicator("SPY", self.macd, thirtyMinuteConsolidator) def ThirtyMinuteBarHandler(self, sender, bar): '''This is our event handler for our 30-minute trade bar defined above in Initialize(). So each time the consolidator produces a new 30-minute bar, this function will be called automatically. The sender parameter will be the instance of the IDataConsolidator that invoked the event ''' #self.Debug(str(self.Time) + " " + str(bar)) if not self.macd.IsReady: return if self.Portfolio["SPY"].Quantity == 0 and self.macd.Current.Value > self.macd.Signal.Current.Value: self.Buy("SPY",100) print("MACD VALUE :",self.macd.Current.Value) print("SIGNAL VALUE :",self.macd.Signal.Current.Value) elif self.Portfolio["SPY"].Quantity > 0 and self.macd.Current.Value < self.macd.Signal.Current.Value: self.Liquidate() print("MACD VALUE :",self.macd.Current.Value) print("SIGNAL VALUE :",self.macd.Signal.Current.Value) #self.Plot("Charting", "MACD",self.macd) def OnData(self, data): pass