Hello,
First post on Quantopian, very excited to use it more.
While trying to learn, I created the following day of the week strategy (randomly chosen parameters)
def initialize(context):
context.aapl = sid(24)
context.flag = 0
def handle_data(context, data):
if data[context.aapl].datetime.weekday() == 3 and data[context.aapl].returns > 5:
context.flag = 1
if data[context.aapl].datetime.weekday() == 4 and context.flag == 1:
context.flag = 2
print("buy")
order(context.aapl, +100)
if data[context.aapl].datetime.weekday() == 1 and context.flag == 2:
order(context.aapl, -100)
context.flag = 0
print("sell")
#if returns > 0.05, strat return is -1.98, sharpe -2.68
#if returns > 5.00, strat return is -1.98, sharpe -2.68
The idea is to buy the apple stocks on Fridays if Thursdays were profitable, and then to sell it on Tuesdays.
I set a threshold for the Thursday returns: if the returns are greater than 0.05, i.e. 5%, buy, etc. But whatever I set the threshold to, I get the exact same results. Even if I set it to the almost impossible return of 500%! I was wondering if someone can point as to where the error in my logic or code is.
Best,
Ryan