Module: playerB/market_estimate.py

# Market Estimate

rawtrends = [ 
 ["AA", -0.4543],
 ["AIG", 0.2927],
 ["AXP", 0.1816],
 ["BA", 0.0337],
 ["BAC", 0.3662],
 ["C", 0.1642],
 ["CAT", 0.1235],
 ["CVX", 0.2505],
 ["DD", 0.4274],
 ["DIS", 0.4725],
 ["GE", 0.0915],
 ["GM", -0.3854],
 ["HD", -0.0286],
 ["HPQ", -0.0777],
 ["IBM", -0.1041],
 ["INTC", -0.2254],
 ["JNJ", 0.2191],
 ["JPM", 0.1622],
 ["KO", -0.1285],
 ["MCD", 0.0152],
 ["MMM", 0.1575],
 ["MRK", -0.4224],
 ["MSFT", 0.2043],
 ["PFE", 0.3470],
 ["PG", 0.3944],
 ["T", 0.3049],
 ["UTX", -0.3165],
 ["VZ", 0.0659],
 ["WMT", 0.4142],
 ["XOM", -0.4298] ]


class MarketEstimate:
    def __init__(self, f):
        # recommended adjustable multiplicative factor
        # n.b. !! There are two points in the demo where we rig the numbers so that we get agreement between
        # players A and B very easily. Earlier in the process, A and B received the same set of trends shown above.
        # Here, in the module for Player B, we introduce a negative multiplier for the trend numbers. Thus, B will use
        # trends that are exactly the opposite of those used by A. Each will easily come to agreement with the other and
        # think that it will win big on the transaction.
        self.factor = -1.0 * f
        self.trends = {}
        for p in rawtrends:
            self.trends[ p[0] ] = self.factor * p[1]

    def show_market(self, f):
        f.write( "Market Estimate\n------------------\n")
        symb = self.trends.keys()
        symb.sort()
        for c in symb:
            f.write( "%5s = %f6.4\n" % ( c, self.trends[c]) )
        f.write( "\nEstimate is percent change per month for each stock\n\n")


if __name__ == '__main__':
    o = MarketEstimate(1.0)
    f = open("market_estimate.txt", "w")
    o.show_market(f)
    f.close()
    print "wrote market_estimate.txt"