from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'zyoteii' doc = """ This is the draft of multiperiods portfolio game """ class Constants(BaseConstants): name_in_url = 'game_test' players_per_group = None max_num_rounds = 11 min_num_rounds = 4 num_rounds = 1 endowment = 1000 return_A = [-0.05, 0.1] return_B = 0.02 tax_A = 0.35 tax_B = 0.35 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.round_number == 1: p.random_max_round = random.randint(Constants.min_num_rounds,Constants.max_num_rounds) p.endowment = Constants.endowment p.participant.vars['max_round'] = p.random_max_round p.participant.vars['my_round'] = 1 class Group(BaseGroup): pass class Player(BasePlayer): p1 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p2 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p3 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p4 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p5 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p6 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p7 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p8 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p9 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) p10 = models.FloatField(label='Percentage of points investing in Asset A',min=0, max=100) random_max_round = models.IntegerField() endowment = models.FloatField() payoff_a = models.FloatField() payoff_b = models.FloatField() a_aftertax = models.FloatField() b_aftertax = models.FloatField() all_aftertax = models.FloatField() bonus = models.FloatField() participant_vars_dumps = models.LongStringField() # records of asset value of every period in part 2 a1 = models.FloatField() b1 = models.FloatField() endowment1 = models.FloatField() a2 = models.FloatField() b2 = models.FloatField() endowment2 = models.FloatField() a3 = models.FloatField() b3 = models.FloatField() endowment3 = models.FloatField() a4 = models.FloatField() b4 = models.FloatField() endowment4 = models.FloatField() a5 = models.FloatField() b5 = models.FloatField() endowment5 = models.FloatField() a6 = models.FloatField() b6 = models.FloatField() endowment6 = models.FloatField() a7 = models.FloatField() b7 = models.FloatField() endowment7 = models.FloatField() a8 = models.FloatField() b8 = models.FloatField() endowment8 = models.FloatField() a9 = models.FloatField() b9 = models.FloatField() endowment9 = models.FloatField() a10 = models.FloatField() b10 = models.FloatField() endowment10 = models.FloatField()