All entries

    Build a Gym Trading Environment with Transaction Costs

    A toy Gymnasium trading environment can make execution timing and transaction fees explicit.

    A chart and fee tokens illustrate a fictional trading simulation
    Conceptual pixel-art illustration.

    A toy Gymnasium trading environment can make execution timing and transaction fees explicit.

    Build the example

    Define the observation at time t, an action for the target position, and a price at which the action is executed. Debit fees on turnover and calculate reward from the change in equity under the chosen convention. Gymnasium step returns observation, reward, terminated, truncated and info. Document how the episode ends and what reset returns.

    Use prices of 100, 100 and 100 with one unit of position. A buy-and-sell round trip should lose the total fees under the defined convention. Then change one price and verify the mark-to-market change separately from turnover. Test a hold action that produces zero fees so cost accounting cannot accidentally charge every time step.

    Watch the failure boundary

    Define whether transaction costs apply to a reversal as two units of turnover or under a different execution model. Expose equity and fees in the info object so a test can account for every step. Keep termination for environment rules distinct from a time-limit truncation in the training loop.

    Verify the behavior

    Use fictional prices and compare hold, buy-once and frequent-trading baselines. Check that a flat price and positive fees produce a loss when switching positions. Keep observations limited to data that would have been available before the trade, and treat the results as a software simulation.

    FURTHER READING

    Sources

    Technical references checked .

    END OF ENTRY / 89
    Eeshan Singh with Big Ben in London
    BEHIND THE JOURNAL

    Eeshan Singh

    I’m Eeshan Singh Pokharia, an AI Full Stack Developer and CoFounder of UltraFit360. I work across AI features, full-stack product development, and web and mobile experiences—from Figma and frontend interactions to the systems behind them.

    Define whether transaction costs apply to a reversal as two units of turnover or under a different execution model. Expose equity and fees in the info object so a test can account for every step. Keep termination for environment rules distinct from a time-limit truncation in the training loop.

    Meet the author
    THE CONVERSATION

    Your side of the story.