For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Buy and Hold example - monthly cash being added twice?
-
From the buy and hold blog post:
Buy and HoldWhy is the self.p.monthly_cash added first to self.broker.add, and then again to calculate the target_value for the current order? Isn't this adding the cash twice?
def notify_timer(self, timer, when, *args, **kwargs): # Add the influx of monthly cash to the broker self.broker.add_cash(self.p.monthly_cash) # buy available cash target_value = self.broker.get_value() + self.p.monthly_cash self.order_target_value(target=target_value)
-
@gretzteam I believe you are adding the cash twice. First using:
self.broker.add_cash(self.p.monthly_cash)
Then here:
self.broker.get_value() + self.p.monthly_cash
get_value
will have the first cash addition in it. -
-
@gretzteam No my error, get_value is returning the value of a datas, or if no datas provide then all the market value of the datas. Backtrader's blog is correct. See the comments here