Explain the code below "REGRESSION_WINDOW = 60
Z_SCORE_WINDOW = 60

ENTR_SHORT = -1.5
ENTR_LONG = 1.5
EXIT_SHORT = 0
EXIT_LONG = 0
#
ENTR_FLAT = 0.25
EXIT_FLAT = 0.25
# %% ----------------------------------- Get data
BBG_DICT = {
'LMCADS03 Curncy' : 'Copper',
'XAU Curncy' : 'Gold',
'USGG10YR Index' : '10s',
'USYC2Y10 Index' : '2s10s',
'FDTR Index' : 'FDTR',
'ED4 Comdty' : 'ED4',
'US0003M Index' : '3mLIBOR',
}
# Organize BBG Data
df_bbg = blp.bdh(list(BBG_DICT.keys()), 'px_last', dt(1990,1,1), dt(2021, 12, 31))
df_bbg.columns = [c[0] for c in df_bbg.columns]
df_bbg.rename(BBG_DICT, axis=1, inplace=True)
df_bbg = df_bbg.iloc[:-1]
df_bbg = df_bbg.ffill().bfill()
df_bbg['10s'] *= 100
# Create Special Columns
# %% ----------------------------------- Create special columns

df_bbg['CuAu'] = df_bbg['Copper']/df_bbg['Gold']
# 10s ELB Filter
df_bbg['10s_ELB_Filter'] = (df_bbg['FDTR'].expanding().min().apply(lambda x: min(3,x))+1)*100
df_bbg['10s_ELB_Filter'] = (df_bbg['10s'].shift(20).bfill()>df_bbg['10s_ELB_Filter']).astype(int)
# 2s10s Hike
df_bbg['2s10s_Hike'] = ((100-df_bbg['ED4']) - df_bbg['3mLIBOR']).rolling(20).mean().fillna((100-df_bbg['ED4']) - df_bbg['3mLIBOR'])
df_bbg['2s10s_Cut_Filter'] = (df_bbg['FDTR']-df_bbg['FDTR'].rolling(250).mean().fillna(df_bbg['FDTR'].expanding().mean()) > -.25).astype(int)
df_bbg['2s10s_Trade'] = (df_bbg['2s10s_Hike']>ENTR_FLAT).astype(int) * df_bbg['2s10s_Cut_Filter']

# %% ----------------------------------- Create RSI

def calculate_interday_RSI(in_df, col='yld', decay=1/3.0):
    df_tmp = in_df.copy()
    ### Perform RSI
    df_tmp['_diff'] = df_tmp[col].diff()
    # Construct up indicator
    df_tmp['_up'] = df_tmp['_diff']
    df_tmp.loc[df_tmp['_up'] < 0, '_up'] = 0
    df_tmp['_up'] = df_tmp['_up'].ewm(alpha=decay, ignore_na=True).mean()
    # Construct dn indicator
    df_tmp['_dn'] = df_tmp['_diff']
    df_tmp.loc[df_tmp['_dn'] > 0, '_dn'] = 0
    df_tmp['_dn'] = df_tmp['_dn'].ewm(alpha=decay, ignore_na=True).mean()
    # Construct RSI
    df_tmp['RSI'] = 100 - (100/(1-(df_tmp['_up']/df_tmp['_dn'])))
    # Clean
    df_tmp.drop(columns=['_up', '_dn', '_diff'], inplace=True)
    # Return
    return(df_tmp)

def calculate_threshold_RSI(in_df, col='yld', decay=1/10, threshold=70, threshold_decay=5):
    df_tmp = in_df.copy()
    df_tmp = calculate_interday_RSI(df_tmp, col=col, decay=decay)
    df_tmp['RSIT'] = (df_tmp['RSI']>threshold).astype(int).rolling(threshold_decay).mean()
    # Return
    return(df_tmp)

# %% ----------------------------------- Create CuAu Model

def create_regression_df(df_bbg, regression_window=REGRESSION_WINDOW, z_score_window=Z_SCORE_WINDOW, smooth_z=False):
    # Organize data
    X = df_bbg['CuAu'].values
    X = add_constant(X)
    Y = df_bbg['10s'].values
    # Fit model
    model = ROLS(Y, X, window=regression_window).fit()
    # Create combined df
    df = pd.DataFrame(model.params, columns=['b0', 'b1'], index=df_bbg.index)
    df = df.join(df_bbg)
    # Create Z Score model
    df['10s_hat'] = df['b0'] + df['b1']*df['CuAu']
    # df['10s_hat'] = df['10s_hat'].shift(1) # We don't need to shift 1. At EOD we will know 10s, Copper, and Gold. We make the trading decision the next day.
    df['10s_hat'] = df['10s_hat']
    df['10s_resid'] = df['10s'] - df['10s_hat']
    rolling_view = df['10s_resid'].rolling(z_score_window)
    df['10s_z_score'] = (df['10s_resid'] - rolling_view.mean())/rolling_view.std()
    if(smooth_z):
        df['10s_z_score'] = df['10s_z_score'].ewm(3).mean()
    df = df[dt(1990,  1, 1):]
    # if(df.isna().any().any()):
    #     raise Exception('You have missing values')
    # Create dates
    df['Date'] = df.index
    # Create 3m drawdown?
    # Return
    return(df)
"