| 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 -2.268 Tracking Error 0.113 Treynor Ratio 0 Total Fees $0.00 |
from collections import deque
from datetime import datetime, timedelta
from numpy import sum
import numpy as np
from scipy import stats
class CustomIndicatorAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019,1,1)
self.SetEndDate(2019,12,31)
symbol="SPY"
self.AddEquity(symbol, Resolution.Daily)
self.slopy = custom_slope('custom', 100)
history = self.History(symbol, 100, Resolution.Daily)
#self.slopy[symbol].Warmup(history)
self.RegisterIndicator(symbol, self.slopy, Resolution.Daily)
def OnData(self, data):
self.Plot("slopy", "slopy", self.slopy.Value)
#class custom_slope(PythonIndicator):
class custom_slope():
def __init__(self,symbol, periods):
self.symbol=symbol
self.queue = deque(maxlen=periods)
self.Value = 0
self.Time=None
self.IsReady=False
def __repr__(self):
return "{0} -> IsReady: {1}. Time: {2}. Value: {3}".format(self.Name, self.IsReady, self.Time, self.Value)
def Update(self,input):
self.queue.appendleft(input.Close)
count = len(self.queue)
if count == self.queue.maxlen:
y = np.log(self.queue)
x = [range(len(y))]
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
self.Value=slope * 10000 # value is very small an will display 0 if not multiplyed
self.IsReady=True
def Warmup(self,history):
if self.symbol not in history:
return
for index, row in history.loc[self.symbol].iterrows():
self.queue.Add(row["close"])