MarketSim-AI
- 4 Devlogs
- 3 Total hours
Build an autonomous stock-trading simulation platform that evaluates AI-driven investment strategies using historical market data.
Build an autonomous stock-trading simulation platform that evaluates AI-driven investment strategies using historical market data.
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:
step()
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.
Today I worked on various things. I worked on the data loader python file. Ensuring that all the tickers were clean, and processed and then loaded. Then I worked on the market environment python file. This is arguably the most important file because I need to make sure that no future data can be seen by it. After that, I created tests for both the data loader, and the market environment to make sure I am writing production quality code.
Today I spent the majority of my time loading my data. This means downloading the raw data from Yahoo Finance. Then I realized it came in a format I didn’t want. So as you can see below, I spent some time cleaning it up.
Today I spent a lot of time working on organizing all my files and getting the correct architecture structure set up. Very boring indeed.