def generate_final_report (symbol, info: 'ask_for_quote_info') -> 'final report': ''' Formats the final analysis report ''' closing_prices = info[0] dates = info[1] format_str = '{:<14} {:<10} {:<10} {:<10}' response = input(MENU) if response.strip() == 's': result = SignalStrategies.run_signal_strategy(Indicators.SimpleMovingAverage(), info[0]) indicator = result[0] signal = result [1] days = result[2] print('\n--------------------- Here is the final analysis report ---------------------\n') print('SYMBOL: {} \nSTRATEGY: Simple moving average ({}-day)\n'.format(symbol, days)) print('DATE CLOSE INDICATOR SIGNAL') for i in range(len(indicator)): print(format_str.format(dates[i], closing_prices[i], indicator[i], signal[i])) elif response.strip() == 'd': buy_threshold = input('Enter a buy threshold: ') sell_threshold = input('Enter a sell threshold: ') result = SignalStrategies.run_signal_strategy(Indicators.Directional(), info[0]) indicator = [] signal = [] days = result[2] for i in result[0]: if i > 0: indicator.append('+{}'.format(i)) else: indicator.append(i) for i in range(len(result[1])): if result[1][i] == result[1][i-1]: result[1][i] = '-' signal.append(result[1][i]) else: signal.append(result[1][i]) print('\n--------------------- Here is the final analysis report ---------------------\n') print('SYMBOL: {}\nSTRATEGY: Directional ({}-day), buy above +{}, sell below {}\n'.format( symbol, days, buy_threshold, sell_threshold)) print('DATE CLOSE INDICATOR SIGNAL') for i in range(len(indicator)): print(format_str.format(dates[i], closing_prices[i], indicator[i], signal[i]))
def calcDirectionalSignal(indicator:list, days:int): buy = int(input('Enter your buying threshold: ')) sell = int(input('Enter your selling threshold: ')) while sell > buy: print('The selling threshold should be below the buying threshold. ') sell = int(input('Enter your selling threshold: ')) p = SignalStrategies.directionalIndicatorStrategy(buy,sell) return p.execute(indicator)
def indicator_and_signal(price_list): while True: try: strategy = UserIOUtils.ask_for_signal_strategy() period = UserIOUtils.ask_for_period() if strategy == 1: buy_signal, sell_signal = '+', '-' SMA = SignalStrategies.simple_moving_average(price_list, period) indicator_list, signal_list = SMA.execute() else: buy_signal, sell_signal = UserIOUtils.ask_for_buy_and_sell_signals() DI = SignalStrategies.directional_indicator(price_list, period, buy_signal, sell_signal) indicator_list, signal_list = DI.execute() return strategy, period, buy_signal, sell_signal, indicator_list, signal_list except Exception as error: print("Invalid @ indicatorAndSignal. Please try again.")
def calcSimpleMovingAverageSignal(indicator:list, days:int, closePrices:list): p = SignalStrategies.simpleMovingAverageStrategy(indicator,days) return p.execute(closePrices)