HOW to Look for Documentation / Features?
-
Hi,
while looking at the features of Backtrader, I frequently come to the point where I am little bit helpless:
E.g.:
I take one of the examples:
quickstart11.py (aka: "Let’s Optimize")
and try to extend it a little bit:
Instead of:
self.order = self.buy()
in
def next(self):
I write:
myCash = cerebro.broker.get_cash() mySize = myCash/(self.dataclose[0] * 0.1) self.order = self.buy(size=mySize)
and nothing happens :-(
I thought I could set the amount of stock to buy just relatively to the amount of money I have.
My asumption was - as it seems to be possible in strategy.py:
def buy(self, data=None, size=None, price=None, plimit=None, exectype=None, valid=None, tradeid=0, oco=None, trailamount=None, trailpercent=None, parent=None, transmit=True, **kwargs):
that I can supply attributes like the amount of stocks (
size
) in this way.How should I look for examples, docu (or something else) to find a solution for this by myself (I realized that the online documentation is in the docu2 folder within the *.rst files, so I can look here for docu, ok - but without success in this case)? Or is there any debug/log mode available that I could activate?
And if somebody knows a quick answer for my issue, that would be nice, too :-)
-
@NewestTrader said in HOW to Look for Documentation / Features?:
mySize = myCash/(self.dataclose[0] * 0.1)
Maybe you wanted to make like this:
mySize = 0.1 * myCash // self.dataclose[0]
-
@NewestTrader said in HOW to Look for Documentation / Features?:
How should I look for examples, docu (or something else) to find a solution for this by myself (I realized that the online documentation is in the docu2 folder within the *.rst
Why would you look in the
reSructuredText
(aka.rst
) files if you can read it online and directly google? (Plus the generated online documentation has a built-in search facility)@NewestTrader said in HOW to Look for Documentation / Features?:
that I can supply attributes like the amount of stocks (size) in this way.
You cannot do it in the bank/broker. When you go to the market you express yourself in
$$
and that low-level operation does the same. Ifsize
had different meanings or entry points it would lead to trouble.In any case and even if you can do it like @ab_trader indicated you are probably looking for this:
Where you can use the family of orders to specify target size, target value or target percentage.
The other option being a
Sizer
which does the calculation for you -
Addition to @Paska-Houso post -
target
orders set percent based on portfolio value (cash + open positions). If you want to use cash only, then your code is better. The other thing that need to be corrected ismyCash = self.broker.get_cash()
-
@ab_trader said in HOW to Look for Documentation / Features?:
target orders set
target_order_size
works with target sizes ... or am I missing something? -
@Paska-Houso in his case the target_order_value can be a better option in this case. I forgot about this type if order.
target_order_size as I remember operates with stock quantities, not percents of cash or portfolio.
-
@NewestTrader said in HOW to Look for Documentation / Features?:
that I can supply attributes like the amount of stocks (size) in this way.
The original poster said ...
@ab_trader said in HOW to Look for Documentation / Features?:
target_order_size as I remember operates with stock quantities
And that was my idea, that he looked into
target_order_size
. I believe we have probably misunderstood each other. -
@Paska-Houso got your point. I was considering the 0.1 * My cash as the goal rather then setting of size. ;) Anyway target orders really convenient feature of the bt.
-
Thanks for your replies guys!