from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'ComplementaryInvest' players_per_group = None num_rounds = 10 a = 0.4 endowment = c(100) multi = 3 r = 0.1 class Subsession(BaseSubsession): def interestrate(self): return 100*Constants.r class Group(BaseGroup): def treatment(self): for p in self.get_players(): if (p.participant.id_in_session % 2)==0: p.participant.vars['p1']=0.4 else: p.participant.vars['p1']=0.6 class Player(BasePlayer): initial = models.CurrencyField(initial=0, label='What is your investment?', min=0) complementary = models.CurrencyField(initial=0, label='How much do you want to add?', min=0) p2 = models.FloatField(initial=0) fail1 = models.BooleanField() fail2 = models.BooleanField() p1 = models.FloatField() gender = models.BooleanField(choices=[[True, 'Male'], [False, 'Female']], label='For research purpose, please tell us your gender in the following field.') email = models.StringField(blank=True, label='Please enter your email so you will be contacted and paid if you are the winner.') wealth = models.CurrencyField() def totalincome1(self): total_income1=self.initial*Constants.multi return total_income1 def netincome1(self): net_income1=self.initial*Constants.multi-self.initial return net_income1 def stage2(self): self.p2=0.4*self.complementary/self.initial return self.p2 def limitp2(self): return max(0,min(100*Constants.a*self.complementary/self.initial,100)) def initial_max(self): if self.round_number==1: return Constants.endowment else: return self.in_round(self.round_number - 1).wealth def complementary_max(self): compmax=self.wealth-self.initial return compmax def prob1(self): return 100*self.participant.vars['p1'] def getwealth(self): if self.round_number==1: return Constants.endowment else: return self.in_round(self.round_number - 1).wealth