AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)
MIT License
2.1k stars 465 forks source link

Buy/Sell Step Logic Not Working in Stocks? #40

Closed windowshopr closed 3 years ago

windowshopr commented 3 years ago

Hey!

Just found the repo and love it, but I am wondering what's going on re: the stocks environment.

According to the step logic in the trading_env super class:

        trade = False
        if ((action == Actions.Buy.value and self._position == Positions.Short) or
            (action == Actions.Sell.value and self._position == Positions.Long)):
            trade = True

...and after a reset, the initial position is a Short. So this to me reads that a Buy position will only be opened if the current position is a short, and a Buy action is generated. But when I review my render:

image

...you can see it starts with a bunch of red sells. How? Why? :'(

Also, using that same step logic, I would assume that if a Sell/Short position is already active, no other Short/Sells would be issued, but there's still consecutive red dots on that render, same as green for buys. What do these dots denote exactly?

I have another question about the quantstats report too. If the render says "Total Profit: 0.6828566" or whatever it's profited, how come the quantstats report is so down??

image

Thanks! Love the work!

windowshopr commented 3 years ago

Upon review of the code, I'm noticing that each green dot represents wherever a current Long position is held, and red for the Shorts, so it's not like those are separate actions, just showing what kind of position is currently being held.

The profit, if less than 1, would indicate a loss, based on the reset value of 1. I think I have it now, thanks!