-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[request] Consider to implement the trading capital, position sizing and market risk in gekko #1841
Comments
Here comes a brief example what I meant by trading account on an exchange and do some risk assessment by calculating the position size.. Imagine you have the following currencies/assets on an exchange: Account (trading account) balance is the estimated value of the currency and the assets you want to trade
So the account balance is the BTC price of the assets above, and the trading risk is 1% you wil lhave 3 markets and each of them has 1% trading risk:
When you enter a position (short or long) you need to calculate the position size (the max amount you can trade) of the market. This means when we get the signal we have the theoretical entry price (as the real entry price is the price when you actually buy or sell assets). Assume, that the long entry price for the BTC-NEO market is 0.0125000 and as we have 0.25 BTC then we can buy max. 20 NEOs. but, if you buy all and the price drops for example 10% and your signal says to sell, then you will lose a lot. So, to stop the loss or get the profit, you need to have some stop-loss (cancel orders at the losing position) and an exit price (exit from winning position). It's usually done by configuring some indicators (some crosses etc.) or use some volatility measurement such as TA-Lib's ATR or similar. I really like the idea of the volatility measurement as the cryptocurrencies are very volatile, and the ATR gives you the Average True Range for a certain period, but it also means if the volatility is high you cannot buy that amount of NEOs because you will lose a lot on the lost position. We set the stop-loss signal based on the ATR(20, SMA) ( I have checked and it's 0.000212545 at the moment), so if we set
This means if we lose the position and we will sell the ~5.88 NEO at 0.01207491 price (curr - 2*ATR), we will get 0.07101384413, that means we will only lose 0.07101384413 - 0.07351384413 = -0.002500 which is the 1% of the current (not the whole market balance the 0.375) balance. |
There's the beginnings of a stop loss implementation in #1317. Would just need to be extendable to do the ATR for half of this feature. What I really want is the ability to only trade with a portion of currency though. Would be really nice to have multiple gekkos running on one exchange with the same pairing. |
@ilap Yes, it is very well understood what you are implying here, very important. There has been discussions about this going for months, and sophisticated users of Gekko end up implementing their own version of this by modifying the core source code. Due to where the project is at, and how many people are using it in different ways, this is something which could take a long time to get consensus on how to implement, so that is why people go ahead and implement it on their own. Long term it needs to be addressed in the core functionality of Gekko to add support for various types of position and portfolio sizing, risk management, etc. Since this is very much an open source effort, the best way at this point I'd suggest would be to study the existing app structure and propose different ways to implementing and consult members of the community here on their opinions, get consensus, make a roadmap, and start implementing incrementally with pull requests. Or else make a fork, and fully implement your vision for it, and then work on getting it merged back into the core. That type of effort would be appreciated by the Gekko power users, as some people end up taking shortcuts and hacking these features in, though it doesn't end up making it back into the source. |
@scragz Unfortunately, it's not as easy as it looks, as Gekko does not really track the orders.
So it's harder than it looks, but not impossible. Note: Proper definition for trade and order is required, as the order != trade, as one order can have multiple trades, as the exchange trading engines probably would buy/sell from/to different sellers/buyers to fulfil the order. @ansonphong I think, the get consensus is the hardest part of the game, as in general, the decisions are made by personal believes, emotions and opinions which do not represent any scientific approach.:) |
Very old issue, apologies for never responding here. Right now portfolio management inside your strategy is out of scope. While I agree it's great to have it, it complicates a lot of things. I've gone into this in here: #1619 (comment) and here: #2173. Implementing this would have to start with a discussion on design. Since it's throwing away all of Gekko's core principles we need to come up with new ones. The forum would be a more appropiate place for this as this is the bug tracker. |
Note: for support questions, please join our Discord server
[ ] bug report
[x ] feature request
[ ] question about the decisions made in the repository
The currently implemented trading engine in gekko is very risky for any users as it does not have the position sizing, market risk and trading capital features implemented.
Gekko currently trades as "all in", which means the market risk is very high (read this) instead of the common 1% (for newbies) or max. 2% (advanced traders), and it also reduces the market diversity to only 1 market and also does not allow pyramiding.
The initial potential solution could be the following:
This will reduce the trading risks and can increase the diversification of the markets as we would be able to run different gekko instances for the same exchange. It would allow us to play/test gekko on real exchange defining some very small trading capital e.g. running real trades using a very small amount of currency (0.001 BTC with ETH/BTC pair).
I had a look at the portfolioManager.js and the trader.js and it seems that the balance calculating feature can be easily implemented in gekko by using some abstract method in the portfolio manager (Interface Pattern similar to the Decorator Pattern, but not really).
The simple pseudo-code in ES6 is the following:
The text was updated successfully, but these errors were encountered: