Back to Community
Pair Trading

Hi, I am new to Quantopian
From the following link on Pair Trading
https://www.quantopian.com/algorithms/5667083d2a37e94ced000198
Please help me in understanding these codes and its functioning here, If there is any description of these functions on Quantopian,please let me know.
Q1)
set_slippage(slippage.FixedSlippage(spread=0))
set_commission(commission.PerTrade(cost=1))
set_symbol_lookup_date('2014-01-01')

Q2) context.spread = np.ndarray((context.num_pairs, 0))
# context.hedgeRatioTS = np.ndarray((context.num_pairs, 0))
context.inLong = [False] * context.num_pairs
context.inShort = [False] * context.num_pairs

Q3) prices = history(35, '1d', 'price').iloc[-context.lookback::]

new_spreads = np.ndarray((context.num_pairs, 1))  

4) new_spreads[i, :] = Y[-1] - hedge * X[-1]

Thanks in advance.

1 response

Q1: set_slippage, set_commission, and set_symbol_lookup_date are Quantopian API functions described at http://www.quantopiancom/help .

Q2: ndarray is a NumPy function, described at http://docs.scipy.org/doc/numpy/reference/ , that creates an "n-dimensional array". * is the Python operator that "multiplies" a list by an int.

Q3: history is a Quantopian function. It returns a pandas.DataFrame. See http://pandas.pydata.org/pandas-docs/stable/api.html and read about DataFrames and indexing.

Q4: Indexing and vector arithmetic in NumPy.