Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Bertrand-Edgeworth competition in experimental markets.
Econometrica: Journal of the Econometric Society, 343-371."
"""
class Constants(BaseConstants):
players_per_group = 2
name_in_url = 'bertrand'
num_rounds = 1
instructions_template = 'bertrand/instructions.html'
maximum_price = c(100)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
winning_price = models.CurrencyField()
def set_payoffs(self):
import random
players = self.get_players()
self.winning_price = min([p.price for p in players])
winners = [p for p in players if p.price == self.winning_price]
winner = random.choice(winners)
for p in players:
if p == winner:
"""
class Constants(BaseConstants):
name_in_url = 'trust'
players_per_group = 2
num_rounds = 1
instructions_template = 'trust/instructions.html'
# Initial amount allocated to each player
endowment = c(100)
multiplier = 3
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
sent_amount = models.CurrencyField(
min=0, max=Constants.endowment, doc="""Amount sent by P1"""
)
sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", min=c(0))
def sent_back_amount_max(self):
return self.sent_amount * Constants.multiplier
def set_payoffs(self):
p1 = self.get_player_by_id(1)
p2 = self.get_player_by_id(2)
"""
class Constants(BaseConstants):
name_in_url = 'dictator'
players_per_group = 2
num_rounds = 1
instructions_template = 'dictator/instructions.html'
# Initial amount allocated to the dictator
endowment = c(100)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
kept = models.CurrencyField(
doc="""Amount dictator decided to keep for himself""",
min=0,
max=Constants.endowment,
)
def set_payoffs(self):
p1 = self.get_player_by_id(1)
p2 = self.get_player_by_id(2)
p1.payoff = self.kept
p2.payoff = Constants.endowment - self.kept
"""
class Constants(BaseConstants):
name_in_url = 'public_goods'
players_per_group = 3
num_rounds = 1
instructions_template = 'public_goods/instructions.html'
# """Amount allocated to each player"""
endowment = c(100)
multiplier = 2
class Subsession(BaseSubsession):
def vars_for_admin_report(self):
contributions = [
p.contribution for p in self.get_players() if p.contribution != None
]
if contributions:
return dict(
avg_contribution=sum(contributions) / len(contributions),
min_contribution=min(contributions),
max_contribution=max(contributions),
)
else:
return dict(
avg_contribution='(no data)',
min_contribution='(no data)',
max_contribution='(no data)',
)
BasePlayer,
Currency as c,
currency_range,
)
class Constants(BaseConstants):
name_in_url = 'public_goods_simple'
players_per_group = 3
num_rounds = 1
endowment = c(100)
multiplier = 1.8
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
total_contribution = models.CurrencyField()
individual_share = models.CurrencyField()
def set_payoffs(self):
players = self.get_players()
contributions = [p.contribution for p in players]
self.total_contribution = sum(contributions)
self.individual_share = (
self.total_contribution * Constants.multiplier / Constants.players_per_group
)
for p in players:
p.payoff = Constants.endowment - p.contribution + self.individual_share
instructions_template = 'traveler_dilemma/instructions.html'
# Player's reward for the lowest claim"""
adjustment_abs = c(2)
# Player's deduction for the higher claim
# The maximum claim to be requested
max_amount = c(100)
# The minimum claim to be requested
min_amount = c(2)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
lower_claim = models.CurrencyField()
def set_payoffs(self):
p1, p2 = self.get_players()
if p1.claim == p2.claim:
self.lower_claim = p1.claim
for p in [p1, p2]:
p.payoff = self.lower_claim
p.adjustment = c(0)
else:
if p1.claim < p2.claim:
author = 'Markus Konrad'
doc = """
Example 1 for usage of the otreeutils package.
"""
class Constants(BaseConstants):
name_in_url = 'otreeutils_example1'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
understanding_questions_wrong_attempts = models.PositiveIntegerField() # number of wrong attempts on understanding quesions page
def validate_model(model):
if isinstance(model, BasePlayer):
return 'player'
elif isinstance(model, BaseSubsession):
return 'subsession'
else:
raise ValueError('invalid model %s' % model.__class__.__name__)
model_type = validate_model(model)
from .cache import initialize_model_cache, set_market_id_table, get_market_id_table
from .exogenous_event import ExogenousEventModelFactory
from . import market_environments
from django.utils import timezone
from .dispatcher import DispatcherFactory
log = logging.getLogger(__name__)
class Constants(BaseConstants):
name_in_url = 'hft'
players_per_group = None
num_rounds = 3
class Subsession(BaseSubsession):
model_name = models.StringField(initial='subsession')
auction_format = models.StringField()
session_duration = models.IntegerField()
batch_length = models.IntegerField(initial=0)
code = models.CharField(default=random_chars_8)
def creating_session(self):
def create_trade_session(session_format):
trade_session_cls = TradeSessionFactory.get_session(session_format)
dispatcher = DispatcherFactory.get_dispatcher(session_format)
trade_session = trade_session_cls(self, session_format, dispatcher)
environment = market_environments.environments[session_format]
for event_type in environment.exogenous_events:
event_filename = self.session.config[event_type].pop(0)
trade_session.register_exogenous_event(
event_type, event_filename)
See https://en.wikipedia.org/wiki/Guess_2/3_of_the_average
"""
class Constants(BaseConstants):
players_per_group = 3
num_rounds = 3
name_in_url = 'guess_two_thirds'
jackpot = Currency(100)
guess_max = 100
instructions_template = 'guess_two_thirds/instructions.html'
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
two_thirds_avg = models.FloatField()
best_guess = models.IntegerField()
num_winners = models.IntegerField()
def set_payoffs(self):
players = self.get_players()
guesses = [p.guess for p in players]
two_thirds_avg = (2 / 3) * sum(guesses) / len(players)
self.two_thirds_avg = round(two_thirds_avg, 2)
self.best_guess = min(
guesses, key=lambda guess: abs(guess - self.two_thirds_avg)