def get_row(pair, command): ps = process_pair_string(pair) ticker1 = ps.ticker1 ticker2 = ps.ticker2 fixed_stdev_ratio = ps.stdev_ratio back_days = core.safe_execute(gcnv.PAIR_BACK_DAYS, ValueError, lambda x: int(x) * 30, command[2]) bring_if_connected(ticker1) bring_if_connected(ticker2) try: pair = Pair(ticker1, ticker2, fixed_stdev_ratio) max_stored_date = gcnv.data_handler.get_max_stored_date( "stock", ticker1) date = '-' if max_stored_date is None \ else util.date_in_string(max_stored_date) # Need to change this row = [ ticker1 + '-' + ticker2, date, '-', pair.get_last_close( back_days), # GettingInfoError raised here if not stored data pair.min(back_days), pair.max(back_days), pair.current_rank(back_days), pair.ma(back_days), '-', pair.stdev_ratio(back_days), pair.correlation(back_days), pair.hv_to_10_ratio(back_days), '-' ] closes = pair.closes(back_days)[-gcnv.PAIR_PAST_RESULTS:] closes.reverse() row += closes return row except (GettingInfoError, ZeroDivisionError, statistics.StatisticsError) as e: print(e) return []
def get_row(ticker, command): try: bring_if_connected(ticker) date = gcnv.data_handler.get_max_stored_date("stock", ticker) if date is None: return [] date = util.date_in_string(date) back_days = core.safe_execute(gcnv.BACK_DAYS, ValueError, lambda x: int(x) * 30, command[2]) iv = IV(ticker) hv = HV(ticker) mixed_vs = MixedVs(iv, hv) stock = Stock(ticker) spy_pair = Pair(ticker, "SPY") spy_iv = IV("SPY") earnings_data = load_earnings() row = [ticker, date] # Price related data row += [ stock.get_close_at( date), # GettingInfoError raised here if not stored data f"{stock.min(back_days)} - {stock.max(back_days)}", round(stock.min_max_rank(date, back_days)), stock.range(28) / spy_pair.stdev_ratio(back_days), stock.range(14) / spy_pair.stdev_ratio(back_days), stock.move(7) / spy_pair.stdev_ratio(back_days), stock.get_last_percentage_change(), up_down_closes_str(stock, 14), core.safe_execute('-', GettingInfoError, spy_pair.correlation, back_days), spy_pair.stdev_ratio(back_days), stock.hv_to_10_ratio(back_days), round( notional.directional_stock_number( stock.get_close_at(date), spy_pair.stdev_ratio(back_days))), round( notional.neutral_options_number( stock.get_close_at(date), spy_pair.stdev_ratio(back_days)), 1), round( notional.directional_options_number( stock.get_close_at(date), spy_pair.stdev_ratio(back_days)), 1), earnings_data[ticker][0], earnings_data[ticker][1], chart_link(ticker) ] # Volatility related data try: row += [ iv.current_to_average_ratio(date, back_days), mixed_vs.iv_current_to_hv_average(date, back_days), mixed_vs.positive_difference_ratio(back_days), mixed_vs.difference_average(back_days), iv.current_percentile_iv_rank(back_days) ] row += iv.period_iv_ranks(back_days, max_results=gcnv.IVR_RESULTS) except (GettingInfoError, ZeroDivisionError, statistics.StatisticsError) as e: result_row_len = 5 # Number of rows above row += ['-'] * (result_row_len + gcnv.IVR_RESULTS) return row except (GettingInfoError, InputError, ZeroDivisionError, statistics.StatisticsError) as e: print(e) return []