2 “prices” in a repo contract

The moment 2 parties agree on a repo, they finalize 2 numbers
– The Price is the amount paid for the security at the “opening” leg
– The Rate is the interest to be paid at the “closing” leg

For a common repo, the opening leg is a spot trade, so price is comparable to the market price of the security, but negotiable if it's illiquid.

A repo can also be forward-start. Price would be a forward price.

Advertisements

tunnel^bubble routed events, first look

Routed events have a bit of theory behind it. Routing theory perhaps?

One of the (top 3?) essential jobs of xaml is linking up the GUI event handlers. These event handlers are essential and found in every GUI toolkit. WPF event handlers are often implemented as instance methods in the xaml class. The xaml xml can specify a handler method by unqualified method name like a bare-word.

A bit of history on the “event” concept. In swing and other GUI, an event instance is a single occurrence of a … say a button click (or mouse-over or a special key combination). In dotnet, an event is conceptually a (usually non-static) field holding a functor. In GUI, such an event often points to an instance method of the xaml class behind the xaml. So I feel in a dotnet gui an event in a xaml screen is like “a specific type of user action”, like a click on ButtonA. WPF uses a supercharged kind of event, built on top of the CLR event. We are talking about routed event.

To understand routed event, we better bear in mind that a xaml defines a screen, built with a tree of visuals in a containment hierarchy. Such a hierarchy is also essential in Swing.

When a user action happens, the WPF “Hollywood” typically raises 2 routed events — 1) a tunneling version then 2) a bubbling version. Tunneling events are named Preview_*, and designed to fire before the bubbling event. [[illustrated wpf]] shows a simple example. Upon a click, first the tunnel event hits outer container, then the inner image, and then a second event, the bubble event, hits the inner image then the outer container. Both the inner and outer visual object define event handlers for the click, adding up to 4 event handler methods in the code behind. Therefore we we see 4 log messages.

This is all standard behavior of “Hollywood”. It provides flexibility that you can opt out. You can disable any of the 4 event handlers, and an earlier tunneling event handler can stop the propagation of the tunneling event (ditto bubble), but often you want to give outermost container the first chance to react, before the children. “This gives the container the power to see an event before its children“, as someone pointed out on http://stackoverflow.com/questions/1107922/wpf-routed-events-tunneling-and-bubbling. Here’s my sound byte –

    In the preview (tunneling) phase, container gets the preview before the children

2 technical motivations for inventing WPF commanding

When WPF creators came up with the command infrastructure, they had some competing designs, motivations, trade-off etc. http://msdn.microsoft.com/en-us/library/ms752308.aspx pointed out 2 major driving forces. Here’s my wording, not the original wording

1) 1:Multiple
2) enable/disable the Multiple CommandSources at once.

Various authors also touched on these 2 concepts among other concepts. I find it extremely insightful to single out these 2 primary purposes.

Let me elaborate a bit ….

[practically]proc to return 0-row, null or default value

We often write lookup procedures to return a single joined record.
Better distinguish between these scenarios below. The same stored proc
can
– returns 0-row
– return a special value to indicate 0-row
– return a null value for a field
– return a default value
If possible, I generally avoid returning null value, because they
require extra parsing in java. Besides, null values can be a consequence
of many scenarios — ambiguous.
If the one and only select from the proc simply selects a bunch of
variables, then 0-row won’t happen. How do you indicate 0-row? A very
common scenario. I often use a @rowct variable, that’s updated by the
earlier table selects. In this context, we can also put special values
into other fields to indicate 0-row.
If you want the caller to know it’s 0-row, null or default value, when
all scenarios are possible.
– then choosing a default value can be tricky
– null can be tricky because in the @rowct case, a lot of fields of the
last select might be null.

What’s so special about jvm portability compared2python/perl#letter

You have a very strong technical mind and I find it hard to convince you. Let’s try this story…
At a party, one guy mentions (quietly) “I flew over here in my helicopter …” 5 boys overheard and start talking “I too have a helicopter”. Well the truth is, either they are renting a helicopter, or their uncle used to have a helicopter, or their girlfriend is rich enough to own a helicopter, or they have an old 2nd hand helicopter, they have a working helicopter for a university research project, or a toy helicopter.
It’s extremely hard to build a cross-platform bytecode interpreter that rivals native executable performance. Early JVM was about the same speed as perl. Current JVM easily exceeds perl and can sometimes surpass C.
In contrast, it’s much easier to build a cross-platform source code interpreter. Javascript, python, perl, php, BASIC, even C can claim that. But why do these languages pale against java in terms of portability? One of the key reasons is efficiency.
To convince yourself the value of JVM portability, ultimately you need to see the limitations of dynamic scripting languages. I used them for years. Scripting languages are convenient and quick-turnaround, but why are they still a minor tool for most large systems? Why are they not taking over the software world by storm?
Why is C still relevant? Because it’s low-level. Low-level means (the possibility of) maximum efficiency.  Why is MSOffice written in C/C++ and not VBA? Efficiency is a key reason. Why are most web servers written in C and not perl, not even java? Efficiency is a key reason.
Back to jvm portability. When I compile 2000 classes into a jar, and download 200 other jars from vendors and free packages. I zip them up and I get a complete zip of executables. If I fully tested it in windows then in many cases I don’t need to test them in unix. Compile once, run anywhere. We rely on this fact every day. Look at spring jars, hibernate jars, JDBC driver jars, xml parser jars, jms jars. Each jar in question has a single download for all platforms. I have not seen many perl downloads that’s one-size-fit-all.
I doubt Python, php or other scripting languages offer that either.
(See comments below)
Sent: Sunday, June 26, 2011 8:14 PM
Subject: RE: What’s so special about jvm’s portability compared to python’s or perl’s?
If you treat JVM == the interpreter of php/python/perl/etc., then Java’s so called “binary code portability” is almost the same as those scripting languages’ “source code portability”.
[Bin ] I have to disagree. AMD engineered their instruction set to be identical to Intel’s. Any machine code produced for Intel runs on AMD too — hardware level portability.

That’s one extreme level of portability. Here’s another level — Almost any language, once proven on one platform, can be ported to other platforms, but only at the SCP (source-code-portable) level. Portability at different levels has very different values. High-level portability is cheap but less useful.
Java Bytecode is supposed to be much faster as a lot of type checking, method binding, access checking, address resolution.. were already completed at compile-time. Java bytecode looks like MOV, JMP, LOAD … and gives you some of the efficiency of machine code.
Another proof is: Java binary code (compiled using regular method) can be de-compiled into source code, which indicates that its “binary code” has almost 1-to-1 mapping to “source code”, which means its binary code is equal to source code.
[Bin ] I would probably disagree. The fastest java bytecode is JIT and probably not decompilable I guess. For a sequence of instructions, the more “machine-like”, the faster it runs.
Well, you may want to argue JVM is better than the interpreter of those scripting languages, and I tend to agree. Java must have something that earned the heart of the enterprise application developers. Only that I haven’t found what it is yet 🙂

Singapore is a trickier work place

Singapore is a trickier work place than US. It would be great to find a mentor and a protective manager.

I usually have good rapport with users, but it's possible that I may not jell well with some traders and some colleagues.

I hope to fall back on my ability to get-things-done and my system knowledge so they would feel it's hard to find someone to replace me.

what swing components must a trading app use

Absolutely must —
* top-level container? Yes, mostly JFrame, as the other 2 top-level containers are less useful or popular
* content pane
* JComponent, the parent of most UI components
* layout manager is an absolute must, since every content pane needs a layout manager, unless you choose absolute positioning

There are non-UI objects that are absolute musts —
– invokeLater() etc. Without it swing might appear to be functional, but i don't feel safe.
* UI events and listeners

If you are expecting more, I'm afraid those are the only ones I know. But here are a few “unavoidables”
– jtable? row/column data. Why is Excel by far the most important and sophisticated among Office apps?
– text panes?
– jpanel? indispensable for grouping components

white board coding interview – some patterns

Always a well-defined, well-understood problem, with no ambiguity. Usually a typical comp science problem. Usually 5 – 30 min given. The faster, the better, since interviewer has really limited time, even if they say “take your time”.

+ Usually needs some non-trivial algo, perhaps some data structure.
+ Usually you need to be crystal clear about stackVar vs fields vs static var.
+ For loops and recursion, you need to be crystal clear about boundary conditions.

Often you need a good grasp of a lot of important details of the language.
– Often you need to be crystal clear about memory (de)allocation.
– For pointers, you need to be absolutely clear about init, reseating, deallocations.

The algo always builds up from
– if/while (the simplest, but can be tricky)
– subroutines
– methods, ctor,
– locking/wait/notify
– recursion? sometimes, esp if the data structure is a graph
– regex? seldom

Therefore you need to be thoroughly familiar with a small number of lego blocks.

Data structures involved
– linked list
– binary tree
– directory tree
– arrays

simplified wire data format in market data feed

struct quote{
  char[7] symbol; // null terminator not needed
  int bidPrice; // no float please
  int bidSize;
  int offerPrice;
  int offerSize;
}
This is a 23-byte fixed-width record, extremely network friendly.

Q: write a hash function q[ int hashCode(char * char7) ] for 300,000 symbols
%%A: (c[0]*31 + c[1])*31 …. but this is too slow for this options exchange

I was told there’s a solution with no loop no math. I guess some kind of bitwise operation on the 56bits of char7.