## Implementation Guidance for Interdimensional Market Trading Environment

### File Structure
- `interdimensional_market_env.py` - Main environment class
- `market_observation.py` - Observation policy implementation  
- `market_generator.py` - World generator implementation

### Core Classes to Implement

**InterdimensionalMarketEnv(SkinEnv)**
- `_dsl_config()`: Load YAML config, set up exchange rate mechanics
- `reset()`: Initialize or load market state with hidden sinusoidal patterns
- `transition()`: Handle 5 action types with complex state updates
- `reward()`: Multi-stream reward calculation (profit/stability/fairness/research/goal)
- `observe_semantic()`: Return market state with noisy exchange rates
- `render_skin()`: Format trading terminal display
- `done()`: Check max_steps OR embargo>=100 OR negative inventory/ledgers

**Key Transition Logic:**
- PROPOSE_TRADE: Calculate cross-dimensional value using true rates, update ledgers and embargo risks based on trade fairness
- CONVERT_CREDITS: Apply hidden exchange rates regardless of observed noise
- HEDGE: Freeze one dimension's drift pattern for 5 steps, deduct fee
- RESEARCH: Randomly select rate pair, reduce its noise variance permanently  
- DONATE: Remove inventory, reduce target dimension's embargo risk proportionally

**MarketObservationPolicy(ObservationPolicy)**
- `__call__()`: Add gaussian noise to true exchange rates, expose full inventory/ledgers
- Noise level controlled by config, reduced by research actions permanently
- Never expose true rates or drift parameters to agent

**MarketWorldGenerator(WorldGenerator)**  
- `generate()`: Create complete market instance with deterministic randomness
- `_execute_pipeline()`: Run 5 pipeline steps in sequence
- Pipeline steps:
  1. init_from_template: Copy base state template
  2. randomize_inventory: Select 3-7 items with 5-15 units each randomly  
  3. initialize_ledgers: Set 10-30 credits per dimension randomly
  4. generate_exchange_patterns: Create sinusoidal drift [amplitude, frequency, phase] for each rate pair
  5. set_embargo_risks: Initialize 20-40 diplomatic tension per dimension

**Mathematical Core:**
- Exchange rates: `true_rate = base + amplitude * sin(frequency * t + phase)`
- Observed rates: `observed = true_rate + gaussian_noise * noise_reduction_factor`
- Embargo risk updates: Increase when dimension loses value, decrease with donations
- Trade fairness: Compare value given vs received using true rates

**Critical Implementation Notes:**
- All randomization must be seed-based for reproducible environments
- Exchange rate drift continues every step regardless of hedging (hedge freezes observation of drift)
- Embargo termination occurs immediately when any dimension reaches 100% risk
- max_steps in termination section should override environment's self.max_steps if level has different value
- Maintain strict inventory/ledger conservation - no artificial value creation
- Episodes terminate in exactly 40 steps unless embargo/resource violations occur first

**Generator Logic:**
The generator creates diverse but balanced market scenarios by randomizing starting conditions while maintaining mathematical consistency. Each world has unique sinusoidal exchange patterns (different amplitude/frequency/phase per rate pair), varied inventory distributions across item categories, and different initial diplomatic tensions. This ensures agents must learn to identify hidden patterns rather than memorize fixed scenarios, while keeping all rate relationships mathematically valid for arbitrage opportunities.