| 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.927 Tracking Error 0.118 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# how to set limit on list - https://stackoverflow.com/questions/40696005/limit-the-length-of-a-python-list
import decimal
from QuantConnect.Python import PythonQuandl
from QuantConnect.Data import *
import statistics
"""
Algo Overview
Use the rolling average daily gains for each day of the week. (later create one for just day in a given set of day (3-10, pref with dynamic range if possible)
Enter at noon on the worst day.
- only enter if VIX < 20 or some other determinant of uptrend.
Exit at noon on the best day.
"""
# Need to make history request
# - loop thru each weekday and calculatre the dialy return and append that to the list
# Global Vars
EQUITY = "SPXL"
BENCHMARK = "SPY"
ROLLING_LOOK_BACK_PERIOD = 5 # in number of weeks as each list will pull up that last returns on those weekdays
class AlertVioletChicken(QCAlgorithm):
def Initialize(self):
# Debug Set
self.SetStartDate(2022, 1, 1) # Set Start Date
self.SetEndDate(2022, 11, 1)
# Test Set
self.SetCash(100000) # Set Strategy Cash
self.equity = self.AddEquity(EQUITY, Resolution.Minute).Symbol
self.AddEquity(BENCHMARK, Resolution.Minute)
# Capture morning price
self.Schedule.On(self.DateRules.EveryDay("SPXL"), self.TimeRules.AfterMarketOpen("SPXL", 0), self.EveryDayAfterMarketOpen)
# Capture closing price
self.Schedule.On(self.DateRules.EveryDay("SPXL"), self.TimeRules.BeforeMarketClose("SPXL", 0), self.EveryDayBeforeMarketClose)
self.dailyMorningPrice = None
self.dailyClosingPrice = None
# Monday
self.mondayRollingAvg = 0
self.mondayHistoricalReturns = []
# Tuesday
self.tuesdayRollingAvg = 0
self.tuesdayHistoricalReturns = []
# Wednesday
self.wednesdayRollingAvg = 0
self.wednesdayHistoricalReturns = []
# Thursday
self.thursdayRollingAvg = 0
self.thursdayHistoricalReturns = []
# Monday
self.thursdaydayRollingAvg = 0
self.thursdaydayHistoricalReturns = []
# Call historical data to then loop thru to get Historical Return lists initialized
self.SetWarmup(timedelta(days=365)) # pretty sure this doesn't do anything
def OnData(self, data):
self.price = self.Securities[self.equity].Price
if self.IsWarmingUp:
return
def EveryDayAfterMarketOpen(self):
# capture morning price
self.dailyMorningPrice = self.price
pass
def EveryDayBeforeMarketClose(self):
# capture closing price
self.dailyClosingPrice = self.price
daily_return = (self.dailyClosingPrice - self.dailyMorningPrice) / self.dailyMorningPrice
# Debugging day of week code
# self.Debug(str(self.Time) + " : " + str(self.Time.weekday()))
# add to weekday's rolling average
if self.Time.weekday() == 0:
# append today's return to today's list of returns, add max days allowed in list
self.mondayHistoricalReturns.append(daily_return)
self.mondayRollingList = self.mondayHistoricalReturns[-ROLLING_LOOK_BACK_PERIOD:]
self.Debug(str(self.Time) + " monday rolling count " + str(len(self.mondayRollingList)))
self.Debug(str(self.Time) + " last 5 mondays: " + str(self.mondayRollingList))
self.mondayRollingAvg = sum(self.mondayRollingList) / (ROLLING_LOOK_BACK_PERIOD)
self.Debug(str(self.Time) + " monday rolling avg: " + str(self.mondayRollingAvg))
# right now it only works on days in the algo - doesn't get the days before it - need to get historical data; the warmup didn't append to the list (1/16/22)
# how to set limit on list - https://stackoverflow.com/questions/40696005/limit-the-length-of-a-python-list
import decimal
from QuantConnect.Python import PythonQuandl
from QuantConnect.Data import *
import statistics
"""
Algo Overview
Use the rolling average daily gains for each day of the week. (later create one for just day in a given set of day (3-10, pref with dynamic range if possible)
Enter at noon on the worst day.
- only enter if VIX < 20 or some other determinant of uptrend.
Exit at noon on the best day.
"""
# Need way to say only look back __ days
# maybe make lists for dayRollingAverage inputs
# Global Vars
EQUITY = "SPXL"
BENCHMARK = "SPY"
ROLLING_LOOK_BACK_PERIOD = 5 # in number of weeks as each list will pull up that last returns on those weekdays
class AlertVioletChicken(QCAlgorithm):
def Initialize(self):
# Debug Set
self.SetStartDate(2022, 1, 1) # Set Start Date
self.SetEndDate(2022, 11, 1)
# Test Set
self.SetCash(100000) # Set Strategy Cash
self.equity = self.AddEquity(EQUITY, Resolution.Minute).Symbol
self.AddEquity(BENCHMARK, Resolution.Minute)
# Capture morning price
self.Schedule.On(self.DateRules.EveryDay("SPXL"), self.TimeRules.AfterMarketOpen("SPXL", 0), self.EveryDayAfterMarketOpen)
# Capture closing price
self.Schedule.On(self.DateRules.EveryDay("SPXL"), self.TimeRules.BeforeMarketClose("SPXL", 0), self.EveryDayBeforeMarketClose)
self.dailyMorningPrice = None
self.dailyClosingPrice = None
# Monday
# self.mondayReturn = None
self.mondayRollingAvg = 0
self.mondayHistoricalReturns = []
self.SetWarmup(365)
def OnData(self, data):
self.price = self.Securities[self.equity].Price
def EveryDayAfterMarketOpen(self):
# capture morning price
self.dailyMorningPrice = self.price
pass
def EveryDayBeforeMarketClose(self):
# capture closing price
self.dailyClosingPrice = self.price
daily_return = (self.dailyClosingPrice - self.dailyMorningPrice) / self.dailyMorningPrice
# Debugging day of week code
# self.Debug(str(self.Time) + " : " + str(self.Time.weekday()))
# add to weekday's rolling average
if self.Time.weekday() == 0:
# append today's return to today's list of returns, add max days allowed in list
self.mondayHistoricalReturns.append(daily_return)
self.mondayRollingList = self.mondayHistoricalReturns[-ROLLING_LOOK_BACK_PERIOD:]
self.Debug(str(self.Time) + " monday rolling count " + str(len(self.mondayRollingList)))
self.Debug(str(self.Time) + " last 5 mondays: " + str(self.mondayRollingList))
self.mondayRollingAvg = sum(self.mondayRollingList) / (ROLLING_LOOK_BACK_PERIOD)
self.Debug(str(self.Time) + " monday rolling avg: " + str(self.mondayRollingAvg))
# right now it only works on days in the algo - doesn't get the days before it - need to get historical data; the warmup didn't append to the list (1/16/22)