* t status pep8 conversion * Minor tweaks and rebase * Various minor fixes --------- Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
This commit is contained in:
@@ -22,37 +22,37 @@ from AlgorithmImports import *
|
||||
### <meta name="tag" content="plotting indicators" />
|
||||
class RegressionChannelAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
def initialize(self):
|
||||
|
||||
self.SetCash(100000)
|
||||
self.SetStartDate(2009,1,1)
|
||||
self.SetEndDate(2015,1,1)
|
||||
self.set_cash(100000)
|
||||
self.set_start_date(2009,1,1)
|
||||
self.set_end_date(2015,1,1)
|
||||
|
||||
equity = self.AddEquity("SPY", Resolution.Minute)
|
||||
self._spy = equity.Symbol
|
||||
self._holdings = equity.Holdings
|
||||
self._rc = self.RC(self._spy, 30, 2, Resolution.Daily)
|
||||
equity = self.add_equity("SPY", Resolution.MINUTE)
|
||||
self._spy = equity.symbol
|
||||
self._holdings = equity.holdings
|
||||
self._rc = self.rc(self._spy, 30, 2, Resolution.DAILY)
|
||||
|
||||
stockPlot = Chart("Trade Plot")
|
||||
stockPlot.AddSeries(Series("Buy", SeriesType.Scatter, 0))
|
||||
stockPlot.AddSeries(Series("Sell", SeriesType.Scatter, 0))
|
||||
stockPlot.AddSeries(Series("UpperChannel", SeriesType.Line, 0))
|
||||
stockPlot.AddSeries(Series("LowerChannel", SeriesType.Line, 0))
|
||||
stockPlot.AddSeries(Series("Regression", SeriesType.Line, 0))
|
||||
self.AddChart(stockPlot)
|
||||
stock_plot = Chart("Trade Plot")
|
||||
stock_plot.add_series(Series("Buy", SeriesType.SCATTER, 0))
|
||||
stock_plot.add_series(Series("Sell", SeriesType.SCATTER, 0))
|
||||
stock_plot.add_series(Series("UpperChannel", SeriesType.LINE, 0))
|
||||
stock_plot.add_series(Series("LowerChannel", SeriesType.LINE, 0))
|
||||
stock_plot.add_series(Series("Regression", SeriesType.LINE, 0))
|
||||
self.add_chart(stock_plot)
|
||||
|
||||
def OnData(self, data):
|
||||
if (not self._rc.IsReady) or (not data.ContainsKey(self._spy)): return
|
||||
def on_data(self, data):
|
||||
if (not self._rc.is_ready) or (not data.contains_key(self._spy)): return
|
||||
if data[self._spy] is None: return
|
||||
value = data[self._spy].Value
|
||||
if self._holdings.Quantity <= 0 and value < self._rc.LowerChannel.Current.Value:
|
||||
self.SetHoldings(self._spy, 1)
|
||||
self.Plot("Trade Plot", "Buy", value)
|
||||
if self._holdings.Quantity >= 0 and value > self._rc.UpperChannel.Current.Value:
|
||||
self.SetHoldings(self._spy, -1)
|
||||
self.Plot("Trade Plot", "Sell", value)
|
||||
value = data[self._spy].value
|
||||
if self._holdings.quantity <= 0 and value < self._rc.lower_channel.current.value:
|
||||
self.set_holdings(self._spy, 1)
|
||||
self.plot("Trade Plot", "Buy", value)
|
||||
if self._holdings.quantity >= 0 and value > self._rc.upper_channel.current.value:
|
||||
self.set_holdings(self._spy, -1)
|
||||
self.plot("Trade Plot", "Sell", value)
|
||||
|
||||
def OnEndOfDay(self, symbol):
|
||||
self.Plot("Trade Plot", "UpperChannel", self._rc.UpperChannel.Current.Value)
|
||||
self.Plot("Trade Plot", "LowerChannel", self._rc.LowerChannel.Current.Value)
|
||||
self.Plot("Trade Plot", "Regression", self._rc.LinearRegression.Current.Value)
|
||||
def on_end_of_day(self, symbol):
|
||||
self.plot("Trade Plot", "UpperChannel", self._rc.upper_channel.current.value)
|
||||
self.plot("Trade Plot", "LowerChannel", self._rc.lower_channel.current.value)
|
||||
self.plot("Trade Plot", "Regression", self._rc.linear_regression.current.value)
|
||||
|
||||
Reference in New Issue
Block a user