from __future__ import division
import random
# This model attempts to explore the generation of a price, and seeing how such prices are generated.
def make_consumer(demand, personal_supply):
return (demand, personal_supply)
def make_consumers(max_demand, max_supply, amnt):
return [make_consumer(random.randint(1, max_demand), random.randint(1, max_supply)) for i in range(amnt)]
def consumer_preferred_price(con):
return con[0] / con[1]
def avg_pref_price(consumers):
return sum([consumer_preferred_price(c) for c in consumers]) / len(consumers)
def avg_demand(consumers):
return sum([c[0] for c in consumers]) / len(consumers)
def avg_supply(consumers):
return sum([c[1] for c in consumers]) / len(consumers)
"""
Here, the supplys and demands of consumers are randomly generated,
and the fluctuation of their average preferred price is observed
"""
if __name__ == '__main__':
conbin = make_consumers(30, 20, 10)
print conbin
print "avg pref price = " + str(avg_pref_price(conbin))
print "avg demand = " + str(avg_demand(conbin))
print "avg supply = " + str(avg_supply(conbin))