Is there a preferred method for setting up an initial portfolio at the start of a backtest?
I'm trying to start out my test with an initial purchase and then, based on performance, balance those positions over time. The handle_data function operates on each frame so currently I check to see if the portfolio is empty and setup my portfolio if it is. However, this seems inefficient to do on every frame.
Perhaps even more confusing to me is that I've noticed, after building several times, and changing the backtest date range, that my previous settings for the portfolio are still in memory. After placing several orders I went back into my code and commented out everything except a log statement which showed that the portfolio object still had the previous orders. However the context.portfolio.cash and context.portfolio.positions_value are reset.
I feel like I must be missing something very basic, so my apologies if I haven't picked up on it.