| 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 -1.476 Tracking Error 0.166 Treynor Ratio 0 Total Fees $0.00 |
# ScipyStatsLinearRegression
from scipy import stats
class ScipyStatsLinearRegression(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 8, 23)
self.SetEndDate(2020, 12, 24)
self.cap = 100000
self.SetCash(self.cap)
self.PERIOD = 42
self.OFFSET = 5
self.STK = self.AddEquity('QQQ', Resolution.Daily).Symbol
self.SetWarmUp(self.PERIOD + 1)
def OnData(self, data):
prices = self.History(self.STK, self.PERIOD, Resolution.Daily)['close']
y = [float(data) for data in prices]
x = [range(len(y))]
slope, intercept = stats.linregress(x, y)[0], stats.linregress(x, y)[1]
linreg = (intercept + slope*(self.PERIOD - 1 - self.OFFSET))
self.Plot('Indicator', 'linreg', round(linreg, 4))
self.Plot('Indicator', 'prices', prices.iloc[-1])