def test_prompt_int(self):

        # Return empty string first, then string, finally an int value the last time asked
        def get_input(msg):
            self.count += 1
            if self.count == 1:
                return ''
            elif self.count == 2:
                return 'Hi'
            else:
                return '10'

        util.get_input = get_input
        self.assertEqual(util.prompt_float('msg'), 10)
        self.assertEqual(self.count, 3)

        # Values with commas
        util.get_input = lambda msg: '1,000.1'
        self.assertEqual(util.prompt_float('msg'), 1000.1)
    def test_prompt_int(self):

        # Return empty string first, then string, finally an int value the last time asked
        def get_input(msg):
            self.count += 1
            if self.count == 1:
                return ""
            elif self.count == 2:
                return "Hi"
            else:
                return "10"

        util.get_input = get_input
        self.assertEqual(util.prompt_float("msg"), 10)
        self.assertEqual(self.count, 3)

        # Values with commas
        util.get_input = lambda msg: "1,000.1"
        self.assertEqual(util.prompt_float("msg"), 1000.1)
Exemplo n.º 3
0
    def get_filter_settings(self):
        """
        Setup the advanced portfolio filters (terms, grades, existing notes, etc.)
        """

        # Saved filter
        saved_filters = self.investor.lc.get_saved_filters()
        if len(saved_filters) > 0 and util.prompt_yn('Would you like to select one of your saved filters from LendingClub.com?', self.investing['filter_id'] is not None):

            # Get the selected one from list (has to be same-same object)
            selected = None
            if self.investing['filter_id']:
                selected = self.investing['filter_id']

            print '\nSelect a saved filter from the list below:'
            saved = self.list_picker(
                items=saved_filters,
                default=selected,
                label_key='name',
                id_key='id')

            if saved is False:
                print '\nDefine all your filters manually...'
            else:
                print 'Using {0}'.format(saved)
                self.investing['filters'] = saved
                self.investing['filter_id'] = saved.id
                return

        filters = Filter()

        # Manual entry
        print 'The following questions are from the filters section of the Invest page on LendingClub\n'

        # Existing loans
        filters['exclude_existing'] = util.prompt_yn('Exclude loans already invested in?', filters['exclude_existing'])

        # Funding progress rounded to the nearest tenth
        print '---------'
        print 'Funding progress'
        progress = util.prompt_float('Only include loans which already have at least __% funding (0 - 100)', filters['funding_progress'])
        filters['funding_progress'] = int(round(progress / 10) * 10)

        print '---------'
        print 'Choose term (36 - 60 month)'

        while(True):
            filters['term']['Year3'] = util.prompt_yn('Include 36 month term loans?', filters['term']['Year3'])
            filters['term']['Year5'] = util.prompt_yn('Include 60 month term loans?', filters['term']['Year5'])

            # Validate 1 was chosen
            if not filters['term']['Year3'] and not filters['term']['Year5']:
                print 'You have to AT LEAST choose one term length!'
            else:
                break

        print '---------'
        print 'Choose interest rate grades (7.4% - 24.84%)'
        while(True):
            if util.prompt_yn('Include ALL interest rate grades', filters['grades']['All']):
                filters['grades']['All'] = True
            else:
                filters['grades']['All'] = False
                filters['grades']['A'] = util.prompt_yn('A - ~7.41%', filters['grades']['A'])
                filters['grades']['B'] = util.prompt_yn('B - ~12.12%', filters['grades']['B'])
                filters['grades']['C'] = util.prompt_yn('C - ~15.80%', filters['grades']['C'])
                filters['grades']['D'] = util.prompt_yn('D - ~18.76%', filters['grades']['D'])
                filters['grades']['E'] = util.prompt_yn('E - ~21.49%', filters['grades']['E'])
                filters['grades']['F'] = util.prompt_yn('F - ~23.49%', filters['grades']['F'])
                filters['grades']['G'] = util.prompt_yn('G - ~24.84%', filters['grades']['G'])

            # Verify one was chosen
            gradeChosen = False
            for grade in filters['grades']:
                if filters['grades'][grade] is True:
                    gradeChosen = True
            if not gradeChosen:
                print 'You have to AT LEAST choose one interest rate grade!'
            else:
                break

        self.investing['filters'] = filters
Exemplo n.º 4
0
    def get_investment_settings(self):
        """
        Display a series of prompts to get how the user wants to invest their available cash.
        This fills out the investing dictionary.
        """

         # Minimum cash
        print '---------'
        print 'The auto investor will automatically try to invest ALL available cash into a diversified portfolio'
        while(True):
            self.investing['min_cash'] = util.prompt_int('What\'s the MINIMUM amount of cash you want to invest each round?', self.investing['min_cash'])
            if self.investing['min_cash'] < 25:
                print '\nYou cannot invest less than $25. Please try again.'
            else:
                break

        # Min/max percent
        print '---------'
        while(True):
            print 'When auto investing, the LendingClub API will search for diversified investment portfolios available at that moment.'
            print 'To pick the appropriate one for you, it needs to know what the minimum and maximum AVERAGE interest rate value you will accept.'
            print 'The investment option closest to the maximum value will be chosen and all your available cash will be invested in it.\n'

            self.investing['min_percent'] = util.prompt_float('What\'s MININUM average interest rate portfolio that you will accept?', self.investing['min_percent'])

            # Max percent should default to being larger than the min percent
            if self.investing['max_percent'] is False or self.investing['max_percent'] < self.investing['min_percent']:
                self.investing['max_percent'] = self.investing['min_percent'] + 1
            self.investing['max_percent'] = util.prompt_float('What\'s MAXIMUM average interest rate portfolio that you will accept?', self.investing['max_percent'])

            # Validation
            if self.investing['max_percent'] < self.investing['min_percent']:
                print 'The maximum value must be larger than, or equal to, the minimum value. Please try again.'
            elif self.investing['max_percent'] == self.investing['min_percent']:
                print 'It\'s very uncommon to find an available portfolio that will match an exact percent.'
                if not util.prompt_yn('Would you like to specify a broader range?'):
                    break
            else:
                break

        # Max per note
        print '---------'
        while(True):
            self.investing['max_per_note'] = util.prompt_int('How much are you willing to invest per loan note (max per note)?', self.investing['max_per_note'])

            if self.investing['max_per_note'] < 25:
                print 'You have to invest AT LEAST $25 per note.'
                self.investing['max_per_note'] = 25
            else:
                break


        # Portfolio
        print '---------'
        folioOption = False
        if self.investing['portfolio']:  # if saved settings has a portfolio set, default the prompt to 'Y' to choose
            folioOption = 'y'

        if util.prompt_yn('Do you want to put your new investments into a named portfolio?', folioOption):
            self.investing['portfolio'] = self.portfolio_picker(self.investing['portfolio'])
        else:
            self.investing['portfolio'] = False

        print '\n---------'

        # Advanced filter settings
        if util.prompt_yn('Would you like to set advanced filter settings?', self.investing['filters'] is not False):
            self.get_filter_settings()

        # Review summary
        self.confirm_settings()
        return True
 def test_prompt_float_prefill(self):
     # User enters empty string, select prefill
     util.get_input = lambda msg: ''
     self.assertEqual(util.prompt_float('msg', 10.1), 10.1)
 def test_prompt_float_prefill(self):
     # User enters empty string, select prefill
     util.get_input = lambda msg: ""
     self.assertEqual(util.prompt_float("msg", 10.1), 10.1)
    def get_filter_settings(self):
        """
        Setup the advanced portfolio filters (terms, grades, existing notes, etc.)
        """

        # Saved filter
        saved_filters = self.investor.lc.get_saved_filters()
        if len(saved_filters) > 0 and util.prompt_yn('Would you like to select one of your saved filters from LendingClub.com?', self.investing['filter_id'] is not None):

            # Get the selected one from list (has to be same-same object)
            selected = None
            if self.investing['filter_id']:
                selected = self.investing['filter_id']

            print('\nSelect a saved filter from the list below:')
            saved = self.list_picker(
                items=saved_filters,
                default=selected,
                label_key='name',
                id_key='id')

            if saved is False:
                print('\nDefine all your filters manually...')
            else:
                print('Using {0}'.format(saved))
                self.investing['filters'] = saved
                self.investing['filter_id'] = saved.id
                return

        filters = Filter()

        # Manual entry
        print('The following questions are from the filters section of the Invest page on LendingClub\n')

        # Existing loans
        filters['exclude_existing'] = util.prompt_yn('Exclude loans already invested in?', filters['exclude_existing'])

        # Funding progress rounded to the nearest tenth
        print('---------')
        print('Funding progress')
        progress = util.prompt_float('Only include loans which already have at least __% funding (0 - 100)', filters['funding_progress'])
        filters['funding_progress'] = int(round(progress / 10) * 10)

        print('---------')
        print('Choose term (36 - 60 month)')

        while(True):
            filters['term']['Year3'] = util.prompt_yn('Include 36 month term loans?', filters['term']['Year3'])
            filters['term']['Year5'] = util.prompt_yn('Include 60 month term loans?', filters['term']['Year5'])

            # Validate 1 was chosen
            if not filters['term']['Year3'] and not filters['term']['Year5']:
                print('You have to AT LEAST choose one term length!')
            else:
                break

        print('---------')
        print('Choose interest rate grades (7.4% - 24.84%)')
        while(True):
            if util.prompt_yn('Include ALL interest rate grades', filters['grades']['All']):
                filters['grades']['All'] = True
            else:
                filters['grades']['All'] = False
                filters['grades']['A'] = util.prompt_yn('A - ~7.41%', filters['grades']['A'])
                filters['grades']['B'] = util.prompt_yn('B - ~12.12%', filters['grades']['B'])
                filters['grades']['C'] = util.prompt_yn('C - ~15.80%', filters['grades']['C'])
                filters['grades']['D'] = util.prompt_yn('D - ~18.76%', filters['grades']['D'])
                filters['grades']['E'] = util.prompt_yn('E - ~21.49%', filters['grades']['E'])
                filters['grades']['F'] = util.prompt_yn('F - ~23.49%', filters['grades']['F'])
                filters['grades']['G'] = util.prompt_yn('G - ~24.84%', filters['grades']['G'])

            # Verify one was chosen
            gradeChosen = False
            for grade in filters['grades']:
                if filters['grades'][grade] is True:
                    gradeChosen = True
            if not gradeChosen:
                print('You have to AT LEAST choose one interest rate grade!')
            else:
                break

        self.investing['filters'] = filters
    def get_investment_settings(self):
        """
        Display a series of prompts to get how the user wants to invest their available cash.
        This fills out the investing dictionary.
        """

         # Minimum cash
        print('---------')
        print('The auto investor will automatically try to invest ALL available cash into a diversified portfolio')
        while(True):
            self.investing['min_cash'] = util.prompt_int('What\'s the MINIMUM amount of cash you want to invest each round?', self.investing['min_cash'])
            if self.investing['min_cash'] < 25:
                print('\nYou cannot invest less than $25. Please try again.')
            else:
                break

        # Min/max percent
        print('---------')
        while(True):
            print('When auto investing, the LendingClub API will search for diversified investment portfolios available at that moment.')
            print('To pick the appropriate one for you, it needs to know what the minimum and maximum AVERAGE interest rate value you will accept.')
            print('The investment option closest to the maximum value will be chosen and all your available cash will be invested in it.\n')

            self.investing['min_percent'] = util.prompt_float('What\'s MININUM average interest rate portfolio that you will accept?', self.investing['min_percent'])

            # Max percent should default to being larger than the min percent
            if self.investing['max_percent'] is False or self.investing['max_percent'] < self.investing['min_percent']:
                self.investing['max_percent'] = self.investing['min_percent'] + 1
            self.investing['max_percent'] = util.prompt_float('What\'s MAXIMUM average interest rate portfolio that you will accept?', self.investing['max_percent'])

            # Validation
            if self.investing['max_percent'] < self.investing['min_percent']:
                print('The maximum value must be larger than, or equal to, the minimum value. Please try again.')
            elif self.investing['max_percent'] == self.investing['min_percent']:
                print('It\'s very uncommon to find an available portfolio that will match an exact percent.')
                if not util.prompt_yn('Would you like to specify a broader range?'):
                    break
            else:
                break

        # Max per note
        print('---------')
        while(True):
            self.investing['max_per_note'] = util.prompt_int('How much are you willing to invest per loan note (max per note)?', self.investing['max_per_note'])

            if self.investing['max_per_note'] < 25:
                print('You have to invest AT LEAST $25 per note.')
                self.investing['max_per_note'] = 25
            else:
                break


        # Portfolio
        print('---------')
        folioOption = False
        if self.investing['portfolio']:  # if saved settings has a portfolio set, default the prompt to 'Y' to choose
            folioOption = 'y'

        if util.prompt_yn('Do you want to put your new investments into a named portfolio?', folioOption):
            self.investing['portfolio'] = self.portfolio_picker(self.investing['portfolio'])
        else:
            self.investing['portfolio'] = False

        print('\n---------')

        # Advanced filter settings
        if util.prompt_yn('Would you like to set advanced filter settings?', self.investing['filters'] is not False):
            self.get_filter_settings()

        # Review summary
        self.confirm_settings()
        return True