def test_arima_model(): ''' unit test for arima ''' import cs_data_analysis as cs import cs_logger as cslog import logging log = setlogfile(cslog.arima_model_log) try: import nb_credit_spread as cslibrary cslib = cslibrary.creditspread() srcfile = r'src/YTW-All-Values.xlsx' df = cslib.get_ytw_from_date_delta(srcfile=srcfile, start='2009-01-31') return log.info('**** AR(1) ****') cs.print_full(cs.arima_model(df), log) log.info('**** AR(1) diff period 1 ****') cs_df = cs.get_ytw_from_date( '1989-12-31') # fetch month before 31 Jan 1990 cs_df = cs_df.diff(periods=1) # diff with previous period cs_df = cs_df[ '1990-01-31':] # get only records from 31 Jan 1990; this avoids NaN in first row cs.print_full(cs.arima_model(cs_df), log) # get AR(1) coefficients assert True except: import sys message = f"Unexpected error: {sys.exc_info()[0]} {sys.exc_info()[1]}" log.error(message) raise
def test_load_source_values(): df = get_ytw_test() log = setlogfile('test.load.source.values', logging.INFO) from statsmodels.tsa.stattools import adfuller # adf_tstat, pvalue, tstat, results = adfuller(df['CS-Aaa-3MO'].values) # , maxlag=40, regression='ct', autolag='BIC', regresults=True) # print(adf_tstat) #print(pvalue) #print(tstat) #print(results) adf = adfuller( df['CS-Aaa-3MO'].values ) # , maxlag=40, regression='ct', autolag='BIC', regresults=True) print(adf) from arch.unitroot import ADF adf = ADF(y=df['CS-Aaa-3MO'].values) #, lags=40, trend='ct', method='BIC') print(adf.pvalue) import cs_data_analysis as cs cs.print_full(df, log) pass '''
def test_summary_stats_full(): ''' unit test for summary stats ''' import cs_data_analysis as cs import cs_logger as cslog import logging log = setlogfile(cslog.summary_stats_full_log) try: import nb_credit_spread as cslibrary cslib = cslibrary.creditspread() srcfile = r'src/YTW-All-Values.xlsx' ytw_df = cslib.get_ytw_from_date_delta(srcfile=srcfile, start='2014-01-31') cs_stats, cs_stats_p1 = cs.summary_stats_full(ytw_df) log.info('**** cs stats ****') cs.print_full(cs_stats, log) log.info('**** cs stats p1 diff ****') cs.print_full(cs_stats_p1, log) assert True except: import sys log.error(f"Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]) raise
def test_summary_stats(): ''' unit test for summary stats ''' import cs_data_analysis as cs import cs_logger as cslog import logging import nb_credit_spread as cslibrary cslib = cslibrary.creditspread() srcfile = r'src/YTW-All-Values.xlsx' ytw_df = cslib.get_ytw_from_date_delta(srcfile=srcfile, start='2014-01-31') cs.print_full(cs.summary_stats(ytw_df), setlogfile(cslog.summary_stats_log)) assert True
def test_causation(): ''' ''' import cs_data_analysis as cs import cs_logger as cslog log = setlogfile(cslog.causation_log) try: import nb_credit_spread as cslibrary cslib = cslibrary.creditspread() srcfile = r'src/YTW-All-Values.xlsx' ytw_df = cslib.get_ytw_from_date_delta(srcfile=srcfile, start='2009-01-31') cs.print_full(cs.causation(ytw_df), log) assert True except: import sys log.error(f"Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]) raise
def test_causation_cs_pce(): import cs_data_analysis as cs import cs_logger as cslog log = setlogfile(cslog.causation_log) try: import nb_credit_spread as cslibrary cslib = cslibrary.creditspread() srcfile = r'src/YTW-All-Values.xlsx' ytw_df = cslib.get_ytw_from_date_delta(srcfile=srcfile, start='2009-01-31') df = ytw_df[['CS-Aaa-3MO', 'Econ-PCE']] from cs_causation import grangers_causation r = grangers_causation(df) # print(r) cs.print_full(r, log) assert True except: import sys log.error(f"Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]) raise