sthewissen / Mynt

An Azure Functions-based crypto currency trading bot; featuring 10 exchanges, 25 indicators, custom strategy support, backtester and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a simple way to allow for hedging?

brspurri opened this issue · comments

It seems the prepare() method of each strategy defines a buy-sell -> buy-sell -> buy-sell pattern by populating the result list which is returned form the method.

Is there any way to support hedging with this workflow? Ie., allow the same coin to be purchased more than one time before reaching a sell point (profit or stoploss). Obviously, the logic for this is simple, but I'm just trying to figure out what needs to be modified in the code (if its at all possible) to allow this.

I should also add that I'm currently looking at this in backtesting context.

At this point I'm fairly sure that there's not. It would probably require some additional code where the bot checks the current trades for their profit rate. The Prepare method is mainly used for defining entry and exit points.

A few thoughts here that I think might be simple. Open for a discussion. In prepare(), the buy and sell signals are denoted as 1 and -1 respectively (as mentioned above). This limits one open trade allowed at a time. However, if we change those values to incrementing values representing different simultaneous buys and sells, then the prepare() method will effectively allow overlapping open orders of the same coin - effectively allowing hedging.

So a result list might looks like:

[ 0 0 1 0 0 2 0 0 -2 0 0 -1 ...]

Indicating two "buys" open at the same time where the second order is sold prior to the first order. (Just a hypothetical). I am working on cleaning up the code in my fork, then will submit a pull request. But wanted to open this up for a discussion before.

On the develop branch the 0/1/-1 system is replaced by a TradeAdvice enum which should provide more flexibility in writing a strategy. Since the strategies are what you make of them it's quite easy to simply generate multiple sell signals in a row. They don't always have to have a matching sell signal. You could add a TradeAdvice called Hedge and use that in your strategy. Some hedging constants will probably need to be added to define a hedging strategy.