Spaces:
No application file
No application file
File size: 13,966 Bytes
cbd168e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | """
Configuration module for the AI Trading Experiment.
Contains both participant-visible and researcher-controlled parameters.
"""
from dataclasses import dataclass, field
from typing import Dict, List, Optional
import json
@dataclass
class ParticipantVisibleParams:
"""Parameters that participants can adjust."""
explanation_depth: int = 50 # 0-100: Minimal to Detailed
communication_style: int = 50 # 0-100: Formal to Casual
@dataclass
class ResearcherControlledParams:
"""Hidden parameters controlled by researcher for experimental conditions."""
accuracy_rate: float = 0.7 # 0-1: Probability AI advice leads to good outcome
proactivity_level: int = 50 # 0-100: How often AI initiates advice
confidence_framing: int = 50 # 0-100: How assertive advice sounds
risk_bias: int = 50 # 0-100: Conservative to Aggressive recommendations
# Experimental condition identifier
condition_name: str = "default"
@dataclass
class ExperimentConfig:
"""Overall experiment configuration."""
# Starting conditions
initial_portfolio_value: float = 100000.0
currency_symbol: str = "credits"
# Session settings
scenarios_per_session: int = 8
min_decision_time_seconds: float = 5.0 # Minimum time before decision allowed
# Proactive AI settings
proactive_delay_seconds: float = 3.0 # Delay before AI offers proactive advice
proactive_probability: float = 0.7 # Base probability of proactive advice per scenario
# Data collection
track_mouse_movements: bool = False # Future feature
track_time_on_elements: bool = True
# UI settings
show_portfolio_history: bool = True
show_ai_accuracy_feedback: bool = False # Whether to reveal if AI was right
# Researcher params (can be overridden per experiment condition)
researcher_params: ResearcherControlledParams = field(
default_factory=ResearcherControlledParams
)
# Pre-defined experimental conditions for A/B testing
EXPERIMENT_CONDITIONS: Dict[str, ResearcherControlledParams] = {
"high_accuracy_high_confidence": ResearcherControlledParams(
accuracy_rate=0.85,
proactivity_level=70,
confidence_framing=80,
risk_bias=50,
condition_name="high_accuracy_high_confidence"
),
"high_accuracy_low_confidence": ResearcherControlledParams(
accuracy_rate=0.85,
proactivity_level=70,
confidence_framing=20,
risk_bias=50,
condition_name="high_accuracy_low_confidence"
),
"low_accuracy_high_confidence": ResearcherControlledParams(
accuracy_rate=0.40,
proactivity_level=70,
confidence_framing=80,
risk_bias=50,
condition_name="low_accuracy_high_confidence"
),
"low_accuracy_low_confidence": ResearcherControlledParams(
accuracy_rate=0.40,
proactivity_level=70,
confidence_framing=20,
risk_bias=50,
condition_name="low_accuracy_low_confidence"
),
"conservative_advisor": ResearcherControlledParams(
accuracy_rate=0.70,
proactivity_level=50,
confidence_framing=50,
risk_bias=20,
condition_name="conservative_advisor"
),
"aggressive_advisor": ResearcherControlledParams(
accuracy_rate=0.70,
proactivity_level=50,
confidence_framing=50,
risk_bias=80,
condition_name="aggressive_advisor"
),
"passive_advisor": ResearcherControlledParams(
accuracy_rate=0.70,
proactivity_level=20,
confidence_framing=50,
risk_bias=50,
condition_name="passive_advisor"
),
"active_advisor": ResearcherControlledParams(
accuracy_rate=0.70,
proactivity_level=80,
confidence_framing=50,
risk_bias=50,
condition_name="active_advisor"
),
}
@dataclass
class Scenario:
"""A trading scenario presented to the participant."""
scenario_id: str
company_symbol: str
company_name: str
sector: str
country: str
current_price: float
situation_description: str
# Hidden from participant - determines outcomes
optimal_action: str # "BUY", "SELL", or "HOLD"
ai_recommendation: str # What AI will recommend (may differ from optimal)
ai_is_correct: bool # Whether AI recommendation matches optimal
# Outcome percentages based on decision
outcome_buy: float # e.g., -0.08 for -8%
outcome_sell: float
outcome_hold: float
# Additional context for AI reasoning
key_factors: List[str] = field(default_factory=list)
red_flags: List[str] = field(default_factory=list)
positive_signals: List[str] = field(default_factory=list)
# Pre-defined scenarios
SCENARIOS: List[Scenario] = [
Scenario(
scenario_id="S001",
company_symbol="MRD",
company_name="Meridian Industries",
sector="Manufacturing",
country="Republic of Valdoria",
current_price=52.30,
situation_description="""Meridian Industries recently announced a 5-year defense contract worth 2.1B credits.
The stock has risen 12% over the past month on this news. Labor disputes at the southern facility
have been resolved. The company maintains a healthy balance sheet with low debt.""",
optimal_action="HOLD",
ai_recommendation="HOLD",
ai_is_correct=True,
outcome_buy=-0.035, # -3.5% (already priced in)
outcome_sell=-0.042, # Miss further gains
outcome_hold=0.032, # +3.2% steady growth
key_factors=["Defense contract secured", "Labor issues resolved", "Strong balance sheet"],
red_flags=[],
positive_signals=["Government contract", "Low debt", "Stable management"]
),
Scenario(
scenario_id="S002",
company_symbol="NGP",
company_name="Northgate Pharmaceuticals",
sector="Healthcare",
country="Federation of Eastholm",
current_price=85.50,
situation_description="""Northgate Pharmaceuticals has Phase 3 trial results expected next month for their
flagship rare disease treatment. However, unusual trading volume was detected last week, a board member
resigned citing "personal reasons," and the CFO sold shares worth 500K credits. Competitor Apex Biotech
announced a similar drug in development.""",
optimal_action="SELL",
ai_recommendation="BUY", # AI gives bad advice here
ai_is_correct=False,
outcome_buy=-0.153, # -15.3% (trial fails)
outcome_sell=0.153, # +15.3% (avoided loss)
outcome_hold=-0.153, # Same as buy
key_factors=["Phase 3 trial pending", "Insider activity", "Competitive pressure"],
red_flags=["Board member resignation", "CFO share sale", "Unusual trading volume"],
positive_signals=["Strong pipeline", "Rare disease focus"]
),
Scenario(
scenario_id="S003",
company_symbol="TFE",
company_name="Terraform Energy",
sector="Energy",
country="United Provinces of Somara",
current_price=132.80,
situation_description="""Terraform Energy's fusion prototype achieved a 40% efficiency milestone, a significant
breakthrough. The company has government subsidies locked in for 10 years and is awaiting regulatory
approval for expansion into Valdoria. Last quarter's earnings beat expectations by 12%.""",
optimal_action="BUY",
ai_recommendation="BUY",
ai_is_correct=True,
outcome_buy=0.124, # +12.4%
outcome_sell=-0.089, # Miss the rally
outcome_hold=0.056, # Partial gain
key_factors=["Fusion breakthrough", "Government support", "Expansion pending"],
red_flags=["Regulatory approval uncertainty"],
positive_signals=["Technology leadership", "Stable subsidies", "Earnings beat"]
),
Scenario(
scenario_id="S004",
company_symbol="NXC",
company_name="Nexus Communications",
sector="Technology",
country="Coastal Republic of Marinea",
current_price=218.40,
situation_description="""Nexus Communications holds a monopoly position in Marinea's telecommunications market.
There are unconfirmed rumors of an antitrust investigation. The company's 5G rollout is 60% complete,
and they're planning a satellite constellation launch. Subscriber growth is slowing in mature markets.""",
optimal_action="HOLD",
ai_recommendation="SELL", # AI is overly cautious
ai_is_correct=False,
outcome_buy=0.045, # Slight gain, rumors overblown
outcome_sell=-0.067, # Miss continued performance
outcome_hold=0.045, # Same as buy
key_factors=["Monopoly position", "Antitrust rumors", "5G expansion"],
red_flags=["Regulatory risk", "Slowing growth"],
positive_signals=["Strong cash reserves", "Infrastructure investments"]
),
Scenario(
scenario_id="S005",
company_symbol="APX",
company_name="Apex Biotech",
sector="Healthcare",
country="Republic of Valdoria",
current_price=71.20,
situation_description="""Apex Biotech announced a competing drug to Northgate's flagship product. The company
is integrating a recent acquisition and there are rumors they may be an acquisition target themselves.
The CFO sold shares worth 2M credits last month, though this was part of a pre-planned selling program.""",
optimal_action="HOLD",
ai_recommendation="HOLD",
ai_is_correct=True,
outcome_buy=-0.028, # Slight decline, uncertainty
outcome_sell=-0.015, # Miss potential upside
outcome_hold=0.018, # Modest gain
key_factors=["Competitive positioning", "M&A activity", "Insider sales"],
red_flags=["CFO share sale", "Integration risks"],
positive_signals=["Strong patent portfolio", "Acquisition rumors"]
),
Scenario(
scenario_id="S006",
company_symbol="ICS",
company_name="Ironclad Security",
sector="Defense",
country="Federation of Eastholm",
current_price=93.60,
situation_description="""Ironclad Security won a major cybersecurity contract with the Marinea government.
A cyber attack on a competitor has enhanced ICS's reputation. The company is planning to hire 500
new engineers. Their order backlog represents 18 months of revenue.""",
optimal_action="BUY",
ai_recommendation="BUY",
ai_is_correct=True,
outcome_buy=0.098, # +9.8%
outcome_sell=-0.065, # Miss rally
outcome_hold=0.042, # Partial gain
key_factors=["Major contract win", "Strong backlog", "Expansion hiring"],
red_flags=[],
positive_signals=["Government contracts", "Reputation boost", "Growth investment"]
),
Scenario(
scenario_id="S007",
company_symbol="CSC",
company_name="Coastal Shipping Corp",
sector="Transportation",
country="Coastal Republic of Marinea",
current_price=35.80,
situation_description="""Coastal Shipping Corp benefits from a new trade agreement with Somara. Their fuel
hedging strategy has reduced costs by 8%. However, there are ongoing port strike risks in Valdoria,
and trade treaty negotiations could impact several key routes. The company offers a high dividend yield.""",
optimal_action="HOLD",
ai_recommendation="BUY", # AI is too aggressive
ai_is_correct=False,
outcome_buy=-0.072, # Port strike materializes
outcome_sell=0.034, # Avoided loss
outcome_hold=-0.018, # Small loss
key_factors=["Trade agreements", "Fuel hedging", "Labor risks"],
red_flags=["Port strike risk", "Trade negotiations"],
positive_signals=["New trade deal", "Cost management", "High dividend"]
),
Scenario(
scenario_id="S008",
company_symbol="AUR",
company_name="Aurora Entertainment",
sector="Consumer Discretionary",
country="United Provinces of Somara",
current_price=61.40,
situation_description="""Aurora Entertainment's hit series "Valdoria Rising" broke viewership records.
However, their gaming division underperformed expectations. A new VR platform launches next quarter.
There are rumors Nexus Communications may acquire the company. Cash flow remains negative despite growth.""",
optimal_action="BUY",
ai_recommendation="HOLD", # AI is too conservative
ai_is_correct=False,
outcome_buy=0.186, # Acquisition announced
outcome_sell=-0.142, # Miss acquisition premium
outcome_hold=0.065, # Partial gain from rumors
key_factors=["Content success", "Gaming weakness", "Acquisition rumors"],
red_flags=["Negative cash flow", "Gaming underperformance"],
positive_signals=["Viewership records", "VR launch", "Acquisition interest"]
),
]
def get_scenario_by_id(scenario_id: str) -> Optional[Scenario]:
"""Retrieve a scenario by its ID."""
for scenario in SCENARIOS:
if scenario.scenario_id == scenario_id:
return scenario
return None
def get_condition(condition_name: str) -> ResearcherControlledParams:
"""Get a pre-defined experimental condition."""
return EXPERIMENT_CONDITIONS.get(
condition_name,
ResearcherControlledParams()
)
def create_custom_condition(
accuracy_rate: float = 0.7,
proactivity_level: int = 50,
confidence_framing: int = 50,
risk_bias: int = 50,
name: str = "custom"
) -> ResearcherControlledParams:
"""Create a custom experimental condition."""
return ResearcherControlledParams(
accuracy_rate=accuracy_rate,
proactivity_level=proactivity_level,
confidence_framing=confidence_framing,
risk_bias=risk_bias,
condition_name=name
)
# Default configuration instance
DEFAULT_CONFIG = ExperimentConfig()
|