from otree.api import * doc = """ This is a standard 2-player trust game where the amount sent by player 1 gets tripled. The trust game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'trust' players_per_group = 2 num_rounds = 1 instructions_template = 'trust/instructions.html' instructions_investment_template = 'trust/instructions_investment.html' # Initial amount allocated to each player endowment = cu(100) multiplier = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): sent_amount = models.CurrencyField( lable="Please enter an amount from 0 to 100:", min=0, max=Constants.endowment, doc="""Amount sent by P1 as a sender""", ) sent_return_10 = models.CurrencyField( label="If participant A sent 10 ECU, I would like to return:", min=0, max=10, doc="""Amount sent by P1 as a receiver if 10 returned""" ) sent_return_20 = models.CurrencyField( label="If participant A sent 20 ECU, I would like to return:", min=0, max=20, doc="""Amount sent by P1 as a receiver if 20 returned""" ) sent_return_30 = models.CurrencyField( label="If participant A sent 30 ECU, I would like to return:", min=0, max=30, doc="""Amount sent by P1 as a receiver if 30 returned""" ) sent_return_40 = models.CurrencyField( label="If participant A sent 40 ECU, I would like to return:", min=0, max=40, doc="""Amount sent by P1 as a receiver if 40 returned""" ) sent_return_50 = models.CurrencyField( label="If participant A sent 50 ECU, I would like to return:", min=0, max=50, doc="""Amount sent by P1 as a receiver if 50 returned""" ) sent_return_60 = models.CurrencyField( label="If participant A sent 60 ECU, I would like to return:", min=0, max=60, doc="""Amount sent by P1 as a receiver if 60 returned""" ) sent_return_70 = models.CurrencyField( label="If participant A sent 70 ECU, I would like to return:", min=0, max=70, doc="""Amount sent by P1 as a receiver if 70 returned""" ) sent_return_80 = models.CurrencyField( label="If participant A sent 80 ECU, I would like to return:", min=0, max=80, doc="""Amount sent by P1 as a receiver if 80 returned""" ) sent_return_90 = models.CurrencyField( label="If participant A sent 90 ECU, I would like to return:", min=0, max=90, doc="""Amount sent by P1 as a receiver if 90 returned""" ) sent_return_100 = models.CurrencyField( label="If participant A sent 100 ECU, I would like to return:", min=0, max=100, doc="""Amount sent by P1 as a receiver if 100 returned""" ) sent_invest_advisor_x = models.CurrencyField( label="Please indicate how much you would like to invest into the risky investment with advisor X:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with advisor X""" ) sent_invest_advisor_y = models.CurrencyField( label="Please indicate how much you would like to invest into the risky investment with advisor Y:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with advisor Y""" ) sent_invest_advisor_x_2 = models.CurrencyField( label="Please indicate how much you would like to invest into the risky investment with advisor X:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with advisor X""" ) sent_invest_advisor_y_2 = models.CurrencyField( label="Please indicate how much you would like to invest into the risky investment with advisor Y:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with advisor Y""" ) sent_invest_part2_1 = models.CurrencyField( label="Please indicate how much you want to invest into the risky investment with this investment advisor:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with this advisor""" ) sent_invest_part2_2 = models.CurrencyField( label="Now suppose you had to invest with the other investment advisor, who returned 0 ECU to you. Please indicate at which costs (in %) you would be willing to make the same investment allocation as with the other investment", min=0, max=100, doc="""Amount sent by P1 as a receiver if 100 returned""" ) sent_invest_part2_1_1 = models.CurrencyField( label="Please indicate how much you want to invest into the risky investment with this investment advisor:", min=0, max=100, doc="""Amount sent by a participant to invest into the risky investment with this advisor""" ) sent_invest_part2_2_2 = models.CurrencyField( label="Now suppose you had to invest with the other investment advisor, who returned 0 ECU to you. Please indicate at which costs (in %) you would be willing to make the same investment allocation as with the other investment", min=0, max=100, doc="""Amount sent by P1 as a receiver if 100 returned""" ) feedback1 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you perceive advisors who returned more to you in the trust game (Experimental Task 1? as more trustworthy?', widget=widgets.RadioSelect, ) feedback2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you expect investment decisions with advisors who returned more in the trust game (Experimental Task 1) to give you higher returns than investment decisions with advisors who returned less in the trust game?', widget=widgets.RadioSelect, ) feedback3 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you invest more risky with the advisor who returned more in the trust game (Experimental Task 1) because you wanted to reward him?', widget=widgets.RadioSelect, ) sociodemo1 = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female']], label='Please indicate your gender:', widget=widgets.RadioSelect, ) sociodemo2 = models.IntegerField( label='Please enter your age in years:', min=13, max=100, ) sociodemo3 = models.StringField( choices=[['Primary School', 'Primary School'], ['High School', 'High School'], ['College degree (e.g., Bachelor, Master)', 'College degree (e.g., Bachelor, Master)'], ['Ph.D.', 'Ph.D.']], label='Please indicate your educational background (select highest):', widget=widgets.RadioSelect, ) sociodemo4 = models.StringField( choices=[['Student', 'Student'], ['Employment', 'Employment'], ['Self-Employed', 'Self-Employed'], ['Unemployed', 'Unemployed'], ['Retired', 'Retired'], ['I do not want to answer', 'I do not want to answer']], label='Please indicate your current profession:', widget=widgets.RadioSelect, ) sociodemo5 = models.StringField( choices=[['Business', 'Business'], ['Economics', 'Economics'], ['Mathematics, Physics, Engineering', 'Mathematics, Physics, Engineering'], ['Other', 'Other'], ['Not applicable', 'Not applicable']], label='If applicable, please indicate in which field of study you have studied or studying:', widget=widgets.RadioSelect, ) sociodemo6 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Have you ever invested into active funds:', widget=widgets.RadioSelect, ) sociodemo7 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Have you ever invested into passive funds:', widget=widgets.RadioSelect, ) sociodemo8 = models.StringField( choices=[['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='In general, I am willing to take financial risks (1=Not at all willing, 5=Very willing):', widget=widgets.RadioSelect, ) sociodemo9 = models.StringField( choices=[['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='In general, I trust others (1=Not at all, 5=Very much):', widget=widgets.RadioSelect, ) quiz1 = models.IntegerField( label='A bat and a ball costs $1.10 in total. The bat costs a dollar more than the ball. How much does the ball cost?', ) quiz2 = models.IntegerField( label='If it takes 5 machines 5 minutes to make 5 widgets, how long would it take 100 machines to make 100 widgets?', ) quiz3 = models.IntegerField( label='In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how long would it take for the patch to cover half of the lake?', ) quiz4 = models.IntegerField( label='If John can drink one barrel of water in 6 days, and Mary can drink one barrel of water in 12 days, how long would it take them to drink one barrel of water together?', ) quiz5 = models.IntegerField( label='Jerry received both the 15th highest and the 15th lowest mark in the class. How many students are in the class?', ) quiz6 = models.IntegerField( label='A man buys a pig for $60, sells it for $70, buys it back for $80, and sells it finally for $90. How much has he made?', ) quiz7 = models.StringField( choices=[['broken even in the investment market', 'broken even in the investment market'], ['is ahead of where he began', 'is ahead of where he began'], ['has lost money', 'has lost money']], label='Simon decided to invest $8,000 in the investment market one day early in 2008. Six months after he invested, on July 17, the investments he had purchased were down 50%. Fortunately for Simon, from July 17 to Octomer 17, the investments he had purchased went up 75%.', widget=widgets.RadioSelect, ) feedback1_2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you perceive advisors who returned more to you in the trust game (Experimental Task 1? as more trustworthy?', widget=widgets.RadioSelect, ) feedback2_2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you expect investment decisions with advisors who returned more in the trust game (Experimental Task 1) to give you higher returns than investment decisions with advisors who returned less in the trust game?', widget=widgets.RadioSelect, ) feedback3_2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Did you invest more risky with the advisor who returned more in the trust game (Experimental Task 1) because you wanted to reward him?', widget=widgets.RadioSelect, ) sociodemo1_2 = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female']], label='Please indicate your gender:', widget=widgets.RadioSelect, ) sociodemo2_2 = models.IntegerField( label='Please enter your age in years:', min=13, max=100, ) sociodemo3_2 = models.StringField( choices=[['Primary School', 'Primary School'], ['High School', 'High School'], ['College degree (e.g., Bachelor, Master)', 'College degree (e.g., Bachelor, Master)'], ['Ph.D.', 'Ph.D.']], label='Please indicate your educational background (select highest):', widget=widgets.RadioSelect, ) sociodemo4_2 = models.StringField( choices=[['Student', 'Student'], ['Employment', 'Employment'], ['Self-Employed', 'Self-Employed'], ['Unemployed', 'Unemployed'], ['Retired', 'Retired'], ['I do not want to answer', 'I do not want to answer']], label='Please indicate your current profession:', widget=widgets.RadioSelect, ) sociodemo5_2 = models.StringField( choices=[['Business', 'Business'], ['Economics', 'Economics'], ['Mathematics, Physics, Engineering', 'Mathematics, Physics, Engineering'], ['Other', 'Other'], ['Not applicable', 'Not applicable']], label='If applicable, please indicate in which field of study you have studied or studying:', widget=widgets.RadioSelect, ) sociodemo6_2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Have you ever invested into active funds:', widget=widgets.RadioSelect, ) sociodemo7_2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No'], ['I do not know', 'I do not know']], label='Have you ever invested into passive funds:', widget=widgets.RadioSelect, ) sociodemo8_2 = models.StringField( choices=[['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='In general, I am willing to take financial risks (1=Not at all willing, 5=Very willing):', widget=widgets.RadioSelect, ) sociodemo9_2 = models.StringField( choices=[['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='In general, I trust others (1=Not at all, 5=Very much):', widget=widgets.RadioSelect, ) quiz1_2 = models.IntegerField( label='A bat and a ball costs $1.10 in total. The bat costs a dollar more than the ball. How much does the ball cost?', ) quiz2_2 = models.IntegerField( label='If it takes 5 machines 5 minutes to make 5 widgets, how long would it take 100 machines to make 100 widgets?', ) quiz3_2 = models.IntegerField( label='In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how long would it take for the patch to cover half of the lake?', ) quiz4_2 = models.IntegerField( label='If John can drink one barrel of water in 6 days, and Mary can drink one barrel of water in 12 days, how long would it take them to drink one barrel of water together?', ) quiz5_2 = models.IntegerField( label='Jerry received both the 15th highest and the 15th lowest mark in the class. How many students are in the class?', ) quiz6_2 = models.IntegerField( label='A man buys a pig for $60, sells it for $70, buys it back for $80, and sells it finally for $90. How much has he made?', ) quiz7_2 = models.StringField( choices=[['broken even in the investment market', 'broken even in the investment market'], ['is ahead of where he began', 'is ahead of where he began'], ['has lost money', 'has lost money']], label='Simon decided to invest $8,000 in the investment market one day early in 2008. Six months after he invested, on July 17, the investments he had purchased were down 50%. Fortunately for Simon, from July 17 to Octomer 17, the investments he had purchased went up 75%.', widget=widgets.RadioSelect, ) sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", min=cu(0)) class Player(BasePlayer): pass # FUNCTIONS def sent_back_amount_max(group: Group): return group.sent_amount * Constants.multiplier def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = Constants.endowment - group.sent_amount + group.sent_back_amount p2.payoff = group.sent_amount * Constants.multiplier - group.sent_back_amount # PAGES class Page1(Page): pass class Introduction(Page): pass class Send(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class SendBackWaitPage(WaitPage): pass class SendBack(Page): """This page is only for P2 P2 sends back some amount (of the tripled amount received) to P1""" form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): group = player.group tripled_amount = group.sent_amount * Constants.multiplier return dict(tripled_amount=tripled_amount) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): """This page displays the earnings of each player""" @staticmethod def vars_for_template(player: Player): group = player.group return dict(tripled_amount=group.sent_amount * Constants.multiplier) class Send1(Page): form_model = 'group' form_fields = ['sent_return_10', 'sent_return_20', 'sent_return_30', 'sent_return_40', 'sent_return_50', 'sent_return_60', 'sent_return_70', 'sent_return_80', 'sent_return_90', 'sent_return_100'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class Page5(Page): pass class Introduction_investment(Page): pass class Choose_investment(Page): form_model = 'group' form_fields = ['sent_invest_advisor_x', 'sent_invest_advisor_y'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class Investment1WaitPage(WaitPage): pass class Choose_investment1(Page): form_model = 'group' form_fields = ['sent_invest_advisor_x_2', 'sent_invest_advisor_y_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class Result_investment(Page): @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class Result_investment1(Page): @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class Choose_investment_2(Page): form_model = 'group' form_fields = ['sent_invest_part2_1', 'sent_invest_part2_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class Investment2WaitPage(WaitPage): pass class Choose_investment_2_1(Page): form_model = 'group' form_fields = ['sent_invest_part2_1_1', 'sent_invest_part2_2_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class feedback(Page): form_model = 'group' form_fields = ['feedback1', 'feedback2', 'feedback3'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class sociodemo(Page): form_model = 'group' form_fields = ['sociodemo1', 'sociodemo2', 'sociodemo3', 'sociodemo4', 'sociodemo5', 'sociodemo6', 'sociodemo7', 'sociodemo8', 'sociodemo9'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class quiz(Page): form_model = 'group' form_fields = ['quiz1', 'quiz2', 'quiz3', 'quiz4', 'quiz5', 'quiz6', 'quiz7'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 class feedback_2(Page): form_model = 'group' form_fields = ['feedback1_2', 'feedback2_2', 'feedback3_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class sociodemo_2(Page): form_model = 'group' form_fields = ['sociodemo1_2', 'sociodemo2_2', 'sociodemo3_2', 'sociodemo4_2', 'sociodemo5_2', 'sociodemo6_2', 'sociodemo7_2', 'sociodemo8_2', 'sociodemo9_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class quiz_2(Page): form_model = 'group' form_fields = ['quiz1_2', 'quiz2_2', 'quiz3_2', 'quiz4_2', 'quiz5_2', 'quiz6_2', 'quiz7_2'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 class Finale(Page): pass page_sequence = [ Page1, Introduction, Send, SendBackWaitPage, SendBack, Send1, ResultsWaitPage, Results, Page5, Introduction_investment, Choose_investment, Investment1WaitPage, Choose_investment1, Result_investment, Choose_investment_2, Investment2WaitPage, Choose_investment_2_1, feedback, sociodemo, quiz, feedback_2, sociodemo_2, quiz_2, Finale, ]