- ago
I got unexpected equity sizing values for a signal issued today (Saturday ET) to buy a single symbol at market at next bar. I had option "Use broker reported equity" checked with a BI paper account of ~$1,053,000. These are the position size values I got for running strategy with various equity %'s:

100% : $905,000
95% : $779,973
90% : $669, 289
80% : $486,090
60% : $239,606
40% : $102,809
20% : $32,397

To remove the broker connect from the troubleshooting, I shut down TWS, connected to Dummy Broker, unchecked "Use Broker Reported equity...", restarted WL8, but these values are unchanged for setup equity of $100,000.

The initial values with TWS connect are way off, and I can't seem to get WL8 to use setting for strategy when disconnecting from Broker. Do you have an idea what is could be happening?

0
1,013
Solved
48 Replies

Reply

Bookmark

Sort
- ago
#1
What tool is this, Strategy window or S.Monitor?
Have you checked the position sizing of the strategy, perhaps the starting value comes from user input?
0
- ago
#2
QUOTE:
What tool is this, Strategy window or S.Monitor?

Both but with different results.

The Accounts tab correctly shows that I have cash of 1,053,380.01 in my IB paper account, which WL is connected to. I have two current signals for two symbols, and I have the % Equity set at 50% in SM and SW.

SM: signal is for quantity $1,039,087.01 for each symbol.
SW signal is for quantity $1,970,936 for each symbol

QUOTE:
Have you checked the position sizing of the strategy, perhaps the starting value comes from user input?

There is no user input to size strategy. The only Position Sizing I'm aware of is the % Equity settings in SM and SW, which are set at 50%.
0
Cone8
 ( 26.65% )
- ago
#3
Does the Strategy assign a value to Transaction.Quantity?

QUOTE:
// Like this?
Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);
t.Quantity = something;
0
- ago
#4
no
0
Cone8
 ( 26.65% )
- ago
#5
We're going to have to find what's causing that facility to fail... and after switching to my IB paper account, I think I've found something.. stay tuned.
0
Cone8
 ( 26.65% )
- ago
#6
Found it. Notice how only "Cash" is showing up in the Accounts tool. A request for account info was inadvertently changed to use a "lightweight" method that wasn't returning the account's Buying Power. Fixed for the next IB Provider, Build 7.
0
- ago
#7
QUOTE:
Found it.

I'm glad you found it. I guess I'll have to wait for the update to trade through API, at least for % Equity trades? I can enter paper trade manually into TWS, but then I assume I'll have to manage the trade manually (not through API) until it closes because I don't know that there is a way to sync strategy Active Positions? (I'm assuming that WL8 only process trades based on signals it generates, not by syncing active positions from BI.)
0
Cone8
 ( 26.65% )
- ago
#8
This bug shouldn't hold you back if you want to trade. Just calculate the % of equity size each day and enter it for Fixed Value Sizing.

Example:
If your account is $100K, and you want 10% sizing, just enter $10K Fixed Value. Then repeat the process each day.
0
- ago
#9
Great suggestion. Thank you. Placed it through API and worked fine (got Qty correct).

Look forward to the update!
1
- ago
#10
I am running the latest versions of WL8 (10) and IB extension (8). I am still getting strange calculations for % of equity calculation when running strategy in SM during after-market hours. Paper acct balance is 995K and setting is 50% equity for each of 2 positions. Each position staged has value of 783K. (Expecting ~500K.)

To eliminate the Paper Account as a possible cause, I ran again in a live account with a $500 balance and got the same $783K allocation per position for 50% of equity.

0
- ago
#11
Can you please confirm that this problem with equity sizing is on a bug list to be fixed? I wanted to make sure that WL is aware that this issue still persists (see Post #9 above). despite the "lightweight" fix that was put in IB API B7 (see Post #6 above.)
0
Cone8
 ( 26.65% )
- ago
#12
I confirm that it's working, however in the process of checking, I found that it does not work when the Basis Price is set to the [non-standard] "Market Open next bar".

I can't think of a reason why it shouldn't work for that setting, so for now we'll consider that a bug!
0
- ago
#13
Mystery solved. Thanks.

While we're on the topic, I'd like to understand how the sizing algorithm *should* work. 1. If I place an MOO order with % equity selected and Next Bar, will the algorithm detect the opening price and make changes to the quantity placed (particularly useful in the case of an overnight gap move)?
2. If there is Margin available in the account, will the Equity Sizer use all available Margin or will it use the Margin (1, 1.5, 2, etc.) setting to determine how much margin to use?
0
Cone8
 ( 26.65% )
- ago
#14
QUOTE:
will the algorithm detect the opening price and make changes to the quantity placed (particularly useful in the case of an overnight gap move)?
Definitely not. The predetermined size is sent with the signals and if the account can't handle the order it will probably result in an order error and failed.
0
- ago
#15
Then Market Close This/Next Bar is only meaningful for backtesting results?
0
Cone8
 ( 26.65% )
- ago
#16
Either setting is meaningful. Please see: F1 > Strategy > Strategy Settings > Basis Price. It's covered there and I can't really explain it any better.

Edit - Pay attention to: Important Notes for Market Open Basis, especially -
3. Signal Quantity is always Staged or Placed with the number of shares using the Market Closing price basis.

It turns out that even though the $ signal display is not currently taking into account the broker account value, that changes when the orders are Staged/Placed. The share value of the trade, which is always based on the last closing price, is correctly using broker account value for % Equity sizing when that preference is enabled.

The other part of the trading equation is the Preference: "Use Fractional Shares when Possible". The only broker adapter that supports this at the moment is Alpaca. So you won't get fractional shares with IB (yet).
0
- ago
#17
Thanks, Cone for the doc reference.

QUOTE:
The share value of the trade, which is always based on the last closing price, is correctly using broker account value for % Equity sizing when that preference is enabled.

I placed some trades with IB/TWS outside market hours to test various settings and I confirmed that this is the case.

I realized that live trading does not take into account margin or buying power in sizing trades, only current equity (as named). In order to buy shares using margin I found I could accomplish that by increasing the % of Equity value to buy more shares.

For example, if I am buying two symbols and just wanted to use all my cash, I would enter 50%. If I wanted to use 2x equity (1/2 cash, 1/2 margin loan) for two positions I set the % of Equity to 100% and WL buys twice as many positions of each symbol.



0
- ago
#18
For today's auto trading with IB, the sizing numbers are all over the place. Account equity is $~3,200. I want to trade 2x equity including margin, so I set % equity at 100% for 2 positions.

I ran the strategy multiple times from the SM, and each time got a different sizing number. Note that $$ are correctly getting converted into shares, but the $$ amounts are wrong. Each run result is separated by comma below.

Pos #1 $3,693, $4,785, $3,206, $4,847, $4,813
Pos #2 $3,693, $4,785, $3,206, $4,847, $4,813

The correct sizing would be =< $3,200 for each position.

If I set to Use Closing Price This Bar, I get similar erroneous results, except in shares instead of $$.

If you think this is a bizarre behavior that you haven't seen, then please note that my IB account window no longer shows the equity value since I added a second BI account. It only shows active position values. I wonder if it's related to having 2 IB accounts running in the Accounts Window.

BTW, which data provider is used to get the close price of the Current Bar? Is it the same provider designated for the DataSet that the strategy runs against?
0
Cone8
 ( 26.65% )
- ago
#19
Above, we confirmed the bug that the % of Equity sizing when using Basis "Market Open Next Bar" is based on the simulated equity, always. So it's expected that the value is going to change if your simulation has NSF Positions and doesn't assign Transaction.Weight.

If you want to see the correct sizes for Account Equity (we use the IB Account's Net Liquidation Value), then you need to either:

1. Place the order with the broker. If the Trading Preference for broker account equity is checked, you'll see that the proper size is used (shares x last close).
- or -
2. Use Basis "Market Close This Bar". Frankly, unless there's a good reason not to, you should always use this anyway.

QUOTE:
Is it the same provider designated for the DataSet that the strategy runs against
Yes.
1
- ago
#20
HI Cone,

Thank you for the response and the additional information. I'm not intending to repeat a problem you already know about. However, your explanation made me wonder if you noticed one piece of information in the above post I provided about this problem.

QUOTE:
If I set to Use Closing Price current Bar, I get similar erroneous results, except in shares instead of $$.


In other words, I also tested with Market Close This Bar (because I had the "bug" in mind) and got the same random sizing from one run to another, only in shares instead of dollars. (I can post a run sequence in shares using Market Close This Bar, if that would be helpful.) Unless I didn't completely understand your explanation, this issue does not appear to be limited to selecting Closing Price Next Bar.

Also, My Strategy Backtest Metrics Report does not show any NSF positions, even though I have selected to retain them.

Another new behavior I noted above is the disappearance of the Account Equity data for IB accounts from the Accounts page, once I linked a second IB account at IB. Both accounts automatically showed up the Accounts page after linking. Do you think linking the second account is related to this happening? It hasn't changed for TDA or Tradier, both of which have only one account.
0
Cone8
 ( 26.65% )
- ago
#21
If you're not seeing the equity on the Accounts page, it must have something to do with the linked accounts, so give me some time to link my two IB accounts and then we can directly determine the problem. Thanks.
0
- ago
#22
And the position sizing when This Bar is selected? That also?
0
Cone8
 ( 26.65% )
- ago
#23
I mentioned it in another thread, but I'm not going to be able to link my accounts because each are governed by a different IB entity.

Please give me an update - are you still having a problem with this using IB Extension Build 11?
0
- ago
#24
QUOTE:
are you still having a problem with this using IB Extension Build 11?


Yes, no change.

But your account linking was so you could test the issue that IB does not display account information for two accounts in the same way as it does for one account.



The original topic for this thread was that position sizing as % equity is not working (random results). At one point you indicated it might have something to do with placing trades before market open. That problem started before I had two accounts and still persists. Do you need a refresh on that?
0
Cone8
 ( 26.65% )
- ago
#25
We don't have a way to test multiple accounts with the same login.

It's possible that some changes in Build 12 will affect this, so just give it a try when it's available (this weekend).
0
- ago
#26
OK
0
- ago
#27
QUOTE:
It's possible that some changes in Build 12 will affect this, so just give it a try when it's available


I installed IB B12 and it didn't make any difference in behavior.

1. Position sizing based on Broker Equity still delivers random results for each run
2. The accounts page does not show the same standard information with two accounts as it did with one (see above #24). It also does not show active positions or their value.
0
Cone8
 ( 26.65% )
- ago
#28
In that case we don't have any recourse other than to say that the IB Adapter is not compatible for multiple accounts with a single login.
0
Cone8
 ( 26.65% )
- ago
#29
The frustrating thing about this is that nothing is pointing to a single account in our code. We're subscribing to "accountUpdateMulti" and "positionMulti" endpoints and do not assume a single account.

Do you see any "red" or "yellow" messages from IB in WL8's Log Viewer (Ctrl+L) after logging in?
0
- ago
#30
QUOTE:
Do you see any "red" or "yellow" messages from IB in WL8's Log Viewer (Ctrl+L) after logging in?

No

0
- ago
#31
QUOTE:
we don't have any recourse other than to say that the IB Adapter is not compatible for multiple accounts with a single login.

The display of account information is not, IMO, critical.

What I am more concerned about (as a practical matter) is that the Equity Sizing based on Broker Balances is still not working. You are not attributing this to the two-account setup as well, are you?

In Post #19 above you acknowledged there was a bug with Equity Sizing. In my testing, (subsequent post) I noted that this problem was not being caused by setting price calculation to Next Open as it occurs as well when set to Last Close.

Have you been able to duplicate this? Can you tell me what the status of resolving this is? Is it on a list to be fixed? Am I the only one to report this?
0
Cone8
 ( 26.65% )
- ago
#32
QUOTE:
The display of account information is not, IMO, critical.
If it's not displayed, it's because we're not receiving it. So it's critical if you want the sizing to work.

The bug with using the broker account value with open price basis was fixed in Build 15. But there's no way it's going to work for you if the broker account information isn't coming through.

You may be the only one using linked accounts. I'm not denying there's a problem, it's just that we have no way to test or even observe it on a development machine.
0
- ago
#33
Then multi account support is limited, at least for IB?

Does multi account work completely for TDA?
0
Cone8
 ( 26.65% )
- ago
#34
QUOTE:
Then multi account support is limited, at least for IB? Does multi account work completely for TDA?
We have no way to know x 2.

In both cases, the adapters are written to support multiple accounts. But we cannot test this since we don't have multiple accounts at these brokers. But I'm repeating myself.
0
- ago
#35
Do you plan to set up minimally funded multiple accounts with supported brokers as a testbed.?
0
Cone8
 ( 26.65% )
- ago
#36
No.

But let me ask, do you see all of your account IDs in the dropdown list?
0
- ago
#37
I presume you are referring to the Order Manager page. Yes, they do. At the top "Account" dropdown, and also in the signal block "Account" dropdown.

Each account shows up separately on the Accounts page, under Interactive Brokers.

0
Cone8
 ( 26.65% )
- ago
#38
Try again with IB Build 13.

There will be at least one more message added to the Log Viewer containing a delimited list of the account IDs. I would be interested to know if there is a space after the comma separating the account numbers.

If there are any "[account ID] not found" errors in the Log Viewer, let me know.

Incidentally, you're not seeing the 2 Positions in each account because the you turned off the view for Interactive Brokers - the "eye" icon is disabled.
0
- ago
#39


Note that with this build there is a new issue. It is not reporting both account numbers, attributing positions in both accounts to one account.



QUOTE:
Incidentally, you're not seeing the 2 Positions in each account because the you turned off the view for Interactive Brokers - the "eye" icon is disabled.


Thanks for noticing that. It is not showing current values of positions.



QUOTE:
I would be interested to know if there is a space after the comma separating the account numbers.


If it's not clear from the image, there is no space after the comma between account numbers. There is another comma after the second account number followed by chars that look like dashes, if that's relevant.
0
Cone8
 ( 26.65% )
- ago
#40
Great! Thanks for posting the Log Viewer messages. I think I can solve that now.

Re: Position Value
You have to check "Turn on Streaming Last Price Updates" to get the current values.
0
- ago
#41
QUOTE:
You have to check "Turn on Streaming Last Price Updates" to get the current values.


I did that and clicked "Request Updates..." but still no data. I don't think this is a recent issue. I noticed a while ago.
0
Cone8
 ( 26.65% )
- ago
#42
I don't know, this is pretty recent - (now) -



You only get an update on the next trade / tick. So if the instruments don't trade often, it may take minutes (or more) before you see an update.

Edit -
Incidentally, the Position Summary under the Cash amounts is garbage. I'm not sure why..yet.
0
- ago
#43
QUOTE:
Great! Thanks for posting the Log Viewer messages. I think I can solve that now.

Which issue(s) are you referring to that you think you can fix based on what I sent?
0
Cone8
 ( 26.65% )
- ago
#44
The account equity and cash information.
0
- ago
#45
Do you think that could resolve the Equity Sizing issue as well?
0
Cone8
 ( 26.65% )
- ago
#46
Of course. The problem isn't the sizing function, it's not having the equity to size with. If you get the account value with Build 14, the sizing will work.

Build 14 is available... now!
0
Best Answer
- ago
#47
Well, @Cone, looks like you nailed it!



QUOTE:
If you get the account value with Build 14, the sizing will work.

And equity sizing is working correctly now, as you predicted. Thank you very much!!!

Does this finding give you any more confidence to predict whether TDA is likely to work with multiple accounts?
1
Cone8
 ( 26.65% )
- ago
#48
TD and IB and completely different brokers and APIs, but nothing is assumed for a single account. Same story - it should work, but we can't test it.
0

Reply

Bookmark

Sort