def build_portfolio(self, cash, max_per_note=<NUM_LIT>, min_percent=<NUM_LIT:0>, max_percent=<NUM_LIT:20>, filters=None, automatically_invest=False, do_not_clear_staging=False):
assert filters is None or isinstance(filters, Filter), '<STR_LIT>'<EOL>assert max_per_note >= <NUM_LIT>, '<STR_LIT>'<EOL>if filters:<EOL><INDENT>filter_str = filters.search_string()<EOL><DEDENT>else:<EOL><INDENT>filter_str = '<STR_LIT:default>'<EOL><DEDENT>self.session.clear_session_order()<EOL>payload = {<EOL>'<STR_LIT>': cash,<EOL>'<STR_LIT>': max_per_note,<EOL>'<STR_LIT>': filter_str<EOL>}<EOL>self.__log('<STR_LIT>'.format(cash, max_per_note))<EOL>response = self.session.post('<STR_LIT>', data=payload)<EOL>json_response = response.json()<EOL>if self.session.json_success(json_response) and '<STR_LIT>' in json_response:<EOL><INDENT>options = json_response['<STR_LIT>']<EOL>if type(options) is not list or json_response['<STR_LIT>'] == <NUM_LIT:0>:<EOL><INDENT>self.__log('<STR_LIT>')<EOL>return False<EOL><DEDENT>i = <NUM_LIT:0><EOL>match_index = -<NUM_LIT:1><EOL>match_option = None<EOL>for option in options:<EOL><INDENT>if option['<STR_LIT>'] == max_percent:<EOL><INDENT>match_option = option<EOL>match_index = i<EOL>break<EOL><DEDENT>elif option['<STR_LIT>'] > max_percent:<EOL><INDENT>break<EOL><DEDENT>elif option['<STR_LIT>'] >= min_percent and (match_option is None or match_option['<STR_LIT>'] < option['<STR_LIT>']):<EOL><INDENT>match_option = option<EOL>match_index = i<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>if match_option is None:<EOL><INDENT>self.__log('<STR_LIT>')<EOL>return False<EOL><DEDENT>payload = {<EOL>'<STR_LIT>': cash,<EOL>'<STR_LIT>': match_index,<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>self.session.get('<STR_LIT>', query=payload)<EOL>payload = {<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>response = self.session.get('<STR_LIT>', query=payload)<EOL>json_response = response.json()<EOL>fractions = []<EOL>if '<STR_LIT>' in json_response:<EOL><INDENT>fractions = json_response['<STR_LIT>']<EOL>for frac in fractions:<EOL><INDENT>frac['<STR_LIT>'] = frac['<STR_LIT>']<EOL>if frac['<STR_LIT>'] > max_per_note:<EOL><INDENT>raise LendingClubError('<STR_LIT>'.format(frac['<STR_LIT>'], max_per_note))<EOL><DEDENT><DEDENT><DEDENT>if len(fractions) == <NUM_LIT:0>:<EOL><INDENT>self.__log('<STR_LIT>')<EOL>return False<EOL><DEDENT>match_option['<STR_LIT>'] = fractions<EOL>if filters is not None:<EOL><INDENT>filters.validate(fractions)<EOL><DEDENT>if automatically_invest is not True:<EOL><INDENT>if do_not_clear_staging is not True:<EOL><INDENT>self.session.clear_session_order()<EOL><DEDENT><DEDENT>elif automatically_invest is True:  <EOL><INDENT>order = self.start_order()<EOL>order._Order__already_staged = True<EOL>order._Order__i_know_what_im_doing = True<EOL>order.add_batch(match_option['<STR_LIT>'])<EOL>order_id = order.execute()<EOL>match_option['<STR_LIT>'] = order_id<EOL><DEDENT>return match_option<EOL><DEDENT>else:<EOL><INDENT>raise LendingClubError('<STR_LIT>', response)<EOL><DEDENT>return False<EOL>
Returns a list of loan notes that are diversified by your min/max percent request and filters.
One way to invest in these loan notes, is to start an order and use add_batch to add all the
loan fragments to them. (see examples)

Parameters
----------
cash : int
    The total amount you want to invest across a portfolio of loans (at least $25).
max_per_note : int, optional
    The maximum dollar amount you want to invest per note. Must be a multiple of 25
min_percent : int, optional
    THIS IS NOT PER NOTE, but the minimum average percent of return for the entire portfolio.
max_percent : int, optional
    THIS IS NOT PER NOTE, but the maxmimum average percent of return for the entire portfolio.
filters : lendingclub.filters.*, optional
    The filters to use to search for portfolios
automatically_invest : boolean, optional
    If you want the tool to create an order and automatically invest in the portfolio that matches your filter.
    (default False)
do_not_clear_staging : boolean, optional
    Similar to automatically_invest, don't do this unless you know what you're doing.
    Setting this to True stops the method from clearing the loan staging area before returning

Returns
-------
dict
    A dict representing a new portfolio or False if nothing was found.
    If `automatically_invest` was set to `True`, the dict will contain an `order_id` key with
    the ID of the completed investment order.

Notes
-----
**The min/max_percent parameters**

When searching for portfolios, these parameters will match a portfolio of loan notes which have
an **AVERAGE** percent return between these values. If there are multiple portfolio matches, the
one closes to the max percent will be chosen.

Examples
--------
Here we want to invest $400 in a portfolio with only B, C, D and E grade notes with an average overall return between 17% - 19%. This similar to finding a portfolio in the 'Invest' section on lendingclub.com::

    >>> from lendingclub import LendingClub
    >>> from lendingclub.filters import Filter
    >>> lc = LendingClub()
    >>> lc.authenticate()
    Email:test@test.com
    Password:
    True
    >>> filters = Filter()                  # Set the search filters (only B, C, D and E grade notes)
    >>> filters['grades']['C'] = True
    >>> filters['grades']['D'] = True
    >>> filters['grades']['E'] = True
    >>> lc.get_cash_balance()               # See the cash you have available for investing
    463.80000000000001

    >>> portfolio = lc.build_portfolio(400, # Invest $400 in a portfolio...
            min_percent=17.0,               # Return percent average between 17 - 19%
            max_percent=19.0,
            max_per_note=50,                # As much as $50 per note
            filters=filters)                # Search using your filters

    >>> len(portfolio['loan_fractions'])    # See how many loans are in this portfolio
    16
    >>> loans_notes = portfolio['loan_fractions']
    >>> order = lc.start_order()            # Start a new order
    >>> order.add_batch(loans_notes)        # Add the loan notes to the order
    >>> order.execute()                     # Execute the order
    1861880

Here we do a similar search, but automatically invest the found portfolio. **NOTE** This does not allow
you to review the portfolio before you invest in it.

    >>> from lendingclub import LendingClub
    >>> from lendingclub.filters import Filter
    >>> lc = LendingClub()
    >>> lc.authenticate()
    Email:test@test.com
    Password:
    True
                                            # Filter shorthand
    >>> filters = Filter({'grades': {'B': True, 'C': True, 'D': True, 'E': True}})
    >>> lc.get_cash_balance()               # See the cash you have available for investing
    463.80000000000001

    >>> portfolio = lc.build_portfolio(400,
            min_percent=17.0,
            max_percent=19.0,
            max_per_note=50,
            filters=filters,
            automatically_invest=True)      # Same settings, except invest immediately

    >>> portfolio['order_id']               # See order ID
    1861880