I understand the "rejecting trades due to insufficient capital" behavior. But I'm seeing WL reject trades even when (I think) I have plenty of extra capital.
I'm writing a portfolio-trading script using WealtScript Override and SetShareSize. I track the portfolio value inside my script, and that value matches the WL portfolio value to the penny.
My script buys a basket of stocks, and I intend to use up all of my capital in buying the basket. However if I tell my script it's starting with $10k, and tell WL it's starting with $10k, WL rejects a bunch of trades. I have to set the WL starting capital to $24k before it accepts all trades.
But if I set the WL starting capital to $24k (while still telling my script it has $10k) and display the equity curve, it shows the Cash value being a near-straight line just over $14k, with ZERO cases of the Cash value dropping below $14k. In other words, it shows I have $14k more capital than I need. I believe that shows that my code is correctly buying exactly enough shares to keep the cash value just above zero, if the WL starting capital matched my script's $10k starting value.
So since my Cash value never drops below $14k, why does WL reject trades with a lower starting account value?
Size:
Color:
It's all about the basis price. See the Wealth-Lab User Guide:
Strategy Window > Backtesting Strategies > 100% of Equity Sizing.
P.S. For Market orders, a PosSizer is available with "Skipped trade solution". Read more about the feature here:
Position OptionsIn the current build, the feature doesn't apply to SetShareSize though, but it's not a Wealth-Lab's limitation - just my design, so it's easily reversible.
Size:
Color:
OK, I think the basis price is basically the fill price, as opposed to the price you used to issue the signal, correct? E.g. you issue a BuyAtMarket on bar X which is filled on bar X+1, and the basis (fill) price is the opening price on bar X+1 instead of the closing price on bar X. So if that fill/basis price is different than expected, you end up spending more of your available cash for your position than you expected?
Then why is it that, when I set the starting capital so NO trades are skipped, it still doesn't show me dipping below my expected level of available cash? Why do I have to set the account value to many thousands of dollars more than WL says I **actually used** ?
See e.g. this equity curve:
With a starting account of $30k, and the script told it has $10k to work with, at no point does my available cash dip below $20k. I've verified that by copying the equity data to a spreadsheet -- the minimum value of available cash is $20026.61. But if the starting account value is less than $24k, it drops trades.
I can just crank up margin to make this go away. But I want to make sure I understand what's really happening here so it doesn't surprise me somehow.
I don't think I can use a PosSizer for this application, since I calculate position sizes based on a varying formula, not just on a percentage of account or whatever.
Size:
Color:
QUOTE:
So if that fill/basis price is different than expected, you end up spending more of your available cash for your position than you expected?
Right.
Based on the
very deterministic cash level at $20K (again $10K below $30K), it sure seems a LOT more likely there's a logical error in your code causing that. In fact, it seems almost obvious to me that you're always telling your script that you're starting with $10K no matter what you set the Starting Capital to. Is it not so?
Size:
Color:
QUOTE:
I don't think I can use a PosSizer for this application, since I calculate position sizes based on a varying formula, not just on a percentage of account or whatever.
PosSizers are more capable than that. A PosSizer like above can adjust the size based on the real market open (including the Ghost bar access in real time for the
Open[bar+1] thing). Give it a size through
SetShareSize, and it could adjust it without playing with margin (which ultimately affects the backtested results).
Size:
Color:
Cone: yes, I'm telling the script it has $10k to work with, while I start WL with $30k. That's intentional. If I tell the script to start with the same amount as I tell WL, I lose trades.
If I set the WL starting capital to e.g. $20k, the available cash in the equity curve "should" be $10k less than when I set the WL capital to $30k -- in other words if I set the WL capital to $20k the available cash should never drop below $10k. It should look just like the equity curve above but shifted down $10k, and I should always have $10k or more unused cash. But instead it drops many trades. Why?
(Oh rats. I just set it to $20k to verify what I saw before, but now I seem to have introduced a mystery runtime error. But I'm sure that's what I saw before.)
Eugene: I'm sizing my positions based on the overall beta of a basket of stocks vs the beta of a hedge, calculated on a bar-by-bar basis. Maybe PosSizers can do that if I give it a SetShareSize? But if I'm calculating the share size, what is the PosSizer doing?? Does it tweak the position size so you don't exceed your available cash? Seems like it would be better for me to understand what WL is doing and write my code to do the right thing instead of relying on a PosSizer to patch up my misunderstanding!
Size:
Color:
I resolved the mystery error and verified that yes, running with $20k starting capital does cause many lost trades. Even though running with $30k capital, as shown above, says I have $20k excess cash. Why is it dropping these trades when I have plenty of cash in my account??
Size:
Color:
if you are buying and selling on the same day (let's say at the close), there's a known bug in wealth-lab that causes it to not take trades as it doesn't correctly increase the available cash for the sell trades. I trade a market neutral strategy where i'm always 100% long and 100% short (so 200% gross exposure), I have to set the leverage factor close to 5 to 1 to force wealth-lab to not miss trades. unfortunately, it's not a priority for them to fix it given other outstanding issues.
Size:
Color:
Interesting. But as far as I know I'm not buying/selling on the same day. I buy at the close of one day, sell at the close of the next day.
Size:
Color:
Oh, I misunderstood you. You meant "buying some stocks, and shorting others" ?
BTW ss161, this strategy of mine is also market-neutral, though I'm hedging with SDS so I can run it in an IRA. Would you be willing to connect and share ideas? I don't see any way to send messages through this forum but you can contact me at fritz at frii dot com. Thanks!
Size:
Color: