<s> """<STR_LIT>""" <EOL> import random <EOL> from fms import agents <EOL> from fms . utils import BUY , SELL <EOL> from fms . utils . exceptions import MissingParameter <EOL> class RandomFixedTraderHalves ( agents . Agent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , params , offset = <NUM_LIT:0> ) : <EOL> agents . Agent . __init__ ( self , params , offset ) <EOL> try : <EOL> self . maxprice = self . args [ <NUM_LIT:0> ] <EOL> except ( AttributeError , IndexError ) : <EOL> raise MissingParameter , '<STR_LIT>' <EOL> try : <EOL> self . maxbuy = self . args [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> raise MissingParameter , '<STR_LIT>' <EOL> del self . args <EOL> self . buyprice = random . randint ( <NUM_LIT:1> , int ( self . maxprice * <NUM_LIT:50> ) ) / <NUM_LIT> <EOL> self . sellprice = random . randint ( int ( self . maxprice * <NUM_LIT:50> ) , self . maxprice * <NUM_LIT:100> ) / <NUM_LIT> <EOL> def act ( self , world = None , market = None ) : <EOL> """<STR_LIT>""" <EOL> if self . stocks > <NUM_LIT:0> and self . money > <NUM_LIT:0> : <EOL> direction = random . choice ( ( BUY , SELL ) ) <EOL> elif self . stocks <= <NUM_LIT:0> : <EOL> direction = BUY <EOL> else : <EOL> direction = SELL <EOL> if direction : <EOL> price = self . sellprice <EOL> quantity = random . randint ( <NUM_LIT:1> , self . stocks ) <EOL> else : <EOL> price = self . buyprice <EOL> quantity = random . randint ( <NUM_LIT:1> , self . maxbuy ) <EOL> return { '<STR_LIT>' : direction , '<STR_LIT>' : price , '<STR_LIT>' : quantity } <EOL> def _test ( ) : <EOL> """<STR_LIT>""" <EOL> import doctest <EOL> doctest . testmod ( optionflags = + doctest . ELLIPSIS ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _test ( ) </s>
