Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0.582 Tracking Error 0.178 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
from AlgorithmImports import * class MovingAverageCrossAlgorithm(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(2018, 1, 1) self.SetEndDate(datetime.now()) self.SetCash(100000) self.symbols = ["TSLA", "AAPL", "TLT", "SPY"] for symbol in self.symbols: self.AddEquity(symbol, Resolution.Hour) self.fast = self.SMA(symbol, 8, Resolution.Hour) self.slow = self.SMA(symbol, 200, Resolution.Hour) self.previous = None def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.''' # wait for our slow ema to fully initialize if not self.slow.IsReady: return holdings = self.Portfolio[self.symbols].Quantity weight = len(self.symbols) # we only want to go long if we're currently short or flat if holdings <= 0: # if the fast is greater than the slow, we'll go long if self.fast.Current.Value > self.slow.Current.Value: #*(1 + tolerance): #self.Log("BUY >> {0}".format(self.Securities[self.ticker].Price)) for symbol in self.symbols: self.SetHoldings(symbol, 1.0) # we only want to liquidate if we're currently long # if the fast is less than the slow we'll liquidate our long if holdings > 0 and self.fast.Current.Value < self.slow.Current.Value: #self.Log("SELL >> {0}".format(self.Securities[self.ticker].Price)) for symbol in self.symbols: self.Liquidate(symbol) self.previous = self.Time