def test_backtest(): """ Ensures that the backtest function works on all the registered strategies, with their default parameter values """ sample = pd.read_csv(SAMPLE_CSV, parse_dates=["dt"]) # Simulate custom indicator sample["custom"] = np.random.random((sample.shape[0], )) * 100 for strategy in STRATEGY_MAPPING.keys(): if strategy == "sentiment": data = get_yahoo_data("TSLA", "2020-01-01", "2020-07-04") sentiments = get_bt_news_sentiment(keyword="tesla", page_nums=2) cerebro = backtest(strategy, data, sentiments=sentiments, senti=0.4, plot=False) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy) assert cerebro is not None, errmsg else: cerebro = backtest(strategy, sample, plot=False) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy) assert cerebro is not None, errmsg
def test_backtest(): """ Ensures that the backtest function works on all the registered strategies, with their default parameter values """ sample = pd.read_csv(SAMPLE_CSV, parse_dates=["dt"]) # Simulate custom indicator sample["custom"] = np.random.random((sample.shape[0], )) * 100 for strategy in STRATEGY_MAPPING.keys(): if strategy == "sentiment": data = get_yahoo_data("TSLA", "2020-01-01", "2020-07-04", dividends=True) # use cached data instead of scraping for tests purposes. # sentiments = get_bt_news_sentiment(keyword="tesla", page_nums=2) with open(SENTI_PKL, "rb") as handle: sentiments = pickle.load(handle) cerebro = backtest(strategy, data, sentiments=sentiments, senti=0.4, plot=False) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy) assert cerebro is not None, errmsg data_disclosures = get_stock_data( "TSLA", "2020-01-01", "2020-09-30", dividends=True, # source="phisix" ) # sentiments_disclosures = get_disclosure_sentiment( # stock_code="JFC", # start_date="2020-07-01", # end_date="2020-09-30", # ) with open(DISCLOSURE_PKL, "rb") as handle_disclosures: sentiments_disclosures = pickle.load(handle_disclosures) cerebro_disclosures = backtest( strategy, data_disclosures, sentiments=sentiments_disclosures, senti=0.2, plot=False, ) errmsg_disclosures = "Backtest encountered error for strategy '{}'!".format( strategy) assert cerebro_disclosures is not None, errmsg_disclosures else: cerebro = backtest(strategy, sample, plot=False) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy) assert cerebro is not None, errmsg
def test_backtest(): """ Ensures that the backtest function works on all the registered strategies, with their default parameter values """ sample = pd.read_csv(SAMPLE_CSV, parse_dates=["dt"]) for strategy in STRATEGY_MAPPING.keys(): if strategy == "sentiment": data = get_yahoo_data("TSLA", "2020-01-01", "2020-06-10") cerebro = backtest( strategy, data, keyword="tesla", page_nums=2, senti=0.4 ) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy ) assert cerebro is not None, errmsg else: cerebro = backtest(strategy, sample, plot=False) errmsg = "Backtest encountered error for strategy '{}'!".format( strategy ) assert cerebro is not None, errmsg
def test_get_yahoo_data_dividend(): stock_df = get_yahoo_data(MSFT_SYMBOL, MSFT_SYMBOL_START, MSFT_SYMBOL_STOP, dividends=True) assert isinstance(stock_df, pd.DataFrame)
def test_get_yahoo_data(): stock_df = get_yahoo_data(YAHOO_SYMBOL, DATE_START, DATE_END) assert isinstance(stock_df, pd.DataFrame)