bt icon indicating copy to clipboard operation
bt copied to clipboard

Issue in function to allocate

Open GDQF opened this issue 2 years ago • 1 comments

Hi,

When I backtest multiple strategies, I am sometimes shown the error message below:

The difference between what we have raised with q and
the amount we are trying to raise has gotten bigger since
last iteration! full_outlay should always be approaching
amount! There may be a case where the commission fn is
not smooth

I went into the code and debugged. I was in a situation where self.integer_positions = True and

full_outlay <  full_outlay_of_1_more < amount 

In this particular situation, given that I can buy one more unit, the quantity should go up by one unit q+=1. This would therefore lead to a new full_outlay that is much more closer to amount (but still inferior) which would then lead to the condition np.abs(full_outlay - amount) > np.abs(last_amount_short) to be False and therefore would not trigger the error message.

It appears that this situation is not taken into account in the code If full_outlay < full_outlay_of_1_more < amount then no action is taken to update the quantity nor the full_outlay.

This situation can definitely happen ! Reach out for more details.

                    full_outlay_of_1_more, _, _, _ = self.outlay(q + 1)

                    if full_outlay < amount < full_outlay_of_1_more:
                        break
                    else:
                        q += 1
                        full_outlay = full_outlay_of_1_more

GDQF avatar Aug 29 '22 13:08 GDQF

This is an annoying error message that I have also struggled with. But looking at the code I can't replicate what you are describing/see how that is possible. There is a loop which increases the amount until the condition is satisified. The escape condition below would seem to require that full_outlay_of_1_more>amount https://github.com/pmorissette/bt/blob/edbc9b52b0d27ec9c8d596876db1b3919f3a471c/bt/core.py#L1619-L1620 Please provide more detail! E.g. at what point in the code did you find full_outlay < full_outlay_of_1_more < amount

MDDietz1 avatar Oct 18 '22 17:10 MDDietz1