what DEFAULT means for JTable renderers

1) The “default” in getDefaultRenderer() means “class-based”. In each jtable, there’s at most ONE class-based renderer for each class. However, multiple classes (say Price column in double, and Qty column in integer) can share the same class-based renderer.

2) The “default” in DefaultTableCellRenderer.java doesn’t mean “class-based”. It means …. “render for all classes”, kind of render of last resort (Sounds like lender of last resort:)

1b) myjtable.getDefaultRenderer(Object.class) would normally return an instance of DefaultTableCellRenderer.java. This call looks up the class-based renderer for Object.java — the last-resort class-based renderer, which is typically DefaultTableCellRenderer.java.

most basic mkt-data feeds to a real spot/forward FX dealer (ML

Top 3 feed providers — Reuters, Dow Jones, Bloomberg

#1 type of live feed is interest rate in major currencies.

— spot dealer
Live spot prices
Interest rates (probably short term) in each currency.

— forward dealer
Live forward prices
Short term lending rates (money markets) in each currency
Longer term lending rates in each currency

non-trivial FX jargon

? customer order vs non-customer order
bank stream
executable quote
Non-deliverable forwards
repo vs FX swap vs currency swap (x-currency IRS)
rolling forward
T/N, O/N, S/N
run-through (forwards market)
direct quotation, indirect quotation — http://en.wikipedia.org/wiki/Exchange_rate
institutional client vs corporate client
banks vs dealers
volatility smile/skew in FX vs equities
relation between Libor rates and FX forward rates
difference between cross-currency IRS and regular IRS

liquidity providers — dealer banks and some hedge funds. Liquidity consumers include small banks and corporations.

relationship-based vs anonymous dealing platforms — Reuters conversational dealing — 2 counter-parties know the identity of other. Note EBS is anonymous. FXAll started as purely relationship-based, later added anonymous platform.

FX pricer #1 short-term driver — 2 IR of the ccy pair

(See also blog on forward FX rate formula.)

For both spot dealer and forward dealer (see separate blog post), interest rates (both short and long term IR, both spot IR and forward IR) are the most important input. Unlike a buy-side (HF…) trader, a dealer typically gets a lot of RFQ during the day and must watch the live interest rates.

Beside IR, All the other inputs to FX pricing engines are probably for different purposes.

A veteran once told me “FX involve 2 interest rates; equity involves dividends. Roughly equal in complexity” but I believe eq options are more complex, involving volatility, repo (supposed to compensate for PCP imperfections?) in additional to IR + dividend.


http://www.investopedia.com/articles/basics/04/050704.asp gave 6 factors affecting FX rates. I feel interest rate is the only short term live market data.

y does yield follow libor rates@@

Q: When interest rates (libor or T or others) rises, why does yield rise?

I used to think yield reflects credit quality. I think that’s still correct, but that’s a static “snapshot” view — explaining different yields of 2 bonds at a point in time.

For now, focus on one particular bond. When interests rise, yield does rise but why? Remember yield is a discounting device, so why do traders discount the future payouts more deeply? Here’s my answer.

First, ignore credit risk and look at a $1000 T zero maturing in 12 months. Say we used to discount the payout by 201bp but now interest rate is higher for similar maturities in Libor and Treasury markets. Sellers of this zero would each discount the payout at 222bp. If you stick to 201bp, then you create arbitrage opportuniuty within this particular market alone. Therefore all sellers of this zero all advertize at very similar prices.

Q: What if there are only 3 big sellers in the market and we collude to keep our price high at 201bp? Crucially, to avoid arbitrage, bid yield has to be slightly higher at 202bp.

%%A: arbitrager can BUY 12-month libor (==a zero bond) at a higher yield of 300bp, and hit our bids at 202bp. There’s an arbitrage linkd between them.

%%A: arbitrager can BUY a mix of Treasuries of 6-month and 2-year, both of which have higher yields above 250bp and hit out bids at 202bp. There’s a arbitrage link across the maturities.

Effectively inflation is rising meaning future payouts getting “cheaper”. If you don’t discount future payouts, then people will see you are pricing your cash flow unfairly.

In the end, it’s a matter of valuation. If you still discount your coupon payouts at the old 201bp then you over-value your bond. Consequence is arbitrage. If competing sellers undersell, then you can’t sell. If you monopolize this market and also bid around that 201bp, then your bid will get hit due to arbitrage using similar instruments.

non-trivial layout – swing ^ dotnet

In Swing, The lazy way to achieve precise layout is subpanels, but memory-heavy. If you use multiple frames, the number of subpanels can multiply.

The memory-wise solution is layout manager wizardry. GridBag is the most complex, impractical according to some. Microsoft has many more layout features, including xaml. Winforms uses anchorage.

I feel the wpf layout panel is like a panel with a specific layout manager … I feel it works better than swing. “Your chosen container determines the layout”, said one wpf book.

Netbeans offers layout assistance, but is still way behind Microsoft solutions.

3 basic value-add in the ECN business model

An FX dealer bank’s system usually interfaces with EBS, Reuters, Bloomberg, FXAll, Currenex, Hotspot … Between any 2 of these, there’re often competing features.

Feature 1: execution. order forwarding to dealers. Actual execution is at the dealer bank after the Last-Look.
 Remember TMS and FXAll.

I feel execution is the #1 (but not the only[3]) value-add of ECN. A slow ECN can also aggregate a lot of quotes. If no client find the quotes competitive then no trade.

[3] Execution isn’t the only value-add. In this huge ecosystem, there are many players selling nothing but data — evaluation prices, recommendations, research, news feed

Feature 2: quote aggregation. depth of market. This service can be “sold” by itself. Quotes have to be fast to be useful.

2b: enable 2-sided market makers to size up a market and then make a market. If the ECN doesn’t offer execution, then clients can contact the market maker directly, just like how I use kayak.com
2c: price discovery

Feature 3: RFQ, RFS(stream)

Fw: milestoning vs log table

Thanks for sharing your implementation. I agree some apps may need a log of user activity. A log table.

Milestone is probably designed for change-history. By the way I’m not a big fan of milestone. It has many drawbacks – unenforceable data rules, manual updates, foreign key, hibernate, data corrections …

stack to heap trend in languages

  • I guess you seldom see malloc() and free() in business applications. I have seen a number of c applications but didn’t notice them. However, how does c pointers deal with automatic destruction of the objects they reference? I guess all such objects are declared and used in the same scope, never declared in an inner func and used in an outer func?
  • C++ biz apps use lots of new(), but by default, if you don’t call new() or malloc(), C++ uses the stack and global area. In terms of language support and encouragement, stack is still easier to use than heap in C++. I consider C++ as a transition between C and newer languages.
  • STL seems to be mostly heap, to support expansion
  • Java uses the heap more than the stack. Every object is on the heap. Memory leak becomes too likely so java had to provide garbage collector.
Conclusion: c -> c++ -> STL -> java, I see less stack and more heap usage. However, Stroustup pointed out the performance advantage of stack over heap.

y JMS session is Single-Threaded

1 session – 1 transaction.

How about database connection. 1 connection – 1 private memory space in the server to hold transaction data, so no multiple concurrent transaction. Even a select is part of a transaction, if you recall the isolation levels (repeatable read…) Usually, the same connection is not used in multiple concurrent threads, but no system enforcement.

How does any JMS system enforce the single-threaded rule? I doubt there’s any. If you break the rule, then result is perhaps similar to the c++ “undefined behavior”.

Note a Connection can be shared by threads, but a Session can’t. The java tutorial says “You use a connection to create one or more sessions.” Additionally, in the flow diagram anything upstream is thread-safe; anything downstream is single-threaded.

connFactory -> Conn -> Session -> producer/consumers

c++^realtimeJVM for trading

Java might outperform c++ sometimes, but java performance is not consistent or controllable due to GC jitters — #1 motivation behind real time jvm.

IBM realtime jvm limits GC frequency so the GC may struggle to keep up with the demand, and heap gets bigger than in Sun jvm.

Sun realtime jvm requires some code change.

Some people feel that to benefit from real time jvm, you must code very carefully … why not use c++. C++ is the incumbent in low-latency systems.

Market-facing gateways — 1) order execution (FIX or custom), and 2) market data feed — still use c++ primarily for another reason – gateway API is often in c++.

tibrv-CM ^JMS

[[ rv concepts ]] has a concise comparison. A few highlights on CM:

(CM is one of the most important RV use cases in trading.)

* A producer sends a message to consumers directly (peer to peer, decentralized). The producer stores the message until each consumer has acknowledged receipt.

**Note the rv daemon is not a central server. There is usually one daemon on each host. These function a bit like cisco routers in a network. They don’t store or retry messages.

**I think p2p is a defining feature of rv (not only CM) relative to JMS.

* Disk failure on a peer host computer affects only the messages that its programs produce or consume. However, disk mirroring (often done on jms servers) for each individual peer is often impractical.

basics – editable JComboBox

Editable combo box fires an event
1) when the user chooses an item from the menu and
2) when the user types Enter.
3) How about fire-as-you-type, on document change. Document is the model behind the text input editor. You need a DocumentListener —

JTextComponent tc = (JTextComponent) combo.getEditor().getEditorComponent(); // returns a text component just like the one behind a text field/area

See http://stackoverflow.com/questions/1252698/how-can-i-know-when-the-text-of-an-editable-jcombobox-has-been-changed

Warning — menu remains unchanged when the user enters a value into the combo box. If you want, you can easily write an action listener that adds a new item to the combo box’s menu each time the user types in a unique value. This requires a MutableComboBoxModel.

swingWorker doInBackground() — basic tips

1) for a novice, it’s a practical defensive practice to catch Throwable in this method, otherwise the exception might be hidden somewhere.
2) if nothing to return, then Void is ok.
3) this method always runs on a non-EDT thread, so the assert helps document that.

public Void doInBackground(){
try {
// time-consuming scan
scanTables(this.command, this.tagLine);
} catch (Throwable e) {
return null;

a holder of JComponent singletons

package updatable.TextPane;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.JComponent;
* In most swing apps, there are a fixed number of jcomponent objects, effectively singletons.
* Many of them are accessed from multiple “client” classes. Sometimes you can’t pass them as arguments,
* therefore many become fields of the client classes, which is messy.

* This class holds 1 or more singleton jcomponents. Helps you avoid keeping a lot of fields.
public class JCompSingletons {
                static private final Map mixed = new ConcurrentHashMap();
                static public void add(String s, JComponent c,
                                                Class type) {
                                if (!type.isInstance(c)) throw new IllegalArgumentException(“wrong type specified”);
                                mixed.put(s, (T) c);
                static public T get(String key, Class type) {
                                JComponent ret = mixed.get(key);
                                if (!type.isInstance(ret)) throw new IllegalArgumentException(“wrong type specified”);
                                return (T) ret;

repos intuitively: resembles a pawn shop

Borrower (“seller”) needs quick cash, so she deposits her grandma’s necklace + IBM shares + 30Y T bonds .. with the lender i.e. buyer of the necklace. Unlike pawn shops, the 2 sides agree in advance to return the necklace “tomorrow”.

Main benefit to borrowers — repo rate is cheaper than borrowing from a bank.

haircut – the (money) lender often demands a haircut. Instead of lending $100m cash for a $100m collateral, he only hands out $99m.

requester – is usually the borrower. She needs money so she must compromise and accept the lender’s demand.

trader – is usually the borrower. Often a buy-side, who buys the security and needs money to pay for it. (The repo seller could be considered a trader too.)

Repo maturity is 1 day to 3M. Strictly a money market instrument.

Common collateral for most repos — Government securities are the main collateral for most repos, along with agency securities, mortgage-backed securities, and other money market instruments.

For every repo, someone has a “reverse-repo” position. In every repo deal, there’s a borrower and a lender; there’s a repo position on one side and a reverse-repo position on the other side of the fence.

Is repo part of credit business or rates business? Depends on the underlier. Part of the repo business is credit. Compare an ECN – can trade Treasuries and credit bonds.

UChicago Jeff’s assignment question is the most detailed numerical repo illustration I know of. Another good intro is http://thismatter.com/money/bonds/types/money-market-instruments/repos.htm

table cell editor^renderer, briefly

Compared to TCR, TCE needs to do more events such as keyboard/mouse.

Customizing TCE is more work than TCR. TCR only requires you to override 1 method — getXXXComponent(). TCE needs a 2nd — getCellEditorValue(), which is invoked during the event handler stopCellEditing(). This getCellEditorValue() returns the value from the cell editor object, to be injected into setValueAt().

A customized TCR/TCE can both target a data type (like Boolean) or a particular TableColumn, which is most practical in trading.

topFrame.setVisible() on EDT@@


I find it ok to ignore the swing tutorial advice, and call setVisible() on the main thread, without invokeLater(). I don’t think we violate the single-threaded rule — Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread. A Swing component that’s a top-level window is realized by having one of these methods invoked on it: setVisible(true), show(), or (this might surprise you) pack().

bridging over c# and java – solutions

Web service is a common solution in BoA, GS and Citi. MOM probably supports a larger volume (but a popular website supports large volume too.) MOM adds development complexity — C# need 2 threads

– 1 thread sends request
– another thread blocks for response. In Neo, response could take a while.
– this is typical request/response, probably using initiator’s mailbox and tmp queue

In Neo, Java can also server-push updates (triggered by benchmark price change), so one-way web service is insufficient.

emulate join – conflict with Yang

* U don’t like jobs without challenge!
* This job keeps you overclocked.
* adversities will grow you stronger.
* Positive attitude is not easy but will protect you, strengthen you, grow you, ..
* Such design discussions are normal and healthy
* You now see proof that other people (experienced app managers) do see values in the other design — unit of work, multi-threaded,
rerunnable, why something didn’t pass, more detailed logging …
* Take it as a challenge.
* more scalable, since u can easily add another app server, but not another database server.
* avoid locking up AM table for x minutes, and blocking out other spid. However, any time a query runs slowly, you are in the same
* less load on db cpu
* java classes are reusable in future projects.

* I fully agree — the more flexibility and control required, the more Java shines. There are situations when you want to emulate
the SQL join.
** java design supports more testing, more asserts
** if you want to report on invalid cusips absent from Product table, then you need another query, whereas row-by-row handles it
** i agree if u want to log why a lot is skipped due to funding date, join must not mention that funding date condition. java is
more flexible
** to support peg or AAG, you may need a table other than Lot. u may need another query. this might be easier to handle in java.
** if u emulate the join you can force a join order and force an index
** I did want to put SIPayouts ident into Lot table. Hard with bulk insert.
** more choke points possible if you process row by row. Choke points are good for control.
** rerun — if u want intelligent rerun, then row-by-row offers more possibilities

c++ function names – 4-word, 3-word, 2-word

C++ function names are usually 1 word, i.e. 1 word before the “()”. There are exceptions, and all of them critical.

operator-overloads are special functions that always starts with “operator”. Trust me — “operator” is part of the function name. These are 2-word, 3-word function names. One of the longest is qq/ operator const char * () /

I don’t know if you can write

operator const vector ()

initiator’s mailbox — a simple MOM model

An overloaded server has a long queue of big queries to service. Say average 5 seconds/query times 2,000 queries in queue. Initiator (eg GUI) should simply send the request to MOM broker and disappear — no tmp queue. Server gets to this query, returns “value” to the broker. Broker should keep the value in the initiator’s private mailbox.

Initiator have 2 ways to check the mailbox.
* onMessage — server push, triggered by incoming connection. However, if onMessage() is a long method, will broker (separate jvm) block waiting for it?
* poll — client pull. Broker could be overwhelmed by too many clients.

The initiator’s mailbox can be a dynamic queue.

For DQ, see http://tim.oreilly.com/pub/a/onjava/2007/04/10/designing-messaging-applications-with-temporary-queues.html

commodity^IR^FX interaction illustated

When oil, crops (and gold) appreciate against USD, the objective and rational Treasury bond buyers have to discount the cash “flows” deeper [1,2]. In other words, buyers are willing to pay less for those little papers known as coupons. Sellers reluctantly follow.

Commodity (and gold) prices can also rise due to USD depreciation.

QE2 in the US but not Eurozone ==> USD depreciation against Euro and other currencies =?=> commodities appreciation ==> T yields rise. Each cause-effect in the chain reaction is “one of the factors”.

Now, magnitude of this so-called yield shift depends on how important commodities are to an economy. Is it 3% of the economy or 30% of the economy?

I feel basic commodity prices are a major contributing factor beneath the consumer price index.

[1] “Flows” are the shorthand for the multiple future cash flows of any bond, except zeros.

callback objects and func ptr: java^C++

Java has no func ptr. Method objects are sometimes used instead, but anonymous classes are more common.

in C/C++, func pointers are widely used to meet “callback” requirements. Java has a few callback solutions but under many names
* lambda
* observer/listener
* event handler
* command pattern

Func ptr is closer to the metal, but less object oriented.

Boost has a Boost.Function module for callback.