-
I've read through the example to port strategies from backtrader and was attempting to do the same for I feel this might be simple but I couldn't quite understand why in your example @polakowo you were using example below:
The reason I am asking is because the documentation around long entries and long exits versus short entries and short exits is a bit unclear to me. For example, backtesting.py will produce the following trades dataframe in a long/short strategy. (note, the sample dataset below, appears to enter short upon exiting long, but the full series, has partial entries and exits as well. This is why I was attempting to use the
here is a picture incase the markdown of that table didn't format correctly. The question is how to convert this dataframe into a vbt.Portfolio.from_orders() or from_signals() I don't really care which one to use, I just wanted to be able to understand it and explain it to someone else. The
any help would be much appreciated. I'd be happy to share the notebook for the documentation if it is at all helpful. Though, I would suspect that you would do a much better job of that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@eervin123 the notebook was created by one of the users, I can't really answer the design decisions that were made. Regarding your dataframe with trades, there is an issue you need to solve. If you want to use either from_orders or from_signals, you need to make sure that there is at most one order per bar. At bar 949 you exited at 283.98 and entered at 283.41204, which isn't possible to do with one order. But you can go another way - without simulation at all. Portfolio constructor takes close and order records that were generated during the simulation. Since you already have this info, you need to convert your dataframe into an array of order records and just pass to the Portfolio class. For instance, on order of 7724 for 12.94584 (buy side), then an order of 7724 for 283.98 (sell side), then 7739 for 283.41204 (sell side), and so on. |
Beta Was this translation helpful? Give feedback.
@eervin123 the notebook was created by one of the users, I can't really answer the design decisions that were made. Regarding your dataframe with trades, there is an issue you need to solve. If you want to use either from_orders or from_signals, you need to make sure that there is at most one order per bar. At bar 949 you exited at 283.98 and entered at 283.41204, which isn't possible to do with one order. But you can go another way - without simulation at all. Portfolio constructor takes close and order records that were generated during the simulation. Since you already have this info, you need to convert your dataframe into an array of order records and just pass to the Portfolio class…