Hi folks,
As of Thursday, July 7th. This algorithm will need to reflect changes to the way we load VIX: https://www.quantopian.com/posts/upcoming-changes-to-quandl-datasets-in-pipeline-vix-vxv-etc-dot.
In order to do that, you'll need to change
# Calculate the impact of the term structure (see more about the 'impact' at the link above). Basically,
# isolate how much of the movement of VXX isn't due to the VIX index. As a handwavy model we'll
# run a simple regression of the changes in the VIX to the changes in VXX, and use the
# intercept term as an estimation of the 'impact.'
class TermStructureImpact(CustomFactor):
# Pre-declare inputs and window_length
inputs = [yahoo_index_vix.close, USEquityPricing.close]
window_length = 20
def compute(self, today, assets, out, vix, close):
# Get the prices series of just VXX and calculate its daily returns.
vxx_returns = pd.DataFrame(close, columns=assets)[sid(38054)].pct_change()[1:]
# Since there isn't a ticker for the raw VIX Pipeline feeds us the value of the
# VIX for each day in the 'window_length' for each asset. Which kind of makes sense
# -- the VIX is the same value for every security.
# Since I have a fixed universe I'll just use VXX, one of my securities, to get a single series of
# VIX data. You could use any security or integer index to any column, but I'll use one of my
# securities just to keep things straight in my head.
vix_returns = pd.DataFrame(vix, columns=assets)[sid(38054)].pct_change()[1:]
# Calculate the 'impact.'
alpha = _intercept(vix_returns, vxx_returns)
out[:] = alpha * np.ones(len(assets))
To this starting on July 7th
# Calculate the impact of the term structure (see more about the 'impact' at the link above). Basically,
# isolate how much of the movement of VXX isn't due to the VIX index. As a handwavy model we'll
# run a simple regression of the changes in the VIX to the changes in VXX, and use the
# intercept term as an estimation of the 'impact.'
class TermStructureImpact(CustomFactor):
# Pre-declare inputs and window_length
inputs = [yahoo_index_vix.close, USEquityPricing.close]
window_length = 20
def compute(self, today, assets, out, vix, close):
# Get the prices series of just VXX and calculate its daily returns.
vxx_returns = pd.DataFrame(close, columns=assets)[sid(38054)].pct_change()[1:]
# Since there isn't a ticker for the raw VIX Pipeline feeds us the value of the
# VIX for each day in the 'window_length' for each asset. Which kind of makes sense
# -- the VIX is the same value for every security.
# Since I have a fixed universe I'll just use VXX, one of my securities, to get a single series of
# VIX data. You could use any security or integer index to any column, but I'll use one of my
# securities just to keep things straight in my head.
vix_returns = pd.DataFrame(vix).pct_change()[0].iloc[1:]
# Calculate the 'impact.'
alpha = _intercept(vix_returns, vxx_returns)
out[:] = alpha
The main algorithm source code will be migrated to reflect that change once the date comes. If you have any questions, please let me know.