-
Notifications
You must be signed in to change notification settings - Fork 204
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
Mistake #4
Comments
Hi, thanks for your comment. I still don't get where is my mistake, maybe you can write how you think it should look like? You don't even imagine how satisfied I feel hearing such great feedback, thank you! |
should be |
Thanks, will test the impact later |
If you want, here is a little piece of code of my own. Semantic :
With such a function you can easily put any currency in it. Even dollar. def trade(self, trade_type: int, update_last: bool = True) -> float:
"""
Execute action.
Exchange our currency to another one, apply fees.
:param trade_type: The wanted currency index number as defined in the global dataframe
:return: The ratio of the exchange (relative percent change)
"""
wanted_currency: Final[str] = self.df.currencies[trade_type]
if wanted_currency == self.current_currency:
return 0
if wanted_currency in ["etheur", "ltceur"] and self.current_currency in ["etheur", "ltceur"]:
self.trade(1, update_last=False) # Trade to bitcoin first because there is no relation between eth and ltc
my_currency_price = self.df.price(self.current_currency, self.current_step)
new_currency_price = self.df.price(wanted_currency, self.current_step)
ratio = my_currency_price / new_currency_price
last_trade_value = self.last_amount * self.last_price
if self.fees:
self.amount *= 0.995 # Apply fee
if update_last:
self.last_amount = self.amount
self.last_price = my_currency_price
self.last_currency = self.current_currency
self.amount *= ratio
self.current_currency = wanted_currency
current_trade_value = self.amount * new_currency_price
trade_ratio = data.PctChange(last_trade_value, current_trade_value)
with open("W:\\trades.log", "a") as outfile:
outfile.write(f"Order_id:{self.episode_orders}:step{self.current_step}::{self.current_currency}:amount={self.amount}:price={new_currency_price}:Ratio={trade_ratio}\n")
self.episode_orders += 1
return trade_ratio |
I also saw this but I wanted to finish the tutorial before making any change, and forgot later on, thx for the reminder |
You'll see how much harder it is to go above average profit-per-episode just by fixing that. |
I think that original version is correct. if self.trades[-1]['type'] == "buy" and self.trades[-2]['type'] == "sell": If this code is changed to there won't be any reward. reward will always be zero. The orignal code is correct because it tells that it was good choice 'selling' at higher price than current price or it was bad choice 'selling' at lower price than current price. example) sorry for poor english |
I think this is correct as well; it's the price from the (second to last purchase/sale * quantity) ie, the total, compared to the latest at the previous price. What I can't get behind is the use of a negative reward for a sale followed by a purchase. I think that's limiting. |
Seems like the perfect opportunity to learn more about it. |
Hi,
Big mistake right here :
https://github.com/pythonlessons/RL-Bitcoin-trading-bot/blob/main/RL-Bitcoin-trading-bot_7/RL-Bitcoin-trading-bot_7.py#L309
Basically you set your reward as the difference in value of the trades. Which is fine.
The value of a trade is amount of the thing multplied by the price of the thing. Fine.
However, in this particular line, you have made a mistake (by copy pasting your code I believe, it happens).
Because you set the amount of the buy trade the same as the amount of the previous sell trade (= bypassing the fees).
It is only one character at line 309 ... and it dramastically changes your results and the way the model learns.
Still, I would like to thank you for providing your lessons and code online. Sincerely.
I am doing other personal things using pytorch and you're inspiring a lot.
It is a great experience for me to try and translate your code and other youtubers work into pytorch.
You have no idea how much I learned faster thanks to you.
I like a lot your blog posts, mathematical explanations.
Keep it up.
The text was updated successfully, but these errors were encountered: