diff --git a/src/scrilla/analysis/markets.py b/src/scrilla/analysis/markets.py index 55b09d70..128ae851 100644 --- a/src/scrilla/analysis/markets.py +++ b/src/scrilla/analysis/markets.py @@ -42,15 +42,12 @@ def sharpe_ratio(ticker, start_date=None, end_date=None, risk_free_rate=None, ti except errors.InputValidationError as ive: raise ive - print('inside markets.sharpe_ratio') result = profile_cache.filter_profile_cache(ticker=ticker, start_date=start_date, end_date=end_date) - print('result', result) if result is not None and result[static.keys['STATISTICS']['SHARPE']] is not None: return result[static.keys['STATISTICS']['SHARPE']] if ticker_profile is None: - print('calcuatling rr from markets.sharpe_ratio') ticker_profile = statistics.calculate_risk_return(ticker=ticker, start_date=start_date, end_date=end_date) @@ -59,7 +56,6 @@ def sharpe_ratio(ticker, start_date=None, end_date=None, risk_free_rate=None, ti sharpe_ratio = (ticker_profile['annual_return'] - risk_free_rate)/ticker_profile['annual_volatility'] - print('RRRRRRIGGGHHHHTTT FUCKING HERE!!!') profile_cache.save_or_update_row(ticker=ticker, start_date=start_date, end_date=end_date,sharpe_ratio=sharpe_ratio) @@ -218,9 +214,6 @@ def cost_of_equity(ticker, start_date=None, end_date=None, market_profile=None, except errors.APIResponseError as api: raise api - print('prem', premium) - print('beta', beta) - print('risk_free', services.get_risk_free_rate()) equity_cost = (premium*beta + services.get_risk_free_rate()) profile_cache.save_or_update_row(ticker=ticker, start_date=start_date, end_date=end_date, equity_cost=equity_cost) diff --git a/src/scrilla/analysis/statistics.py b/src/scrilla/analysis/statistics.py index 7e1ad48f..3f8c07ba 100644 --- a/src/scrilla/analysis/statistics.py +++ b/src/scrilla/analysis/statistics.py @@ -535,10 +535,8 @@ def calculate_risk_return(ticker, start_date=None, end_date=None, sample_prices= except errors.InputValidationError as ive: raise ive - print('inside statistics.calculate_risk_return') results = profile_cache.filter_profile_cache(ticker=ticker, start_date=start_date, end_date=end_date) - print('results', results) if results is not None \ and results[static.keys['STATISTICS']['RETURN']] is not None \ and results[static.keys['STATISTICS']['VOLATILITY']] is not None: @@ -689,16 +687,14 @@ def calculate_ito_correlation(ticker_1, ticker_2, asset_type_1=None, asset_type_ except errors.APIResponseError as api: raise api - if (len(sample_prices[ticker_1]) == 0) \ - or (len(sample_prices[ticker_2]) == 0) \ - or (len(sample_prices[ticker_1]) != len(sample_prices[ticker_2])) \ - or (len(helper.intersect_dict_keys(sample_prices[ticker_1], sample_prices[ticker_2])) == 0): - raise errors.PriceError("Prices cannot be retrieved for correlation calculation") - if asset_type_1 != asset_type_2: # remove weekends and holidays from crypto prices so samples can be compared sample_prices[ticker_1], sample_prices[ticker_2] = helper.intersect_dict_keys(sample_prices[ticker_1], sample_prices[ticker_2]) - + + if (len(sample_prices[ticker_1]) == 0) \ + or (len(sample_prices[ticker_2]) == 0): + raise errors.PriceError("Prices cannot be retrieved for correlation calculation") + if asset_type_1 == asset_type_2 and asset_type_1 == static.keys['ASSETS']['CRYPTO']: trading_period = static.constants['ONE_TRADING_DAY']['CRYPTO'] else: diff --git a/src/scrilla/cache.py b/src/scrilla/cache.py index 90ab4d73..fd68b6c7 100644 --- a/src/scrilla/cache.py +++ b/src/scrilla/cache.py @@ -149,7 +149,7 @@ def __init__(self): @staticmethod def to_dict(query_results): - return { static.keys['STATISTICS']['CORRELATION']: query_results[0] } + return { static.keys['STATISTICS']['CORRELATION']: query_results[0][0] } def save_row(self, ticker_1, ticker_2, start_date, end_date, correlation): logger.verbose(f'Saving ({ticker_1}, {ticker_2}) correlation from {start_date} to {end_date} to the cacche') @@ -245,10 +245,6 @@ def filter_profile_cache(self, ticker, start_date, end_date): formatter = { 'ticker': ticker, 'start_date': start_date, 'end_date': end_date} result = self.execute_query(query=ProfileCache.profile_query, formatter=formatter) - print(result) - for r in result: - for p in r: - print(p) if len(result)>0: return self.to_dict(result) else: diff --git a/src/scrilla/files.py b/src/scrilla/files.py index 5b1eb39e..7c64c6e6 100644 --- a/src/scrilla/files.py +++ b/src/scrilla/files.py @@ -273,7 +273,7 @@ def get_asset_type(symbol): #return None return static.keys['ASSETS']['EQUITY'] # default to equity for overlap until a better method is determined. - return None + return static.keys['ASSETS']['EQUITY'] def get_watchlist(): """ diff --git a/src/scrilla/main.py b/src/scrilla/main.py index d50ec706..c6138f68 100644 --- a/src/scrilla/main.py +++ b/src/scrilla/main.py @@ -1,4 +1,4 @@ -import sys, os +import sys, os, traceback # Note: need to import from package when running from wheel. # if running locally through main.py file, these imports should be replaced @@ -51,15 +51,15 @@ def validate_function_usage(selection, args, wrapper_function, required_length=1 # TODO: CLI APPLICATION ERROR HANDLING GOES HERE except errors.PriceError as pe: - logger.comment(str(pe)) + traceback.print_exc() except errors.SampleSizeError as se: - logger.comment(str(se)) + traceback.print_exc() except errors.APIResponseError as api: - logger.comment(str(api)) + traceback.print_exc() except errors.InputValidationError as ive: - logger.comment(str(ive)) + traceback.print_exc() except errors.ConfigurationError as ce: - logger.comment(str(ce)) + traceback.print_exc() def do_program(): if len(sys.argv)>0: diff --git a/src/scrilla/services.py b/src/scrilla/services.py index 53b86bbe..d053d9f6 100644 --- a/src/scrilla/services.py +++ b/src/scrilla/services.py @@ -223,7 +223,7 @@ def slice_prices(self, start_date, end_date, asset_type, prices): elif asset_type == static.keys['ASSETS']['CRYPTO']: start_index = list(prices[settings.AV_RES_CRYPTO_FIRST_LAYER].keys()).index(start_string) end_index = list(prices[settings.AV_RES_CRYPTO_FIRST_LAYER].keys()).index(end_string) - prices = dict(itertools.islice(prices[settings.AV_RES_CRYPTO_FIRST_LAYER].items(), end_index, start_index)) + prices = dict(itertools.islice(prices[settings.AV_RES_CRYPTO_FIRST_LAYER].items(), end_index, start_index+1)) return prices except KeyError as ke: @@ -309,7 +309,7 @@ def get_daily_price_history(ticker, start_date=None, end_date=None, asset_type=N (asset_type == static.keys['ASSETS']['EQUITY'] and (helper.business_days_between(start_date, end_date) + 1) == len(prices)) or - (asset_type == static.keys['ASSET']['CRYPTO'] + (asset_type == static.keys['ASSETS']['CRYPTO'] and (helper.days_between(start_date, end_date) + 1) == len(prices)) ): return prices