Analysis of the data

Let's run some analysis to see what the returns over this period might have been had we invested in this ETF:

  1. We'll pull data for the first_open first:
first_open = spy['Open'].iloc[0] 
first_open 

This generates the following output:

  1. Next, let's get the closing price on the final day of the period:
last_close = spy['Close'].iloc[-1] 
last_close 

This generates the following output:

  1. And finally, let's see the change over the full period:
last_close - first_open 

This generates the following output:

So, it appears that a purchase of 100 shares at the start of the period would have cost us approximately $11,237 and, at the end of the period, those same 100 shares would have been valued at roughly $27,564. This transaction would have given us a gain of just a bit over 145% over the period. Not too bad at all.

Let's now take a look at the return over the same period for just the intraday gains. This assumes we buy the stock at the opening of each day and sell it at the close of that same day:

spy['Daily Change'] = pd.Series(spy['Close'] - spy['Open']) 

That will give us the change from the open to the close each day. Let's take a look at that:

spy['Daily Change'] 

This generates the following output:

Let's now total those changes over the period:

spy['Daily Change'].sum() 

This generates the following output:

So, as you can see, we have gone from a gain of over 163 points to one of just over 53 points. Ouch! More than half the market's gains came from holding overnight during the period.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.222.185