Open SamTov opened 1 year ago
Hey Samuel, we definitely implemented our forex integration to feel like trading crypto so I've seen some complaints from forex traders about how it feels to use because it doesn't have the discrete position logic. Our implementation is mathematically the same its just different to interact with.
In your case I think you may also have your symbols flipped. We go by the convention that if you were to buy EUR-AUD
you purchase EUR and lose AUD in that symbol pair. In the other way AUD-EUR
, you would lose EUR and purchase AUD.
Would be super happy to accept some contribution of buy/sell wrappers for forex to provide discrete position logic if you're interested.
Hey @EmersonDove, thank you for your detailed response. I haven't had much time outside of work but I hope to have some more time soon.
It seems I have misunderstood some of the API in this case so I will need to go back over it and see if I can better understand it. If I can get my head around how it is working enough to feel comfortable with the backend, I will be sure to make a PR.
So I went back over all the tests and I see now how to set initial values of the EUR and AUD values. I ran a quick test to try and understand your statement "Our implementation is mathematically the same it's just different to interact with". I am not sure I agree or see how to run a proper back test in the current version.
In my test, every even time step I opened a buy
position with:
state.interface.market_order(symbol, side='buy', size=int(buy))
and every odd I made a sell position on the same symbol:
state.interface.market_order(symbol, side="sell", size=int(buy))
and I do this only for the first 10 time steps in the backtest before running for something like 50 steps.
In a FOREX marketplace, the sell side would be shorting a position, therefore buying and selling in an alternating way would lead to having 10 open positions, 5 shorts and 5 buys. The plots below are the result:
So aside from currency value changes which can take place during the buy and sell, it looks like there are no open positions after the 10th time step. While I do see how that this is how the software is written and that does make sense for cryptocurrency, I don't see how one can run a proper and safe backtest in this case. I would like to be able to make decisions on closing long positions or hedging with both sides. Is it possible to run a test like this within the blankly framework?
Metatrader 5 provides 2 accounting mode :
https://www.mql5.com/en/articles/2299 It will be nice to have a similar system with blankly. The current way blankly handles trades seems to be the netting system.
Description
First off I just want to say I really like the package and enjoy using it.
I do not have a bug so to say more a question to help clarify forex trading through blankly. Typically in FOREX one speaks of a buy and sell position which is in line with the blankly language for trades. However, in the realisation of these trades I am a little lost as to how it is implemented.
If I make a buy position into EUR-AUD for example I am purchasing AUD. If I want to now open a sell position, it will use the money allocated in AUD. So if I do not have a large enough open buy position, I cannot open a sell position in EUR-AUD. Not only that, but this gives me the impression that I am actually closing a buy position when I open a sell which is very counter to some strategies which may actually want to open both trade positions for example. In reality, when trading on the FOREX markets, I can open a 100 euro buy position followed by a 600 euro sell position and that is completely fine. In Blankly, I don't know how to achieve this in a backtest. I also don't know how to open these positions so that they do not interfere with each other as in principle, they should not.
This is just what I have come across from trying to backtest FOREX algorithms through OANDA so if I am doing something wrong I would like to know. If it is also just some differences for the FOREX side of things I would also be happy to contribute.