Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pair Trading

From the following link, if someone can make me understand the relevance and syntax of the following lines in this code
https://www.quantopian.com/algorithms/5667083d2a37e94ced000198 . If there is any reference ,please show me the link.

new_spreads = np.ndarray((context.num_pairs, 1))
new_spreads[i, :] = Y[-1] - hedge * X[-1]

    if context.spread.shape[1] > context.z_window:  
        # Keep only the z-score lookback period  
        spreads = context.spread[i, -context.z_window:]

What are Y[-1] ,X[-1]? and z.window ?

Thanks in advance.

1 response

Without really knowing the context (the notebook did not open), it would appear that the "new_spreads[i,:] = ..." is taking the last data point (the [-1]) and applying a beta hedge to it. The z_window appears to be a preset constant that defines the "window" for the calculation of the z-score, i.e. the number of periods back that is used to find the distribution and calculate the z-score that is used as the threshold for trading signals.