Portfolio value lagged.



  • Hi, I've been searching for a while and didn't get a good answer for what I'm going through. I'm not very familiar with the details, which I'm trying to improve rapidly.

    I have turned on the coc and coo function here and am trying to keep records of every day's closing prices and daily portfolio value with

    self.dataclose[0] 
    self.stats.broker.value[0]
    

    Aftering printing out everything, this is what happens it seems:

    1. it creates an order when a strategy signals it to
    2. it executes the order created the day before using the closing price from the previous day
    3. the portfolio value seems to be lagged. Say my cost base is 100 at day 1, the trade is executed on day 2. Closing price on day 2 is 99, but the portfolio value remains at 100.
    4. Only on day 3, the portfolio value shows up as 99.

    I'm wondering

    1. Is it possible to create and execute trades on the same day?
    2. If a trade does have to execute on two separate days Is it possibly to use the open price of the next day?
    3. Is it possible to align those portfolio values so that the changes in portfolio value happens on the same day as the changes in closing prices, as opposed to the following day?

    Thanks!


  • administrators

    @yjy said in Portfolio value lagged.:

    1. Is it possible to create and execute trades on the same day?

    Yes. You are getting the close price with cheat-on-close. But what you cannot (and won't get with backtrader) is creating an order with for example self.buy is an immediate execution. The platform will queue the order in the broker just like any other order and execute it as soon as possible. The value you are collecting doesn't take the order execution into account, because the order is simply queued. The value isn't lagging.

    Your expectation is to get matched in an unrealistic instant scenario with prices that are already gone (you may have good reasons for it), but backtrader tries to approximate as much as possible the reality of trading, even if you activate cheat-on-close

    1. If a trade does have to execute on two separate days Is it possibly to use the open price of the next day?

    That's the standard default behavior with Market orders and for example timeframe=bt.TimeFrame.Days. The Market order is matched against the next incoming price which is the open price of the next bar.

    See:

    1. Is it possible to align those portfolio values so that the changes in portfolio value happens on the same day as the changes in closing prices, as opposed to the following day?

    No. As explained above, that would be completely unrealistic..


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.