Skip to content

Instantly share code, notes, and snippets.

@olafghanizadeh
Created December 4, 2019 19:56
Show Gist options
  • Save olafghanizadeh/a0d7bbfeefc206f5dd5ba0b0c515807e to your computer and use it in GitHub Desktop.
Save olafghanizadeh/a0d7bbfeefc206f5dd5ba0b0c515807e to your computer and use it in GitHub Desktop.
class Lottery:
"""Create a class to generate a lottery as in HOLT(2002). Has methods to set the number of choices,
if probabilities should be displayed as fractions, percentage or floats, set the payoff amounts."""
def __init__(self, name):
self.name = name
# Set the number of choices the user should get, and create an index of number of choices
def set_choices(self, choices):
index = [j for j in range(1, choices + 1)]
return index
# Set the base payoffs in a list
def set_payoffs(self, payoffs):
return payoffs
def define_probabilities(self, probs):
"""Let user chose how probabilities will be displayed. As stated in Holt(2002), different representations can change outcome"""
if probs == 'float':
probs = np.array([
k / choices
for k in index
])
elif probs == 'percent':
probs = np.array([
"{0:.2f}".format(k / n * 100) + "%"
for k in index
])
elif probs == 'fraction':
probs = np.array([
k / choices
for k in index
])
return probs
def draw(self, result):
self.result = result
result = 2
return result
lottery = Lottery("Risk Aversion and Incentive effects")
print(lottery.name)
choices = lottery.set_choices(10)
num_choices = str(len(choices))
print("The lottery has" + num_choices + "choices")
basePayoffs = [2, 1.6, 3.85, 0.1]
payoffs = lottery.set_payoffs(basePayoffs)
print("The base amounts are" + str(payoffs))
lotteryProbs = lottery.define_probabilities('percent')
print(lotteryProbs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment