Esempio n. 1
0
 def test_from_configuration_invalid(self):
     with patch('support.constants.CONFIG_FILE_PATH',
                "./test/config-unittest-bad/"):
         with self.assertRaises(ValidationError):
             PriceDispersionStrategy.from_configuration(
                 Configuration.from_local_config("bad-test-config.ini"),
                 'sa')
Esempio n. 2
0
    def test_from_configuration_valid(self):

        ticker_list = TickerList.from_local_file("%s/djia30.json" %
                                                 (constants.APP_DATA_DIR))

        with patch.object(util, 'get_business_date',
                          return_value=date(2020, 6, 3)), \
            patch.object(pd, 'to_datetime',
                         return_value=datetime(2020, 6, 19)), \
            patch.object(TickerList, 'from_s3',
                         return_value=ticker_list):

            strategy = PriceDispersionStrategy.from_configuration(
                Configuration.from_local_config(
                    constants.STRATEGY_CONFIG_FILE_NAME), 'sa')

            self.assertEqual(strategy.analysis_start_date, date(2020, 5, 1))
            self.assertEqual(strategy.analysis_end_date, date(2020, 5, 31))
            self.assertEqual(strategy.current_price_date, date(2020, 6, 3))
        '''
def main():
    """
        Main function for this script
    """
    try:
        app_ns = parse_params()

        log.info("Parameters:")
        log.info("Application Namespace: %s" % app_ns)

        business_date = util.get_business_date(
            constants.BUSINESS_DATE_DAYS_LOOKBACK, constants.BUSINESS_DATE_CUTOVER_TIME)
        log.info("Business Date is: %s" % business_date)

        # test all connectivity upfront, so if there any issues
        # the problem becomes more apparent
        connector_test.test_aws_connectivity()
        connector_test.test_intrinio_connectivity()

        log.info('Loading Strategy Configuration "%s" from S3' %
                 constants.STRATEGY_CONFIG_FILE_NAME)
        configuration = Configuration.try_from_s3(
            constants.STRATEGY_CONFIG_FILE_NAME, app_ns)

        log.info("Initalizing Trading Strategies")
        strategies = [
            PriceDispersionStrategy.from_configuration(configuration, app_ns),
            MACDCrossoverStrategy.from_configuration(configuration, app_ns)
        ]

        notification_list = []
        for strategy in strategies:
            recommendation_set = None
            try:
                log.info("Executing %s strategy" % strategy.STRATEGY_NAME)
                recommendation_set = SecurityRecommendationSet.from_s3(
                    app_ns, strategy.S3_RECOMMENDATION_SET_OBJECT_NAME)
            except AWSError as awe:
                if not awe.resource_not_found():
                    raise awe
                log.info("No recommendation set was found in S3.")

            if recommendation_set == None  \
                    or not recommendation_set.is_current(business_date):

                strategy.generate_recommendation()
                strategy.display_results()

                recommendation_set = strategy.recommendation_set

                recommendation_set.save_to_s3(
                    app_ns, strategy.S3_RECOMMENDATION_SET_OBJECT_NAME)

                notification_list.append(recommendation_set)
            else:
                log.info(
                    "Recommendation set is still valid. There is nothing to do")

        recommendation_svc.notify_new_recommendation(
            notification_list, app_ns)
    except Exception as e:
        stack_trace = traceback.format_exc()
        log.error("Could run script, because: %s" % (str(e)))
        log.error(stack_trace)