How is Avg Entry Price calculated when using from_orders function?
#462
Unanswered
jejebelfort
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to backtest a long-short portfolio where I specify the target weights for different dates.
I am using the following command:
pf = vbt.Portfolio.from_orders(close=prices[size_pct.columns], size=tgt_wgts, group_by=True, lock_cash=True, allow_partial=False, size_type='targetpercent', direction='both', fees=0.0, cash_sharing=True, init_cash=10000)When checking trades for a specific symbol
XYZ, I realize that theAvg Entry priceis varying for the sameEntry TimestampandColumn(symbol):I would be expecting a same Entry Price for this symbol
XYZ. How can I force it to be equal to the input close price on that date2021-01-31 01:00:00that I provided in the first inputclose=?PS: I realized there is also a parameter
price=, but even settingprice=prices[size_pct.columns]it doesn't give me the weights I am looking for and I still observe a different Avg entry price.PPS: Could you also tell me whether my other parameters are correct (especially
lock_cash=Trueandallow_partial=Falsegiven that I want a simple portfolio long short, like the below:so that
abs(weights)=1in order to have the full amount of cash (init_cash=10000) allocated to thosesymsgiven the input prices (no slippage, no fees), say:prices=[1,2,3,4].In that case I am expecting the allocation to be (in number of asset, not USD):
alloc=np.array([-0.25,-0.25,0.2,0.3])*10000/np.array([1,2,3,4])=[-2500. -1250. 666.66666667 750.]Beta Was this translation helpful? Give feedback.
All reactions