Kismuz / btgym

Scalable, event-driven, deep-learning-friendly backtesting library
https://kismuz.github.io/btgym/
GNU Lesser General Public License v3.0
979 stars 259 forks source link

Modify action space to support stoploss and takeprofit #111

Closed Ray-0403 closed 4 years ago

Ray-0403 commented 5 years ago

Since my Mac can't downgrade matploitlib to 2.0.2 , i need to move the btgym file to site-packages by myself and i need the init.py file, thank you

Kismuz commented 5 years ago

@Ray-0403 , do you mean this one https://github.com/Kismuz/btgym/blob/master/btgym/__init__.py ?

Ray-0403 commented 5 years ago

@Kismuz thx, and i have another question. When it comes to forex trading, setting stoploss and takeprofit points is important i think. How to modify the action space to support this? For each buy/sell order, i want the agent to choose a stoploss point from (30,40,50,60) and takeprofit point from(40,50,60,70,80,90,100, none)(i don't consider breakeven or trailing stop for now). Can u give me an example about how to modify the code? Also, i want the agent can only hold one position or no position for each time(for example, if the agent open a position after the first bar, it won't open a new position after the second bar...) and be able to choose the position size from a range like (0.5/1/1.5/2/...) lots. And another idea is to combine the stoploss and position size together. For example, when the agent want to open a buy position, it will first decide the stoploss points(choosing from the range we give), and then it will use the stoploss points to calculate the position size. If we set that for each trade the biggest loss we allow is 5% of the total account, then we use the stoploss points to decide the biggest position size we allow for each trade. (and we need to consider the min position size the broker allows us to open during this process)

Kismuz commented 5 years ago

@Ray-0403,

For each buy/sell order, i want the agent to choose a stoploss point from (30,40,50,60) and takeprofit point from(40,50,60,70,80,90,100, none)

I haven't implemented neither market orders nor stop/take points as action variants, so you have to develop it for yourself; one possible option is to utilize discrete action space in a manner described in this paper: https://arxiv.org/pdf/1812.10252.pdf , see p.7 D. "Action space"

only hold one position or no position for each time(for example, if the agent open a position after the first bar, it won't open a new position after the second bar...) and be able to choose the position size from a range

this can also can be incorporated in a same way by multiplying action space dimensionality, but from my experience it is harder to learn than when agent emits consecutive orders of fixed size.

See also: #37

Kismuz commented 4 years ago

Closed due to long inactivity period.