system.stat_arb package¶
Submodules¶
system.stat_arb.pair_trading module¶
-
class
system.stat_arb.pair_trading.
StockPair
(symbol1, symbol2, volatility, price_mean)¶ Bases:
object
-
create_trade
(date, open1, close1, open2, close2, qty1=0, qty2=0, profit_loss=0.0)¶
-
update_betas
(beta0, beta1_hedgeratio)¶
-
update_trades
()¶ This function update daily qtys and profits of the stockpair :return: a dataframe of daily trading records
-
-
system.stat_arb.pair_trading.
build_pair_trading_model
(corr_threshold: float = 0.95, adf_threshold: float = 0.01, sector: str = 'Technology') → None¶ This function build a pair_trading model for a given sector of stocks in sp500 and update database tables :param corr_threshold: the threshold for stock pair correlation :param adf_threshold: the threshold for adf P value :param sector: the sector name of stocks
-
system.stat_arb.pair_trading.
cointegration_all_test
(symbol_list: List[str]) → None¶ This function calculate the cointegration of all the symbol pairs in the symbol_list and write all the results to “pair_info” table :param symbol_list: the list of symbol name
-
system.stat_arb.pair_trading.
cointegration_test
(ticker1: str, ticker2: str) → List[Union[str, float]]¶ This function calculate the cointegration of two tickers :param ticker1: name of the firts ticker :param ticker1: name of the second ticker :return: a list of the linear regression results
-
system.stat_arb.pair_trading.
create_stock_pairs
(sector: str) → None¶ This function creat pair trades for a given sector of stocks from table “sp500” :param sector: the sector name of stocks
-
system.stat_arb.pair_trading.
pair_trade_back_test
(back_testing_start_date: str, back_testing_end_date: str) → None¶ This function do pair trades back testing and write all the results to the “pair_trades” table and “stock_pairs” table. The profit_loss is the total loss of a given stock pair performance during back testing period :param back_testing_start_date: the start date of back testing :param back_testing_end_date: the end date of back testing
-
system.stat_arb.pair_trading.
pair_trade_probation_test
(probation_testing_start_date: str, probation_testing_end_date: str) → None¶
-
system.stat_arb.pair_trading.
populate_stock_data
(tickers: Collection[str], table_name: str, start_date: str, end_date: str) → None¶ This function writes ticker’s data into database :param tickers: a list of tickers that we want to write :param table_name: a string of our database’s table name