Exemple #1
0
 def testInsertMasterEquities(self):
     all_equities = RobotEquitySymbols.insertMasterEquities(count=3)
     total_number = RobotEquitySymbols.getTotalMaster()
     self.assertEqual(total_number, 3)
     self.assertEqual(
         RobotEquitySymbols.isValidPair(bull='TQQQ', bear='SQQQ'), True)
     self.assertEqual(
         RobotEquitySymbols.isValidPair(bull='SQQQ', bear='TQQQ'), False)
     self.assertEqual(
         RobotEquitySymbols.isValidPair(bull='LABU', bear='LABD'), True)
Exemple #2
0
    def testExecutionEngineViaDatabaseEntriesFeed(self):
        #Set up the Data to feed the Robot.
        number_entries = 1  #Nasdaq100 Only (TQQQ, SQQQ, QQQ)
        RobotEquitySymbols.insertMasterEquities(count=number_entries)
        #Start Date on October 01
        start_date = datetime.datetime(2020, 10, 1,
                                       tzinfo=timezone.utc).isoformat()
        backtesting = BackTestInfrastructure(action='download',
                                             useMasterTable=True)
        response = backtesting.processTradeData(start_date=start_date)
        response0 = backtesting.downloadAndStore(target='both', update=False)
        #Data has loaded completely.

        db_infrastructure = BackTestDatabaseInfrastructure(
            bull_symbol=self.bullish,
            bear_symbol=self.bearish,
            etf_symbol=self.etf)
        #Find the Robot to carry the Execution
        robot_0 = ETFAndReversePairRobot.objects.get(pk=self.robot_id)

        #Create and Save a new ETFPairRobotExecution Instance
        start_date_s = datetime.datetime(2020, 10, 1,
                                         tzinfo=timezone.utc).isoformat()
        end_date_s = datetime.datetime(2020, 10, 28,
                                       tzinfo=timezone.utc).isoformat()

        executor = ETFPairRobotExecution.createRobotExecution(
            exec_start_date=start_date_s,
            exec_end_date=end_date_s,
            robot=robot_0)

        #Create a new RobotExecutionEngine
        exec1 = ETFPairBackTestRobotExecutionEngine(
            robot=robot_0,
            executor_id=executor.id,
            request=None,
            datasource=db_infrastructure)

        #Perform the Backtest. There might be a delay in completing the execution.
        results = exec1.executeBackTest()

        #Retrieve the Financial Results
        financial_results = exec1.getExecEngineFinancialReport()
        #print (" {}".format(financial_results))
        financial_summary = financial_results['summary']
        financial_entries = financial_results['entries']
        self.assertTrue(int(financial_summary['transactions']) > 0)
        self.assertTrue(len(financial_entries) > 0)

        #Replay the execution
        replay_results = exec1.getExecEngineReplayReport()
        replay_summary = replay_results['summary']
        replay_entries = replay_results['entries']
        self.assertTrue(int(replay_summary['transactions']) > 0)
        self.assertTrue(len(replay_entries) > 0)
Exemple #3
0
 def setUpTestData(self):
     displayOutput(
         str="Setting up Test Data for test: {}".format(self.test_name))
     #Set up the Data to feed the Robot.
     RobotEquitySymbols.insertMasterEquities(count=self.number_entries)
     #Start Date on October 01
     start_date = datetime.datetime(2020, 10, 1,
                                    tzinfo=timezone.utc).isoformat()
     backtesting = BackTestInfrastructure(action='download',
                                          useMasterTable=True)
     response = backtesting.processTradeData(start_date=start_date)
     response0 = backtesting.downloadAndStore(target='both', update=False)
Exemple #4
0
def refresh_robot_symbols(request, pk):
    logger.debug("Robot Equity Symbols {0}".format(pk))

    user = request.user.get_username()
    robot = ETFAndReversePairRobot.objects.get(pk=pk)
    symbols = robot.symbols
    #print("symbols {0}".format(symbols.getBullishSymbol()))
    pair = dict()
    pair['bull_symbol'] = symbols.getBullishSymbol()
    pair['bear_symbol'] = symbols.getBearishSymbol()
    pair['etf_symbol'] = symbols.getSymbol()

    hour_data = RobotEquitySymbols.getHourlyEquitiesData(pair=pair)
    today_data = RobotEquitySymbols.getTodayEquitiesData(pair=pair)
    week_data = RobotEquitySymbols.getWeekEquitiesData(pair=pair)
    two_weeks_data = RobotEquitySymbols.getTwoWeeksEquitiesData(pair=pair)
    three_weeks_data = RobotEquitySymbols.getThreeWeeksEquitiesData(pair=pair)
    four_weeks_data = RobotEquitySymbols.getFourWeeksEquitiesData(pair=pair)

    symbol_form = RobotEquitySymbolsForm(user_name=user)

    context = {
        'all_symbols': pair,
        'hour_data': hour_data,
        'today_data': today_data,
        'week_data': week_data,
        'two_weeks_data': two_weeks_data,
        'three_weeks_data': three_weeks_data,
        'four_weeks_data': four_weeks_data
    }
    return render(request, 'robot/tabs/equities.html', context)
Exemple #5
0
    def testEquitiesDataTest(self):
        pair = dict()
        pair['bull_symbol'] = 'TQQQ'
        pair['bear_symbol'] = 'SQQQ'
        pair['etf_symbol'] = 'QQQ'

        res_hour = RobotEquitySymbols.getHourlyEquitiesData(pair=pair)
        res_today = RobotEquitySymbols.getTodayEquitiesData(pair=pair)
        res_week = RobotEquitySymbols.getWeekEquitiesData(pair=pair)
        res_2_weeks = RobotEquitySymbols.getTwoWeeksEquitiesData(pair=pair)
        res_3_weeks = RobotEquitySymbols.getThreeWeeksEquitiesData(pair=pair)
        res_4_weeks = RobotEquitySymbols.getFourWeeksEquitiesData(pair=pair)

        #Difficult to Assert?
        self.assertTrue(int(res_hour['bull_h']) > 0)
        self.assertTrue(int(res_hour['bull_l']) > 0)
        self.assertTrue(int(res_hour['bull_a']) > 0)
        self.assertTrue(int(res_hour['bull_s']) > 0)

        self.assertTrue(int(res_hour['bear_h']) > 0)
        self.assertTrue(int(res_hour['bear_l']) > 0)
        self.assertTrue(int(res_hour['bear_a']) > 0)
        self.assertTrue(int(res_hour['bear_s']) >= 0)

        self.assertTrue(int(res_hour['etf_h']) > 0)
        self.assertTrue(int(res_hour['etf_l']) > 0)
        self.assertTrue(int(res_hour['etf_a']) > 0)
        self.assertTrue(int(res_hour['etf_s']) >= 0)
Exemple #6
0
 def matchWithAllowedSymbols(self):
     entries = self.config['entries']
     for x in entries:
         valid_pair = RobotEquitySymbols.isValidPair(bull=x['bull'],
                                                     bear=x['bear'],
                                                     etf=x['etf'])
         if not valid_pair:
             data = "Data: Bull={} Bear={} Etf={}".format(
                 x['bull'], x['bear'], x['etf'])
             displayOutput(
                 str=
                 "ERROR: Invalid Config File Entry. Bull/Bear entry is not in list of approved Bull/Bear ETFs. {}"
                 .format(data))
             self.valid = False
             break
     return
Exemple #7
0
    def __init__(self,
                 config_file=None,
                 config_file_folder=None,
                 start_date=None,
                 action=None,
                 useMasterTable=False):
        #Not used.
        #self.tests_root_folder_key='EGGHEAD_TESTS_FOLDER'
        self.config_folder_key = 'EGGHEAD_CONFIG_FOLDER'
        self.config_file_key = 'EGGHEAD_CONFIG_FILE'
        self.data_folder_root_key = 'EGGHEAD_DATA_FOLDER'
        self.default_config_file = 'config_egghead.json'
        # Keys
        self.bullish_key = 'bull'
        self.bearish_key = 'bear'
        self.etf_key = 'etf'
        self.entries_key = 'entries'

        self.valid = True
        self.config = None
        #datetime.datetime(2020,10,1,tzinfo=timezone.utc).isoformat()
        self.default_start_date = (date.today() +
                                   datetime.timedelta(days=-1)).isoformat()
        self.default_end_date = (date.today() +
                                 datetime.timedelta(days=-1)).isoformat()

        if (useMasterTable):
            displayOutput(str="Loading all ETFs from Master File")
            entries = dict()
            self.config = RobotEquitySymbols.getMasterEntriesAsJSON()
        elif (action == 'download' or (action == None)):
            self.config_file = config_file
            self.config_file_folder = config_file_folder
            self.processConfigEntries()

        self.default_trading_unit = 5  #5 minutes interval of data
        self.default_trading_unit_etf = 60  #For ETFs, we use 60 minutes intervals
        self.default_resolution = 'minute'  # We use Minute units