Back to Community
Cumulative Overnight Returns of `QQQ`

Hello Quantopians. I will be posting a series of posts for my Investment Strategies class at the university. Today's task is a line plot of cumulative overnight returns of QQQ. Please feel free to comment, correct any mistakes or make any suggestions.
Thank you.

Loading notebook preview...
Notebook previews are currently unavailable.
5 responses

Hi Omar,

Make sure that when you compute the overnight return you are using the open of tomorrow and the close of today. Currently, it looks like you are calculating the return of today's close to today's open (which is approximately the opposite of the intraday return, as opposed to the overnight return). Using additive returns like you do, I get something that looks like the following:

Overnight QQQ Returns

@ Michael Matthews is correct. The current implementation is calculating todays return (ie today's close to today's open) . Maybe take a look at the pandas 'shift' method (https://pandas.pydata.org/pandas-docs/version/0.18/generated/pandas.Series.shift.html). You can shift yesterday's close price forward one day. Then compare that value to today's open.

The other issue you have is summing arithmetic returns. That doesn't really work. If one has a 1% gain followed by a 1% loss then it would appear the net gain would be 0%. However, it's really a bit less (1 + .01) x (1 - .01) = .9999. The more correct way is to use log returns.

In my opinion, more realistic results you may get in IDE:

# Cumulative Overnight Returns  
# -----------------  
stk = symbol('QQQ')  
# -----------------  
def initialize(context):  
    schedule_function(buy_at_close, date_rules.every_day(), time_rules.market_close())  
    schedule_function(sell_at_open, date_rules.every_day(), time_rules.market_open())

def buy_at_close(context, data):  
    if get_open_orders(): return  
    if data.can_trade(stk):  
        order_target_percent(stk, 1.0)

def sell_at_open(context, data):  
    if get_open_orders(): return  
    if data.can_trade(stk):  
        order_target_percent(stk, 0)  

'''

10000

START
06/01/2013
END
01-01-2018

stk = symbol('QQQ')

Total Returns
-46.33%
Benchmark Returns
79.71%
Alpha
-0.20
Beta
0.49
Sharpe
-1.25
Sortino
-1.48
Volatility
0.10
Max Drawdown
-48.51%

'''

Loading notebook preview...
Notebook previews are currently unavailable.

I'll second @ Vladimir. Nothing like a backtest.

Thanks a lot for the comments guys. I got better results now