1

I am using optimizer in Pyalgotrade to run my strategy to find the best parameters. The message I get is this:

2015-04-09 19:33:35,545 broker.backtesting [DEBUG] Not enough cash to fill 600800 order [1681] for 888 share/s
2015-04-09 19:33:35,546 broker.backtesting [DEBUG] Not enough cash to fill 600800 order [1684] for 998 share/s
2015-04-09 19:33:35,547 server [INFO] Partial result 7160083.45 with parameters: ('600800', 4, 19) from worker-16216
2015-04-09 19:33:36,049 server [INFO] Best final result 7160083.45 with parameters: ('600800', 4, 19) from client worker-16216

This is just part of the message. You can see only for parameters ('600800', 4, 19) and ('600800', 4, 19) we have result, for other combination of parameters, I get the message : 546 broker.backtesting [DEBUG] Not enough cash to fill 600800 order [1684] for 998 share/s.

I think this message means that I have created a buy order but I do not have enough cash to busy it. However, from my script below:

        shares = self.getBroker().getShares(self.__instrument)
        if bars[self.__instrument].getPrice() > up and shares == 0:
            sharesToBuy = int(self.getBroker().getCash()/ bars[self.__instrument].getPrice())
            self.marketOrder(self.__instrument, sharesToBuy)

        if shares != 0 and bars[self.__instrument].getPrice() > up_stop:
            self.marketOrder(self.__instrument, -1 * shares)
        if shares != 0 and bars[self.__instrument].getPrice() < up:
            self.marketOrder(self.__instrument, -1 * shares)

The logic of my strategy is that is the current price is larger than up, we buy, and if the current price is larger than up_stop or smaller than up after we buy, we sell. So from the code, there is no way that I will generate an order which I do not have enough cash to pay because the order is calculated by my current cash.

So where do I get wrong?

epx
  • 571
  • 4
  • 16
  • 27

1 Answers1

1

You calculate the order size based on the current price, but the price for the next bar may have gone up. The order is not filled in the current bar, but starting from the next bar.

With respect to the 'Partial result' and 'Best final result' messages, how many combinations of parameters are you trying ? Note that if you are using 10 different combinations, you won't get 10 different 'Partial result' because they are evaluated in batches of 200 combinations and only the best partial result for each batch of 200 combinations gets printed.

Gabriel
  • 492
  • 3
  • 4