from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage import pandas as pd from .models import Constants import locale from django import forms import django from django.conf import settings settings.configure() # You can pass default settings here if needed django.setup() class TradeForm(forms.Form): asset_name = forms.CharField(widget=forms.HiddenInput()) action = forms.ChoiceField(choices=[('buy', 'Buy'), ('sell', 'Sell')]) amount = forms.FloatField() round_number = forms.IntegerField(widget=forms.HiddenInput()) def __init__(self, *args, **kwargs): super(TradeForm, self).__init__(*args, **kwargs) # your custom initialization code here class InstructionPage(Page): form_model = 'player' form_fields = ['treatment_group'] def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( treatment_group=getattr(self.player, 'treatment_group') ) class TwitterPage(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "control" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPageStimuli(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "treatment_1" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPageDisclosure(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "treatment_2" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPagePrebunk(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "treatment_3" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPageInoculation(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "treatment_4" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPageAll(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 2 and self.player.treatment_group == "treatment_5" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "control" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2Stimuli(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "treatment_1" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2Disclosure(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "treatment_2" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2Prebunk(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "treatment_3" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2Inoculation(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "treatment_4" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class TwitterPage2All(Page): form_model = 'player' form_fields = ['attention_check1'] def is_displayed(self): return self.round_number == 6 and self.player.treatment_group == "treatment_5" def vars_for_template(self): return dict( attention_check1=getattr(self.player, 'attention_check1') ) class RedditPage(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "control" class RedditPageStimuli(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "treatment_1" class RedditPageDisclosure(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "treatment_2" class RedditPagePrebunk(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "treatment_3" class RedditPageInoculation(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "treatment_4" class RedditPageAll(Page): def is_displayed(self): return self.round_number == 3 and self.player.treatment_group == "treatment_5" class RedditPage2(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "control" class RedditPage2Stimuli(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "treatment_1" class RedditPage2Disclosure(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "treatment_2" class RedditPage2Prebunk(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "treatment_3" class RedditPage2Inoculation(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "treatment_4" class RedditPage2All(Page): def is_displayed(self): return self.round_number == 7 and self.player.treatment_group == "treatment_5" class TikTokPage(Page): def is_displayed(self): return self.round_number == 4 and self.player.treatment_group == "control" class TikTokPageStimuli(Page): def is_displayed(self): return (self.round_number == 4 and (self.player.treatment_group in ["treatment_1", "treatment_3", "treatment_4", "treatment_5"])) class TikTokPageDisclosure(Page): def is_displayed(self): return self.round_number == 4 and self.player.treatment_group == "treatment_2" class TikTokPagePrebunk(Page): def is_displayed(self): return self.round_number == 4 and self.player.treatment_group == "treatment_3" class TikTokPageInoculation(Page): def is_displayed(self): return (self.round_number == 4 and (self.player.treatment_group in ["treatment_4", "treatment_5"])) class TikTokPage2(Page): def is_displayed(self): return self.round_number == 9 and self.player.treatment_group == "control" class TikTokPage2Stimuli(Page): def is_displayed(self): return (self.round_number == 9 and (self.player.treatment_group in ["treatment_1", "treatment_3", "treatment_4", "treatment_5"])) class TikTokPage2Disclosure(Page): def is_displayed(self): return self.round_number == 9 and self.player.treatment_group == "treatment_2" class TikTokPage2Prebunk(Page): def is_displayed(self): return self.round_number == 9 and self.player.treatment_group == "treatment_3" class TikTokPage2Inoculation(Page): def is_displayed(self): return (self.round_number == 9 and (self.player.treatment_group in ["treatment_4", "treatment_5"])) class StartPage(Page): def is_displayed(self): return self.round_number <= self.session.num_rounds def vars_for_template(self): is_training_round = self.session.config['training_round'] and self.round_number == 1 return dict( is_training_round=is_training_round, ) class TradingPage(Page): live_method = 'live_trading_report' form_model = 'player' form_fields = [ 'buy_count_VOO', 'buy_count_VTI', 'buy_count_ZZW', 'buy_count_MDKS', 'buy_count_UDX', 'buy_count_DSLO', 'buy_count_NOQ', 'buy_count_XPOW', 'buy_count_MWQ', 'buy_count_STCK', 'buy_count_IUM', 'buy_count_JUNW', 'buy_count_ETQ', 'buy_count_BTC', 'cash', ] def get_form_fields(self): form_fields = [ 'buy_count_VOO', 'buy_count_VTI', 'buy_count_ZZW', 'buy_count_MDKS', 'buy_count_UDX', 'buy_count_DSLO', 'buy_count_NOQ', 'buy_count_XPOW', 'buy_count_MWQ', 'buy_count_STCK', 'buy_count_IUM', 'buy_count_JUNW', 'buy_count_ETQ', 'buy_count_BTC', 'cash', ] return form_fields # and so on for all fields def is_displayed(self): return self.round_number <= self.session.num_rounds def vars_for_template(self): # Define the data for the dataframe with changes again data = { 'Type': ['ETF', 'ETF', 'ETF', 'ETF', 'Stock', 'Stock', 'Stock', 'Stock', 'Stock', 'Stock', 'Crypto', 'Crypto', 'Crypto', 'Crypto'], 'Base_Ticker': ['VOO', 'VTI', 'ZWC', 'PSA.TO', 'SU', 'WEED', 'MFC', 'ENB', 'BTE', 'STCK', 'DELX', 'BITK', 'ETHQ', 'BTC'], 'Modified_Ticker': ['VOO', 'VTI', 'ZZW', 'MDKS', 'UDX', 'DSLO', 'NOQ', 'XPOW', 'MWQ', 'STCK', 'IUM', 'JUNW', 'ETQ', 'BTC'], 'Round_1': ['$364.30', '$206.69', '$17.34', '$50.01', '$26.27', '$40.36', '$27.03', '$45.78', '$1.31', '$12.08', '$0.09', '$1.17', '$9.36', '$58,918.83'], 'Round_1_Change': ['6.00%', '6.19%', '7.04%', '0.02%', '23.04%', '28.86%', '19.34%', '12.45%', '89.86%', '0.67%', '0.00%', '0.00%', '4.00%', '103.16%'], 'Round_2': ['$393.52', '$222.82', '$18.19', '$50.01', '$29.69', '$29.98', '$24.40', '$49.63', '$2.39', '$11.20', '$0.50', '$0.66', '$11.11', '$35,040.84'], 'Round_2_Change': ['8.02%', '7.80%', '4.90%', '0.00%', '13.02%', '-25.72%', '-9.73%', '8.41%', '82.44%', '-7.28%', '455.56%', '-43.59%', '18.70%', '-40.53%'], 'Round_3': ['$394.40', '$222.06', '$18.15', '$50.00', '$26.26', '$17.55', '$24.38', '$50.46', '$3.45', '$9.92', '$0.52', '$0.37', '$15.59', '$43,790.89'], 'Round_3_Change': ['0.22%', '-0.34%', '-0.22%', '-0.02%', '-11.55%', '-41.46%', '-0.08%', '1.67%', '44.35%', '-11.43%', '4.00%', '-43.94%', '40.32%', '24.97%'], 'Round_4': ['$436.57', '$241.44', '$18.95', '$50.01', '$31.65', '$11.04', '$24.11', '$49.41', '$3.91', '$9.09', '$0.46', '$0.27', '$20.05', '$46,306.45'], 'Round_4_Change': ['10.69%', '8.73%', '4.41%', '0.02%', '20.53%', '-37.09%', '-1.11%', '-2.08%', '13.33%', '-8.37%', '-11.54%', '-27.03%', '28.61%', '5.74%'], 'Round_5': ['$415.17', '$227.67', '$20.00', '$50.04', '$40.70', '$9.48', '$26.66', '$57.55', '$5.45', '$9.00', '$0.39', '$0.21', '$16.68', '$45,538.68'], 'Round_5_Change': ['-4.90%', '-5.70%', '5.54%', '0.06%', '28.59%', '-14.13%', '10.58%', '16.47%', '39.39%', '-0.99%', '-15.22%', '-22.22%', '-16.81%', '-1.66%'], 'Round_6': ['$346.88', '$188.62', '$17.65', '$50.00', '$45.16', '$3.66', '$22.32', '$54.36', '$6.25', '$7.00', '$0.20', '$0.07', '$5.30', '$19,784.73'], 'Round_6_Change': ['-16.45%', '-17.15%', '-11.75%', '-0.08%', '10.96%', '-61.39%', '-16.28%', '-5.54%', '14.68%', '-22.22%', '-48.72%', '-66.67%', '-68.23%', '-56.55%'], 'Round_7': ['$328.30', '$179.47', '$16.78', '$50.02', '$38.90', '$3.75', '$21.68', '$51.22', '$5.85', '$6.70', '$0.16', '$0.16', '$7.50', '$19,431.79'], 'Round_7_Change': ['-5.36%', '-4.85%', '-4.93%', '0.04%', '-13.86%', '2.46%', '-2.87%', '-5.78%', '-6.40%', '-4.29%', '-20.00%', '128.57%', '41.51%', '-1.78%'], 'Round_8': ['$351.34', '$191.19', '$17.12', '$50.03', '$42.95', '$3.14', '$24.15', '$52.92', '$6.08', '$5.85', '$0.08', '$0.11', '$6.48', '$16,547.50'], 'Round_8_Change': ['7.02%', '6.53%', '2.03%', '0.02%', '10.41%', '-16.27%', '11.39%', '3.32%', '3.93%', '-12.69%', '-50.00%', '-31.25%', '-13.60%', '-14.84%'], 'Round_9': ['$376.07', '$204.10', '$17.35', '$50.02', '$41.96', '$2.37', '$24.80', '$51.53', '$5.07', '$6.50', '$0.13', '$0.10', '$9.89', '$28,478.48'], 'Round_9_Change': ['7.04%', '6.75%', '1.34%', '-0.02%', '2.69%', '-24.52%', '0.97%', '-2.63%', '-16.61%', '11.11%', '62.50%', '-9.09%', '52.62%', '72.10%'], 'Round_10': ['$407.28', '$220.28', '$17.00', '$50.04', '$38.86', '$0.51', '$25.04', '$49.24', '$4.32', '$6.80', '$0.10', '$0.10', '$10.13', '$30,477.25'], 'Round 10_Change': ['8.30%', '7.93%', '-2.02%', '0.04%', '-7.39%', '-78.48%', '0.97%', '-4.44%', '-14.79%', '4.62%', '-23.08%', '0.00%', '2.43%', '7.02%'] } data_cap = { "Modified_Ticker": ["VOO", "VTI", "ZZW", "MDKS", "UDX", "DSLO", "NOQ", "XPOW", "MWQ", "STCK", "IUM", "JUNW", "ETQ", "BTC"], "Round_1_Market_Cap/AUM": ["691.0B", "1.2T", "908.0M", "2.0B", "31.8B", "15.4B", "52.5B", "92.8B", "739.0M", "99.9M", "8.7M", "19.0M", "22.3M", "1.1T"], "Round_2_Market_Cap/AUM": ["753.4B", "1.3T", "1.1B", "1.7B", "36.1B", "11.8B", "47.4B", "100.5B", "1.3B", "99.9M", "48.2M", "11.1M", "22.3M", "673.1B"], "Round_3_Market_Cap/AUM": ["770.0B", "1.3T", "1.2B", "1.8B", "30.8B", "6.9B", "47.4B", "102.2B", "1.9B", "90.2M", "60.4M", "6.2M", "258.3M", "794.6B"], "Round_4_Market_Cap/AUM": ["856.1B", "1.4T", "1.3B", "1.8B", "36.1B", "4.4B", "46.8B", "100.1B", "2.2B", "82.7M", "54.3M", "4.5M", "316.1M", "892.3B"], "Round_5_Market_Cap/AUM": ["841.7B", "1.3T", "1.5B", "1.8B", "46.6B", "3.7B", "51.4B", "116.6B", "3.1B", "81.8M", "46.0M", "3.5M", "281.8M", "894.1B"], "Round_6_Market_Cap/AUM": ["709.8B", "1.1T", "1.5B", "2.0B", "49.6B", "1.5B", "42.6B", "110.1B", "3.5B", "63.6M", "23.6M", "1.2M", "63.3M", "383.7B"], "Round_7_Market_Cap/AUM": ["686.5B", "1.1T", "1.5B", "2.7B", "38.4B", "1.8B", "41.2B", "103.7B", "3.2B", "61.9M", "20.5M", "2.6M", "15.1M", "375.1B"], "Round_8_Market_Cap/AUM": ["744.8B", "1.2T", "1.5B", "3.8B", "42.8B", "1.5B", "45.3B", "107.2B", "3.3B", "54.0M", "10.7M", "1.8M", "12.3M", "319.6B"], "Round_9_Market_Cap/AUM": ["803.5B", "1.2T", "1.6B", "4.3B", "41.0B", "1.2B", "45.9B", "104.3B", "2.8B", "58.9M", "17.4M", "1.7M", "20.4M", "548.1B"], "Round_10_Market_Cap/AUM": ["887.0B", "1.4T", "1.6B", "5.0B", "38.2B", "311.6M", "45.9B", "99.7B", "3.7B", "61.5M", "13.2M", "1.7M", "22.3M", "591.1B"] } # Create the dataframe df = pd.read_csv('ZTS/Ticker_Values_Stand.csv') skip = 1 + 2 * (self.round_number) cols = df.iloc[:, skip:skip + 2].copy() df = df.iloc[:, 0:3] df = pd.concat([df, cols], axis=1) # Convert to DataFrame df_cap = pd.DataFrame(data_cap) skip = (self.round_number) cols_cap = df_cap.iloc[:, skip:skip + 1].copy() df = pd.concat([df, cols_cap], axis=1) current_columns = df.columns.tolist() current_columns[3] = 'Round_1' current_columns[4] = 'Round_1_Change' current_columns[-1] = 'Market_Cap' # Assign the modified column labels back to the DataFrame df.columns = current_columns df['change_type'] = df['Type'] != df['Type'].shift() df_to_list_of_dicts = df.to_dict(orient='records') data_modified = [] for row in df_to_list_of_dicts: modified_row = row.copy() buy_fieldname = 'buy_count_' + row['Modified_Ticker'] sell_fieldname = 'sell_count_' + row['Modified_Ticker'] modified_row['buy_fieldname'] = buy_fieldname modified_row['sell_fieldname'] = sell_fieldname data_modified.append(modified_row) previous_round_number = self.subsession.round_number - 1 tickers = [ 'VOO', 'VTI', 'ZZW', 'MDKS', 'UDX', 'DSLO', 'NOQ', 'XPOW', 'MWQ', 'STCK', 'IUM', 'JUNW', 'ETQ', 'BTC' ] initial_values = {} if previous_round_number == 0: for ticker in tickers: initial_values[f'buy_count_{ticker}_initial'] = 0 else: # Otherwise, retrieve the previous round's player and get the value for each ticker previous_player = self.player.in_round(previous_round_number) for ticker in tickers: initial_values[f'buy_count_{ticker}_initial'] = getattr(previous_player, f'buy_count_{ticker}') self.player.update_portfolio_value(pd.DataFrame(data_modified)) initial_values['cash'] = getattr(self.player, 'cash') data = { "Modified_Ticker": ["VOO", "VTI", "ZZW", "MDKS", "UDX", "DSLO", "NOQ", "XPOW", "MWQ", "STCK", "IUM", "JUNW", "ETQ", "BTC"], "Round_1_Market_Cap/AUM": ["691.0B", "1.2T", "908.0M", "2.0B", "31.8B", "15.4B", "52.5B", "92.8B", "739.0M", "99.9M", "8.7M", "19.0M", "22.3M", "1.1T"], "Round_2_Market_Cap/AUM": ["753.4B", "1.3T", "1.1B", "1.7B", "36.1B", "11.8B", "47.4B", "100.5B", "1.3B", "99.9M", "48.2M", "11.1M", "22.3M", "673.1B"], "Round_3_Market_Cap/AUM": ["770.0B", "1.3T", "1.2B", "1.8B", "30.8B", "6.9B", "47.4B", "102.2B", "1.9B", "90.2M", "60.4M", "6.2M", "258.3M", "794.6B"], "Round_4_Market_Cap/AUM": ["856.1B", "1.4T", "1.3B", "1.8B", "36.1B", "4.4B", "46.8B", "100.1B", "2.2B", "82.7M", "54.3M", "4.5M", "316.1M", "892.3B"], "Round_5_Market_Cap/AUM": ["841.7B", "1.3T", "1.5B", "1.8B", "46.6B", "3.7B", "51.4B", "116.6B", "3.1B", "81.8M", "46.0M", "3.5M", "281.8M", "894.1B"], "Round_6_Market_Cap/AUM": ["709.8B", "1.1T", "1.5B", "2.0B", "49.6B", "1.5B", "42.6B", "110.1B", "3.5B", "63.6M", "23.6M", "1.2M", "63.3M", "383.7B"], "Round_7_Market_Cap/AUM": ["686.5B", "1.1T", "1.5B", "2.7B", "38.4B", "1.8B", "41.2B", "103.7B", "3.2B", "61.9M", "20.5M", "2.6M", "15.1M", "375.1B"], "Round_8_Market_Cap/AUM": ["744.8B", "1.2T", "1.5B", "3.8B", "42.8B", "1.5B", "45.3B", "107.2B", "3.3B", "54.0M", "10.7M", "1.8M", "12.3M", "319.6B"], "Round_9_Market_Cap/AUM": ["803.5B", "1.2T", "1.6B", "4.3B", "41.0B", "1.2B", "45.9B", "104.3B", "2.8B", "58.9M", "17.4M", "1.7M", "20.4M", "548.1B"], "Round_10_Market_Cap/AUM": ["887.0B", "1.4T", "1.6B", "5.0B", "38.2B", "311.6M", "45.9B", "99.7B", "3.7B", "61.5M", "13.2M", "1.7M", "22.3M", "591.1B"] } # Convert to DataFrame df_cap = pd.DataFrame(data) return { 'data': data_modified, **initial_values } #def before_next_page(self): # This method is called before moving to the next page #buy_count_VOO_value = self.player.buy_count_VOO # ... handle other fields similarly ... class ProlificIDPage(Page): form_model = 'player' form_fields = ['prolificid'] def is_displayed(self): return self.round_number == 10 class ThankYouPage(Page): def is_displayed(self): return self.round_number == 10 class ResultsPage(Page): def is_displayed(self): return self.round_number <= self.session.num_rounds def to_human_readable(self, x): return '{:,}'.format(int(x)) def vars_for_template(self): data = { 'Type': ['ETF', 'ETF', 'ETF', 'ETF', 'Stock', 'Stock', 'Stock', 'Stock', 'Stock', 'Stock', 'Crypto', 'Crypto', 'Crypto', 'Crypto'], 'Base_Ticker': ['VOO', 'VTI', 'ZWC', 'PSA.TO', 'SU', 'WEED', 'MFC', 'ENB', 'BTE', 'STCK', 'DELX', 'BITK', 'ETHQ', 'BTC'], 'Modified_Ticker': ['VOO', 'VTI', 'ZZW', 'MDKS', 'UDX', 'DSLO', 'NOQ', 'XPOW', 'MWQ', 'STCK', 'IUM', 'JUNW', 'ETQ', 'BTC'], 'Round_1': ['$364.30', '$206.69', '$17.34', '$50.01', '$26.27', '$40.36', '$27.03', '$45.78', '$1.31', '$12.08', '$0.09', '$1.17', '$9.36', '$58,918.83'], 'Round_1_Change': ['6.00%', '6.19%', '7.04%', '0.02%', '23.04%', '28.86%', '19.34%', '12.45%', '89.86%', '0.67%', '0.00%', '0.00%', '4.00%', '103.16%'], 'Round_2': ['$393.52', '$222.82', '$18.19', '$50.01', '$29.69', '$29.98', '$24.40', '$49.63', '$2.39', '$11.20', '$0.50', '$0.66', '$11.11', '$35,040.84'], 'Round_2_Change': ['8.02%', '7.80%', '4.90%', '0.00%', '13.02%', '-25.72%', '-9.73%', '8.41%', '82.44%', '-7.28%', '455.56%', '-43.59%', '18.70%', '-40.53%'], 'Round_3': ['$394.40', '$222.06', '$18.15', '$50.00', '$26.26', '$17.55', '$24.38', '$50.46', '$3.45', '$9.92', '$0.52', '$0.37', '$15.59', '$43,790.89'], 'Round_3_Change': ['0.22%', '-0.34%', '-0.22%', '-0.02%', '-11.55%', '-41.46%', '-0.08%', '1.67%', '44.35%', '-11.43%', '4.00%', '-43.94%', '40.32%', '24.97%'], 'Round_4': ['$436.57', '$241.44', '$18.95', '$50.01', '$31.65', '$11.04', '$24.11', '$49.41', '$3.91', '$9.09', '$0.46', '$0.27', '$20.05', '$46,306.45'], 'Round_4_Change': ['10.69%', '8.73%', '4.41%', '0.02%', '20.53%', '-37.09%', '-1.11%', '-2.08%', '13.33%', '-8.37%', '-11.54%', '-27.03%', '28.61%', '5.74%'], 'Round_5': ['$415.17', '$227.67', '$20.00', '$50.04', '$40.70', '$9.48', '$26.66', '$57.55', '$5.45', '$9.00', '$0.39', '$0.21', '$16.68', '$45,538.68'], 'Round_5_Change': ['-4.90%', '-5.70%', '5.54%', '0.06%', '28.59%', '-14.13%', '10.58%', '16.47%', '39.39%', '-0.99%', '-15.22%', '-22.22%', '-16.81%', '-1.66%'], 'Round_6': ['$346.88', '$188.62', '$17.65', '$50.00', '$45.16', '$3.66', '$22.32', '$54.36', '$6.25', '$7.00', '$0.20', '$0.07', '$5.30', '$19,784.73'], 'Round_6_Change': ['-16.45%', '-17.15%', '-11.75%', '-0.08%', '10.96%', '-61.39%', '-16.28%', '-5.54%', '14.68%', '-22.22%', '-48.72%', '-66.67%', '-68.23%', '-56.55%'], 'Round_7': ['$328.30', '$179.47', '$16.78', '$50.02', '$38.90', '$3.75', '$21.68', '$51.22', '$5.85', '$6.70', '$0.16', '$0.16', '$7.50', '$19,431.79'], 'Round_7_Change': ['-5.36%', '-4.85%', '-4.93%', '0.04%', '-13.86%', '2.46%', '-2.87%', '-5.78%', '-6.40%', '-4.29%', '-20.00%', '128.57%', '41.51%', '-1.78%'], 'Round_8': ['$351.34', '$191.19', '$17.12', '$50.03', '$42.95', '$3.14', '$24.15', '$52.92', '$6.08', '$5.85', '$0.08', '$0.11', '$6.48', '$16,547.50'], 'Round_8_Change': ['7.02%', '6.53%', '2.03%', '0.02%', '10.41%', '-16.27%', '11.39%', '3.32%', '3.93%', '-12.69%', '-50.00%', '-31.25%', '-13.60%', '-14.84%'], 'Round_9': ['$376.07', '$204.10', '$17.35', '$50.02', '$41.96', '$2.37', '$24.80', '$51.53', '$5.07', '$6.50', '$0.13', '$0.10', '$9.89', '$28,478.48'], 'Round_9_Change': ['7.04%', '6.75%', '1.34%', '-0.02%', '2.69%', '-24.52%', '0.97%', '-2.63%', '-16.61%', '11.11%', '62.50%', '-9.09%', '52.62%', '72.10%'], 'Round_10': ['$407.28', '$220.28', '$17.00', '$50.04', '$38.86', '$0.51', '$25.04', '$49.24', '$4.32', '$6.80', '$0.10', '$0.10', '$10.13', '$30,477.25'], 'Round 10_Change': ['8.30%', '7.93%', '-2.02%', '0.04%', '-7.39%', '-78.48%', '0.97%', '-4.44%', '-14.79%', '4.62%', '-23.08%', '0.00%', '2.43%', '7.02%'] } # Create the dataframe df = pd.read_csv('ZTS/Ticker_Values_Stand.csv') skip = 3 + 2 * (self.round_number) cols = df.iloc[:, skip:skip + 2].copy() df = df.iloc[:, 0:3] df = pd.concat([df, cols], axis=1) current_columns = df.columns.tolist() current_columns[3] = 'Round_1' current_columns[4] = 'Round_1_Change' # Assign the modified column labels back to the DataFrame df.columns = current_columns df_to_list_of_dicts = df.to_dict(orient='records') data_modified = [] for row in df_to_list_of_dicts: modified_row = row.copy() buy_fieldname = 'buy_count_' + row['Modified_Ticker'] sell_fieldname = 'sell_count_' + row['Modified_Ticker'] modified_row['buy_fieldname'] = buy_fieldname modified_row['sell_fieldname'] = sell_fieldname data_modified.append(modified_row) previous_round_number = self.subsession.round_number - 1 tickers = [ 'VOO', 'VTI', 'ZZW', 'MDKS', 'UDX', 'DSLO', 'NOQ', 'XPOW', 'MWQ', 'STCK', 'IUM', 'JUNW', 'ETQ', 'BTC' ] initial_values = {} if previous_round_number == 0: for ticker in tickers: initial_values[f'buy_count_{ticker}_initial'] = 0 else: # Otherwise, retrieve the previous round's player and get the value for each ticker previous_player = self.player.in_round(previous_round_number) for ticker in tickers: initial_values[f'buy_count_{ticker}_initial'] = getattr(previous_player, f'buy_count_{ticker}') self.player.update_portfolio_value(pd.DataFrame(data_modified)) return dict( cash = self.to_human_readable(self.player.cash), share_value = self.to_human_readable(self.player.share_value), portfolio_value = self.to_human_readable(self.player.portfolio_value), portfolio_profit=self.to_human_readable(self.player.portfolio_profit), ) page_sequence = [ InstructionPage, TwitterPage, TwitterPageAll, TwitterPageDisclosure, TwitterPageInoculation, TwitterPagePrebunk, TwitterPageStimuli, TwitterPage2, TwitterPage2All, TwitterPage2Disclosure, TwitterPage2Inoculation, TwitterPage2Prebunk, TwitterPage2Stimuli, RedditPage, RedditPageAll, RedditPageDisclosure, RedditPageInoculation, RedditPageStimuli, RedditPagePrebunk, RedditPage2, RedditPage2All, RedditPage2Disclosure, RedditPage2Inoculation, RedditPage2Stimuli, RedditPage2Prebunk, TikTokPage, TikTokPageDisclosure, TikTokPageInoculation, TikTokPagePrebunk, TikTokPageStimuli, TikTokPage2, TikTokPage2Disclosure, TikTokPage2Inoculation, TikTokPage2Prebunk, TikTokPage2Stimuli, TradingPage, ResultsPage, ProlificIDPage, ThankYouPage, ]