Setting a commision changes buy size to be in monetary units?
-
Hi,
When I use:
cerebro.broker.setcommission(commission=0.005)and place a buy order:
self.buy(data=self.data0, size=1)I see in 'notify_order' when the order status is order.completed:
order.executed.price = 1.8768
cerebro.broker.getvalue(self.datas) = 1.9732
self.data0[0] = 1.9732which indicates that 1 unit of the stock was bought.
However, when I set
cerebro.broker.setcommission(commission=0.005, commtype=bt.comminfo.CommInfoBase.COMM_FIXED)
and use the same buy order I get when the order is completedorder.executed.price = 1.8768
cerebro.broker.getvalue(self.datas) = 1.0
self.data0[0] = 1.9732which indicates that the order was places to buy as many units as possible for 1 monetary unit.
Is this a bug or a feature?
How can I set a fixed commision in monetary units and still place buy orders where the size parameter indicates units of the stock to buy?Thanks!
-
You are comparing apples and oranges actually.
@Gil-Keren said in Setting a commision changes buy size to be in monetary units?:
cerebro.broker.setcommission(commission=0.005)
Here you don't specify the commission type and the original behavior is to consider you are operating on stocks with a % commission, because you haven't specified a
margin
(which is meant for future-like assets)@Gil-Keren said in Setting a commision changes buy size to be in monetary units?:
cerebro.broker.setcommission(commission=0.005, commtype=bt.comminfo.CommInfoBase.COMM_FIXED)
In this case you set commission type and the rest of parameters are taken at face value. The default is to operate with future-like assets.
To understand the behavior read the parameter explanation for commission schemes
-
Thanks.
I read the link you attached for the documentation.
Note that the size parameter in buy() is interpreted as face value even I set a percentage commission:cerebro.broker.setcommission(commission=0.005, commtype=bt.comminfo.CommInfoBase.COMM_PERC)
self.buy(data=self.data0, size=1)Then in notify_order:
order.executed.price
1.8768
order.executed.comm
0.009384 # This is 0.5% of 1.8768, makes sense so far
cerebro.broker.getvalue(self.datas)
1.0 # size parameter in buy() was interpreted as face value, not as amount of shares t buy.But my question is the following:
How do I set the commission to be in in fixed monetary units, but still have the 'size' parameter in 'buy()' interpreted as the amount of shares to buy? -
The
size
value is always the number of shares, contracts or whatever you want to buy.Even if you checked the link, it is still being used wrongly. You are not buying shares, you are buying contracts. Either set
stocklike=True
or use the broker methodaddcommissioninfo
and add an instance of for example:CommInfo_Stocks_Fixed
Of fix the parameters of your own subclass like here: Docs - Extending Commissions
-
In any case:
getvalue
doesn't give the actualsize
. It gives you thevalue
of your position which is not the size.
To see the size, use for example:
self.position.size
in the strategy (this is good for the 1st data in a multi-data approach and single data approaches)
The value is given as
1.0
, because in the absence of meaningful values tosetcommission
, the system assigns a value of1.0
to the margin required to keep a future alive (as explained above, you are operating with future-like assets) and that's the value of your position (using the nominal value would in most cases exceed the total value of the account what would probably be puzzling) -
Works like a charm, thanks for the detailed answer!