| Overall Statistics |
|
Total Trades 561 Average Win 1.37% Average Loss -1.85% Compounding Annual Return 4.912% Drawdown 26.300% Expectancy 0.124 Net Profit 77.134% Sharpe Ratio 0.367 Probabilistic Sharpe Ratio 0.461% Loss Rate 35% Win Rate 65% Profit-Loss Ratio 0.74 Alpha 0 Beta 0 Annual Standard Deviation 0.108 Annual Variance 0.012 Information Ratio 0.367 Tracking Error 0.108 Treynor Ratio 0 Total Fees $2047.24 Estimated Strategy Capacity $1200000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
import numpy as np
import pandas as pd
class CalculatingFluorescentOrangeBee(QCAlgorithm):
#1Today is Monday. 2The close must be at least 1% lower than Friday’s close. 3If one and two are true, then enter at the close. 4Exit at the close on Tuesday.
def Initialize(self):
self.SetStartDate(2010, 1, 1) # Set Start Date
self.SetEndDate(2021, 12, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
self.SetWarmup(100)
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
# schedule: rebalance
self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.BeforeMarketClose(self.spy, 0), self.entry_signal)
self.Schedule.On(self.DateRules.Every(DayOfWeek.Tuesday), self.TimeRules.BeforeMarketClose(self.spy, 0), self.close_position)
def entry_signal(self):
histh = self.History(self.spy,180, Resolution.Minute).loc["SPY"]["close"]
histd = self.History(self.spy,21, Resolution.Daily).loc["SPY"]["close"]
histd_df = pd.DataFrame(histd)
histh_df = pd.DataFrame([histh.iloc[-1]])
histd_df = histd_df.append(histh_df, ignore_index = True)
ret = histd_df[::-1].pct_change()
self.Log(str(ret.iloc[-1] * 100))
change = ret.iloc[-1] * 100
if change.close < 1.0:
self.SetHoldings(self.spy, 1)
def close_position(self):
if self.Portfolio[self.spy].Invested:
self.Liquidate()
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
# if not self.Portfolio.Invested:
# self.SetHoldings("SPY", 1)