You are browsing as a guest. Sign up (or log in) to start making projects!

25m 36s logged

day whatever Building the Market Simulation Clock

Today I implemented two core pieces of the MarketSim AI simulation engine: step() and get_history().

The biggest challenge in this project is preventing future data leakage. The trading agent must only see information that would have been available on the current simulated date.

To support this, I created a trading calendar system based on historical SPY market data. Instead of manually adding one day at a time (which would break on weekends and holidays), the simulator follows actual market trading days. The new step() method advances the simulation exactly one trading day forward by moving through this calendar.

I also implemented get_history(), which acts as a security layer between the agent and the raw market data. When historical data is requested, the method filters the dataset to include only dates up to the current simulation date before returning the requested lookback window. This ensures the agent can never accidentally access future information.

Example:

history = env.get_history(
    "AAPL",
    lookback_days=30
)

returns only the previous 30 trading days that existed at that point in time.

Along the way I added unit tests to verify:

  • Environment creation
  • Trading-day advancement with step()
  • Historical data retrieval
  • Prevention of future-date access

Current project status:

✅ Data download pipeline
✅ Data cleaning pipeline
✅ DataLoader
✅ MarketEnvironment
✅ Trading calendar system
step() simulation advancement
get_history() future-leakage protection
✅ 7 passing tests

The simulator can now move through history one trading day at a time while enforcing realistic information constraints—the foundation needed for future trading agents.

0
2

Comments 0

No comments yet. Be the first!