Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookahead Bias #15

Open
MarshallPeng opened this issue Sep 12, 2021 · 3 comments
Open

Lookahead Bias #15

MarshallPeng opened this issue Sep 12, 2021 · 3 comments

Comments

@MarshallPeng
Copy link

current_price = self.df.loc[self.current_step, 'Open']

Hi Rokas,

Thank you for the lesson and fantastic work on this tutorial. I have a quick question about why you set the current price equal to the 'open' price rather than the Close. The agent is able to see the close price for any time step, but is still able to execute at the open price. Doesn't this provide information that a real trader would not have? In other words, isn't the agent able to see that, for example, the close is higher than the open, and therefore should buy? I think this introduces some form of lookahead bias. Do you know what your results look like if you set the current price to the close?

Thanks

@kitmir
Copy link

kitmir commented Jan 21, 2022

I do not think this line is look ahead bias.
Generally speaking, the closing price of a candle is the opening price of the next candle.
But if you want to be sure you can change to:
current_price = self.df.loc[self.current_step-1, 'Close']
You will get the same result.

@MarshallPeng
Copy link
Author

No, this is most definitely look ahead bias.

At each time step the agent is able to see the closing price, while still being able to buy/sell at the open price. In a real trading scenario, this would never be possible. To make the environment more realistic, you would have to set the current_price = self.df.loc[self.current_step, 'Close']. But, if you try this out, it significantly decreases the performance of the agent compared to what was reported in the tutorial.

Setting current_price = self.df.loc[self.current_step-1, 'Close'] as you suggested does nothing to fix the problem as you are still executing at the previous time step while having knowledge of the next time step.

@kitmir
Copy link

kitmir commented Jan 27, 2022

I am not sure if I would agree with you but I see what you mean and I will give it another look.
But I advice also for you to look into what is being sent to action function. State doesn't include current step. that's the reason why I say it is not lookahead bias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants