Re: Strategies with multiple securities

237 views
Skip to first unread message

nonlinear

unread,
Jun 14, 2012, 9:05:54 AM6/14/12
to jbook...@googlegroups.com
Hello Brad, and welcome to the project.

JBT does support trading multiple securities simultaneously. However, the relationship between a strategy and a security is 1 to 1. That is, any given strategy is associated with a single security. If you intend to trade multiple securities, simply create a new strategy class for each one. Note also that multiple strategies can trade the same security as well. For example, you can set up the following strategies:

es1, es2, es3: will use the ES exchange book and will trade ES
ym1, ym2, ym3: will use the YM exchange book and will trade YM
eur-us-1, eur-us-2, eur-us-3: will use the EUR.USD cash book and will trade the EUR.USD cash.

All 9 strategies can run at the same time within the same JBT instance, totally independently.


On Thursday, June 14, 2012 1:19:12 AM UTC-4, Brad wrote:
Hi Guys,

First of all, congrats on a what appears to be a very polished piece of software.

I've taken a look through the source and from what I can tell, strategies are restricted to monitoring and trading a single security, based on the order book for that same security. Is this the case?

 I typically trade intra and interday statarb strategies, monitoring and trading two or more securities. I saw there was a sister project called jarbitrager that was built specifically for pair trading, but I understand this has been abandoned in favor of JBT. I also need to see market depth for my strategies (some illiquid securities), and I think jarbitrager provides top of the book only.....

So i guess my questions are:
- Does JBT only support only single securities for monitoring/trading?
- If so, how baked into the architecture is that assumption? (i.e. is it feasible that I could modify it - I'm an okay programmer). I don't need backtesting/optimization support, only forward test/trade.

Thanks

nonlinear

unread,
Jun 14, 2012, 9:54:13 AM6/14/12
to jbook...@googlegroups.com
Ok, I see now. Yes, pair trading is not easily accomodated in JBookTrader. JArbitrager is specifically designed for it, but it has not been maintained. JArbitrager has the same implementation of the exchange book as JBooktrader. For example, for ES, it maintains 10 price levels, which is the depth of the ES book available from IB.

On Thursday, June 14, 2012 9:26:38 AM UTC-4, Brad wrote:
Hi nonlinear,

Thanks for the quick response. I maybe not have been entirely clear in my original post. The strategies I am looking to implement rely on the relationship between multiple securities to determine position sizing. The positions themselves also relate to multiple securities. e.g:

- Monitor the price of Stock A and Stock B
- When the price of Stock A is greater than 10 times the price of Stock B, sell X units of Stock A and buy Y units of Stock B

This is not a realistic example, but it highlights the type of functionality required. I may be missing something, but I can't see how this can be done using multiple strategies, as each strategy's indicators seem to  reference only the single underlying security and is only able to trade that same underlying security.

Cheers

Brad

unread,
Jun 14, 2012, 10:21:11 AM6/14/12
to jbook...@googlegroups.com
Understood. Given JArbitrager hasn't been maintained, I'd prefer to focus on JBT. I've taken a closer look at the source to see how challenging it might be to implement. As is always the case, I'm sure it will be much more work than it initially appears, but it seems possible.

The market subscriptions and indicator side of things seems pretty straight forward, the more difficult part I imagine would be order management. I'm still trying to wrap my head around the execution flow for orders, but my my initial look it seems that at present, orders are synchronous between strategies. By that, I mean that if execution is currently pending for one strategy, then no other strategy can submit an order. Is my understanding correct on that?

My end goal would be to be able to assign an arbitrary number of securities for each strategy, although given IB limitations, a maximum of three I guess, unless I added the ability to subscribe to top of the book data only, which require new indicator types etc. etc.

I'll keep looking through the source, but any implementation advice on just the multiple security side of things would be greatly appreciated.

ps. well done on the coding. Despite not having any diagrams or code docs, I've found it remarkably easy to follow the program logic and design. Quite a rarity for me when trying to understand someone else's code ;)

Judson Wilson

unread,
Jun 14, 2012, 12:53:46 PM6/14/12
to jbook...@googlegroups.com
I have looked into it before. The single instrument paradigm is pretty deep. However, there is very good use of the object-oriented model, so it is possible. I rank it as "medium complexity / effort required".

Areas where I got hung up:
- GUI - you have to figure out what you want the gui to do, and you will need to do at least SOME re-programming in this regard, which isn't fun if you don't know how it works. My thoughts were to ditch the multiple strategies thing and make the program work on one single strategy, and use each row in the main window to track each instrument.  But still, what do you do for indicators that are based on multiple instruments? Or do you make a rule that indicators can only depend on a single instrument?
- Backtest, etc - apparently you don't care about this, but deciding how to store data, etc, for multiple instruments. Also, how to present the data graphically?
- Error Handling, etc - Decisions on what to do when there is some kind of market data / trade problem only get more complicated when there are more instruments.

I hope this gives you an idea of what is involved.  If you do decide to give it a go, make sure you learn how to use Mercurial / hg  version control - it will make your life a lot simpler.

- Judson

On Wed, Jun 13, 2012 at 10:19 PM, Brad <bra...@gmail.com> wrote:
Hi Guys,

First of all, congrats on a what appears to be a very polished piece of software.

I've taken a look through the source and from what I can tell, strategies are restricted to monitoring and trading a single security, based on the order book for that same security. Is this the case?

 I typically trade intra and interday statarb strategies, monitoring and trading two or more securities. I saw there was a sister project called jarbitrager that was built specifically for pair trading, but I understand this has been abandoned in favor of JBT. I also need to see market depth for my strategies (some illiquid securities), and I think jarbitrager provides top of the book only.....

So i guess my questions are:
- Does JBT only support only single securities for monitoring/trading?
- If so, how baked into the architecture is that assumption? (i.e. is it feasible that I could modify it - I'm an okay programmer). I don't need backtesting/optimization support, only forward test/trade.

Thanks

--
You received this message because you are subscribed to the Google Groups "JBookTrader" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jbooktrader/-/cTrfX4vFFagJ.
To post to this group, send email to jbook...@googlegroups.com.
To unsubscribe from this group, send email to jbooktrader...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jbooktrader?hl=en.

Alpha

unread,
Jun 14, 2012, 1:15:16 PM6/14/12
to jbook...@googlegroups.com
this is indeed a classic problem for building trading systems. Majority of platforms out there have this issue.

It is simple to build a system based on one instrument; as the majority of strategies are indeed based on one instrument. It's the 80/20 rule. You will end up spending 80% of the time and effort to address the 20% of unique situations.

I suggest a solution where you can use the existing JBT system that is based on one instrument; and within the code create additional instrument objects and indicators. This way you can handle as many instruments in the strategy as you want.

as for market data events; you can piggy back on the primary instrument events to trigger your trading logic. When you get an event; query the other instruments for latest market data.

Brad

unread,
Jun 14, 2012, 1:20:26 PM6/14/12
to jbook...@googlegroups.com
Hi Judson,

Thanks for the additional color. The design does indeed seem quite clean. GUI wise, I don't see any major issues. Presentation of the strategy related parameters are the most relevant. Watching security specific prices etc. don't concern me much. I'd be much more inclined to add a console window and log much more detail. I guess the simplest thing would be to maintain the current layout and just display the multiple securites values comma separated in symbol, book, price etc columns.

I actually added the multiple security functionality this afternoon (Asia time) from an indicator monitoring perspective and adjusted to gui to some degree (show all securities tabbed in the strategy info dialog etc.). It seems to work okay. I'm not sure if I chose the most appropriate architecture, but I just wanted to get a feel for how tough it might be. As with any automated trading system, the real difficulty I think would lie in the order management. Since there are multiple securities, there is a need to keep track of partial executions etc, ideally with unwind functionality on failed legs and the like.

With respect to version control, what did you mean exactly? I currently use TortoiseSVN and just created a private online repository for this, based off the most recently released version.

Judson Wilson

unread,
Jun 14, 2012, 1:36:48 PM6/14/12
to jbook...@googlegroups.com


With respect to version control, what did you mean exactly? I currently use TortoiseSVN and just created a private online repository for this, based off the most recently released version.

That works. I recommend hg or git over SVN, but as long as you are using _something_ you should be ok.


 
--
You received this message because you are subscribed to the Google Groups "JBookTrader" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jbooktrader/-/7UFPNlyfXbEJ.

Eugene Kononov

unread,
Jun 14, 2012, 3:55:17 PM6/14/12
to jbook...@googlegroups.com
Ok, here are some comments for clarification:

1. JArbitrager is no longer maintained, but it was left in a solid state. Multiple people have tested it. I seem to remember that one person mentioned order handling issue. The reason I abandoned JArbitrager development is simply because I couldn't come up with any profitable strategies. I forward-tested some of the ES-SPY pair strategies using it, and found that these two markets are too efficient. The spread between these two instruments is very small and very short-lived, so after the transaction costs, there is nothing left on the table. However, it sounds like you are thinking of perhaps some illiquid securities where perhaps there is more arbitrage opportunities. Since JArbitrager already makes it possible to backtest, forward test, optimize, and trade pair strategies, my recommendation is to make it a starring point for your system.

2. In both JBookTrader and JArbitrager, charting is used for post-trade analysis. This makes it a good tool to see if your strategy is performing as designed. A discretionary trader watches the chart, and then trades. An automated trader with JBT and JA starts it in the beginning of the day, lets it run, and looks at the performance charts at the end of the day. In JArbitrager, charting reflects both instruments, so again you'd be better of with JA.

3. Partial executions are handled in both JBT and JA. However, both platforms support only market orders, so handling partial executions is trivial: we are waiting for the orders to be fully filled, which is with IB typically takes between 100 and 300 milliseconds.  

4. Yes, there is an "order pending" flag in JBT which blocks other strategies from placing their trades until the pending order is filled. In JA, this flag is "bi-legged", i.e. it blocks trading until the pending orders in both securities in a pair have been filled.

Eugene.



--
You received this message because you are subscribed to the Google Groups "JBookTrader" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jbooktrader/-/7UFPNlyfXbEJ.

Brad

unread,
Jun 15, 2012, 1:54:48 AM6/15/12
to jbook...@googlegroups.com
Many thanks Eugene, this is very helpful.

1. The key reason I began looking at JBT rather than JArbitrager is the book level functionality. While the underlying securities for my strategies have okay liquidity, the sizes I trade are larger than the top of book bid/ask sizes, and so I need to be able to see the full book to understand likely average fill prices. The book data is also an input to determining appropriate entry points. Do you feel it's likely going to be easier to add multi security capability to JBT, or order book  capability to JArbitrager? 

2. Totally agree. Monitoring and post-trade analysis are crucial. Regardless of which platform I use, I'll be linking it to my existing DB to record positions, execution etc. I already have analytics in place for this, so the inbuilt charting etc is less of an issue. I also do my strategy development and testing primarily in R, which is why I'm not focused on the backtesting and optimization side of things.

3. Yes, if only market orders, then no real drama here. In the long run, I'd intend to add limit order functionality, which complicates things immensely when dealing with multiple legs that are conditional on each other. 

My intention is to develop a much more comprehensive system over the longer term, so although I'm only looking to add multiple securities initially, the plan is to add a great deal more in the future. To this end, I'm looking for a good java base to begin from.

Brad
Reply all
Reply to author
Forward
0 new messages