AidanAlr / Alpaca-Pairs-Trading-Terminal

Interact with the ALPACA stock brokerage through the terminal. Allows you to manage positions, execute trades, run analysis, backtest strategy, execute pairs trading strategy.
2 stars 3 forks source link

independent variable problem? #13

Closed OdinLin closed 1 month ago

OdinLin commented 1 month ago

Hello at https://github.com/AidanAlr/Alpaca-Pairs-Trading-Terminal/blob/4cff49ed59a6f94c02850a3679bae1ae8897fa61/analysis/statistical_methods.py#L59 Should it be stock_data_df[stock_2] - stock_data_df[stock_1] * stock_data_df["hedge_ratio"] ? because according to

RollingOLS(
            stock_data_df[f"{stock_2}_return"],
            stock_data_df[f"{stock_1}_return"],
            window=60,
        )

stock_2 is independent variable and stock_1 is dependent variable, Or I misunderstood this?

AidanAlr commented 1 month ago

stock_2 is dependent and stock 1 is independent. https://www.statsmodels.org/dev/generated/statsmodels.regression.rolling.RollingOLS.html

OdinLin commented 1 month ago

But if stock_2 is dependent, The spread should be stock_data_df[stock_2] - stock_data_df[stock_1] stock_data_df["hedge_ratio"] ? But origin is stock_data_df[stock_1] - stock_data_df[stock_2] stock_data_df["hedge_ratio"]

AidanAlr commented 1 month ago

But if stock_2 is dependent, The spread should be stock_data_df[stock_2] - stock_data_df[stock_1] stock_data_df["hedge_ratio"] ? But origin is stock_data_df[stock_1] - stock_data_df[stock_2] stock_data_df["hedge_ratio"]

yes I think youre right, changed it. Thx