unicast delegate=(carefully)generalized func ptr

The delegate construct is related to func pointer, functor, java SAM interfaces … A beginner need not grasp all the relations but sooner or later we have to.

I feel delegate was invented much later and is a generalization of those predecessors.

http://bigblog.tanbin.com/2010/11/delegate-instance-2-field-heap-object.html is the best sound byte I have come up with. ** The 2-pointer construct is innovative. **

delegate element = 2-field heap object, internally

* A delegate instance is a 2-field HEAP object enclosing a Pair of pointers to 1) Target object 2) a method therein.
* A delegate instance is a 2-field HEAP object enclosing a Pair of pointers to 1) a method 2) its host object.

The method signature must match the delegate Type, which is not as restrictive as it sounds — The signature specified in you delegate Type is entirely up to you.

Caveat — this is a so-called simple delegate with an invocation list of 1. Focus on the core issues.
Caveat — the method in this delegate is non-static. Method can sometimes be static but we won’t cover it today.

Remember — a delegate instance is ALWAYS allocated on heap.

[1] is a very short description. Here’s the slightly longer version — At both runtime and compile time, we should view a simple delegate instance as a 2-field heap object enclosing
1) a pointer to a Target object
2) a pointer to a method therein.

In one part of the program, you pass in a target object (possibly “this”) + its method, to instantiate this delegate as a “wrapper” object. You then pass this wrapper around. Often this wrapper becomes a field of an observable object. The observable can then “invoke” this delegate which internally calls the target’s method.

SecDB – dependency-graph database

SecDB is an in-memory object database, just like gemfire. But Gemfire doesn’t have graphs; only standalone hash tables. Gemfire is credated by OODB (object-oriented database) veterans.

SecDB runs (in-memory) 24/7 with mirror sites and disk-persistence. No early morning cache loading like many trading systems do.

SecDB is, presumably, a master/slave database accessed over the network, just like a regular RDBMS.

This is internal low-level design so not many people would confirm, so here’s my personal speculation. For maximum flexibility SecDB probably uses dynamic object types in the python sense, not the static types in java. (Perl and javascript OO is also based on the generic hash). GS says SecDB is object-oriented, but I guess it’s not strongly typed. Perhaps less like struct-with-methods but more like python’s dictionary-based objects.

1) Here’s the Best way to start understanding secDB –
    Assumption 1 – we can build most FI trading apps using java.

SecDB is a schemaless graph database, like a huge xml. Each node represents a domain object, such as Trade, Position/Deal, Price, Product, a series of market data…

    Assumption 2 – operations are mostly CRUD i.e. create-read-update-delete.
    Assumption 2a – Most CRUD business logic are doable in java without RDBMS, using graph-walk.

SecDB can therefore implement the same logic using graph-walk.

2) Technical comparison against java + rdbms.
Data access is index lookup in RDBMS but SecDB requires deep graph-walk. Occassionally, in-memory indexing can improve performance. A gemfire index is a auxiliary hash table, so secDB may be similar.

3) functional comparison against java + rdbms.
Strength — time-to-market with a new “instrument”. Actually, “Product” is the buzzword used in GS. Using rdbms, we need table changes, application changes, impact analygis and regression test — rigidity.

Weakness — fast-changing data. SecDB is great for relatively static data. To update a tree node repeatedly, we probably need to walk the tree every time. But is disk-based rdbms any faster?
Weakness — equity — latency-sensitive. (But somehow JPM and BofA are using graph-DB for FX risk mgmt.) To address performance hit of graph-walk, GS throws in massive amount of hardware. GSS risk uses a compute-farm aka grid.

Strength — PnL Rollup is naturally a tree algorithm.
Strength — what-if scenario analysis exploits spreadsheet-style chain reaction
Strength — risk stress testing or scenario testing.     Risk is the most important user of SecDB.
Strength — UAT datatabase is the prod DB but in RO mode
Strength — real time pricing an instrument that depends on many other “objects”. You can give a what-if tweak to one of those objects and see the spreadsheet-style ripple effect. I think it’s because all these objects are in memory and listening to each other.

reliable JMS in various configurations

Simple Rule: In both queues and topics, I believe expiration setting overrides every delivery guarantee, including Durable sub. Idea is, sender knows its OK to drop a pending message after its useful life. See P101, 104[[JMS]]

Simple Rule: In both queues and topics, durable or not, non-persistent messages are always at risk to get lost[2] , so reliability is always below 100% — P102 [[JMS]]

[2] if broker acknowledges receipt to sender, then goes down, with the message. Persistent Messages are persisted before broker sends ack to sender, and sender method returns. Without receiving the ack, sender blocks for some time and throws an exception.

As we go though different configurations below, we will realize 100% reliability requires multiple conditions. Each missing condition can break 100% reliability.

– durable, persistent message without expiration? guaranteed
— same config but nonpersistent? not reliable
— same config with expiration? will expire

– p2p, persistent message without expiry, but a disconnected receiver? guaranteed — consider the SIM upfront queue.
— same config with expiry? will expire

– disconnected non-durable subscriber? won't receive
– connected non-durable subscriber, persistent message without expiration? best-effort. I believe broker will attempt delivery. If client disconnects before sending ack, broker may give up.

persistent messages may get delivered twice

Even though a persistent message is “delivered exactly once”, it can get delivered twice to a given receiver, if the broker doesn't receive acknowledgment in time. See P102 [[JMS]]. Failure could be in the broker or the client runtime.

If a trading system must receive each order message exactly once, there are many solutions.

* check the message redelivery flag, which is guaranteed to be set on 2nd delivery by the broker.
* check message id
* client_ack
* transacted message

thread detach — boost ^ java

In most (if not all) systems, a thread object is a “poor handle” on a real world thread.

in java, if the thread object becomes unreachable (and garbage collected) then you can't join or interrupt the thread, or test if it holds a particular lock. You have to wait for it to finish or pull the plug with System.exit().

Same scenario exists in boost thread. Additionally, boost lets you explicitly call myThread.detach(), to decouple the myThread object and the real world thread.

Q: after detach(), what's the thread object?
A: it represents not-a-thread

jargon – grabbing, waiting, blocked, sleeping

A few types of thread suspension. Guess which methods can throw InterruptedException!

1) sleeping — sleep()
2) waiting — (implicitly for another thread) wait(),join(), invokeAndWait() …
3) blocked — socket.accept(),
4) grabbing — blocked while acquiring a lock. Note when a wait() returns due to a notification/exception/timeout, it must go grab the lock.

I would say “the thread is grabbing the lock” or “my thread is blocked by a lock”

cyclic barrier – boost thread ^ java

A quick and memorable analogy of a boost thread barrier object (of the barrier CLASS). Think of such an object as a thread-safe collection (say vector) of 3 items. 3 threads all have a pointer to the same collection.

Thread A calls myBarrier.wait() inside some function1, to remove one item, and blocks
Thread B does the same
Thread C does the same in some function2. Now the collection is empty, all 3 threads join the Eligible club (as described in the post on Eligible^Running)

java offers CyclicBarrier.

what is a c# delegate, again

This post is mostly about the BB case as defined in the post on 2 fundamental categories.

Let’s try this question again — not simple.

#1 A simple delegate instance holds a method’s address[1] + a Target object [2] to call it on.
** I feel the delegate concept gives more meaning to the traditional “callback” concept
** Argument to the method is passed at invocation time, not creation time. In this respect, delegate == functor.

#2 In practice, a delegate instance often holds a bunch [3] of single-method delegate (instances). Supports append/removeLast. If you program your delegate to be invoked at runtime, all those methods run sequentially by insertion order — key language feature.

Warning — in c# discussions, a “delegate” can mean a delegate Type or a delegate Instance. Always know what is meant in each case.

The Target can be null when we instantiate a delegate with a static method. In that case the full address {class, method} is remembered.

[1] an address, not a a pointer variable
[2]This target thingy is a permanent pointer
[3] actually a reverse singly linked list, known as the invocation list.

value-add by software application across industries

End-user applications (not infrastructure) can be a catalyst and enabler in many fields, but which fields let it unleash the most energy? You can measure the ratio of profit generated and man-day cost. Roughly ranked in this ratio —

#1 security trading
** low-latency — indispensible
** In much of FICC, business can usually function using phone and spreadsheet
#2 accounting and ERP
(DB, OS are considered infrastructure — not usable as is; need applications on top of them.)
#3 telecom
** billing etc
** voip
* logistics, warehousing
* gaming
* online gamble
* computer animation
* electronic component testing in Chartered
* e-government
* tax
* hospital information system
* porn sites – consumers pay
* travel site, amazon, 1800flowers, diapers.com
* ebay
* online and mobile payment
* antivirus
* spreadsheets, word processors

Many popular applications are –> “innovative software applications looking for paying customers” <– because consumers want it free.
* search engine
* web mail — hopelessly free
* zed
* knowledge portal — NIE
* online learning
* newspapers online
* cnet
* facebook, twitter

IRS motivation, again

For an issuer to borrow $100M, the floating rate is typically lower than the fixed rate that's available from a regular bond issue.

Some “fixed” bond issuers actually want a floating interest cost, which is typically cheaper. IRS is a simpler route than the VRDO with the remarketing agent and letter of credit.

“Major issuers evaluate the swap market and the bond market side by side” as 2 alternatives.

Cast of characters
* issuer, like IBM
* swap provider, like GS
* investor, like grandma.

commission + seller px == trade px # bond trade

In a bond trade, sales credit is always included in the trade price, the price *buyer* pays, not the net amount seller finally get.

Bond Markets present a simple facade to retail investors. In muni, retail investors tend to be buyers who often hold to maturity. Therefore buyers see a simple, consolidated price.

Seller must give up part of that price to the salesperson as “sales credit”.

Sales credit always *increase* the trade price.

lookaround assertions across languages

/(?)\bparentDataStore/ ## is a perl regex with a negative lookbehind. It disqualifies "->parentDataStore"

(class|struct)\s+MyClass\b(?!;) ## is a perl regex for a class definition. The trailing negative lookahead (?!;) ensures we don’t match a forward class declaration.
—-Below is a Nov 2010 java example:

replaceAll("(?<=</?)MTSMessage", "SIG_Notification")

The optional positive lookbehind assertion above says to match (and replace) the "MTSMessage" string provided it's preceded by "<" or "</".

The "or" is implemented by q( </? ) i.e lessThen followed by an optional slash

— 2019 grep command highlights the token after "responseRuleSet="

grep --color -P '(?<=responseRuleSet=).*? '


LookAhead is simpler than LookBehind — Compare the syntax. Some languages only support lookAhead.

I feel negative lookAhead is more useful than positive lookAhead. I feel these zero-width assertions are useful in progressive matches, but I seldom need complex progressive.

If you use lookaround you may want to start with sample code and make incremental changes. Plausible but incorrect lookaround patterns abound. This is a time you need to understand how regex engines work.

* explains how (not) to capture a back-reference in a lookAhead.

c#delegate:closest ancestors]other lang+py

Update — I now feel it’s more practical to separate the 2 (or more) “streams” of thoughts of labmda vs multicast events. The write-up below was written without that seperation. Unnecessarily complicated.

a unicast delegate type =~= a java interface type with a single method, without method body. [1] I no longer subscribe to this.
a unicast delegate type =~= a typedef for a function pointer. This typedef can apply to many functions.

a “delegate” is an instance of a particular delegate type. If we have to build on the java interface idea, then ….

a delegate instance =~= an instance of a stateless concrete single-method class implementing that interface in [1]

a delegate instance =~= a particular stateless functor. Specifically an instance of a functor-wrapper. Note An instances of a functor type is sometimes stateful (see Scott Meyers), but an instance of a delegate type is always stateless.
Update — As explained in http://msdn.microsoft.com/en-us/library/system.delegate.aspx ….
a delegate instance =~= instance of a functor-wrapper having a permanent pointer to the target object myDog, so it could later invoke myDog.jump()

a delegate instance =~= python method object bound to a host object? But stateless??

a delegate type is a distinct type (with a name), a subtype of Class Delegate. Delegate type names typically start with D like “DSomething”

The clue to see the link between a delegate type and a delegate instance is the instantiation expression new DSomething(meth1)

Java’s interface is not really an extension of the c++ functor. C# delegates build on top of java interfaces AND c++ functors.

average product of 2 deviations — stdev, correlation..

This is the basis of standard deviation, correlation coefficient and variance.

Say we have 22 measurements of student heights. First we find the mean. Deviation is defined as a “distance” from the mean.

Variance is the simplest idea — average product of deviation*deviation. It has dimension of meter*meter

Standard deviation σ is based on variance — √average product of deviation *deviation. Dimension of meter

Now we pair up student’s height deviation and the same student’s weight deviation.

Correlation coefficient is — (average product of deviationh * deviationw) /(σh * σw) Dimension of …nothing.

##shallow technical xp is uaually enough for GTD

(See also post on theory^how-to explaining threading and eclipse.)

Here’s a list of sexy technical skills hiring managers look for, but when you spend a few months in it you realize there’s no real *accumulation* or depth in it. 1 month’s systematic learning is enough then you need to “meet and greet” the creatures in it. That’s how you become productive with each tool.
– spring, hibernate
– RV
– gemfire
– perl, python because most places don’t use advanced features
– web service

? threading requires some theoretical and analytical skill.
? jvm tuning may require accumulation but needed in only low-latency systems

In contrast,
+ DB tuning requires accumulation
+ c++ requires accumulation
+ c#
+ swing, wpf
+ unix has depth but no job requires it
+ reflection, but no job spec mention it
+ eclipse has, but few job specs mention that

parameterized wrapper class with a superclass

(This looks like a low-level and widely usable implementation pattern. If it is, then we better learn to read it. However, I don’t see many java guys create generic classes.)


A wrapper class’s behavior is affected by 3 types of things


·         The “kernel” fields wrapped in the wrapper. In addition, there are often helper fields, too.

·         The parent class

·         The type param. Remember this class is parameterized.


This looks simple until you see it used in a complex system. You need to remember how these “influences” are set.


public class EntityCacheListenerAdapter<K, V extends Entity, T extends EntityListener>

extends AbstractCacheListenerAdapter {

      public EntityCacheListenerAdapter(T target) {

            super(target); // populating this.target



      public void afterUpdate(EntryEvent event) {

            super.getTarget() // inherited from parent

             .entityUpdated( // this method is from the kernel field

                    event.getOldValue(), event.getNewValue());



template and OO are orthogonal constructs

11) Template and OO are orthogonal constructs. Some might see a concrete template class as a subclass? Probably not. In classic OO Analysis and Design, there's no place for templates.

22) Template is one level higher than OO. So-called “Meta-programming”.

12) You can have template-only or OO-only systems, or you can have template+OO systems. Simplest is a template used in class derivation. There are only a few proven ways to integrate templates into an OO system.

12a) STL is NOT one of them. STL is high-template, low-OO.

12b) in java is an excellent way to combine them.

My first focus on the template+OO integration is the role of the actual type. See other posts on allocator and comparator. Only if you are already thoroughly familiar with has-a, then only you can understand how the actual type is used in OO and how it interacts with has-a.

A concrete template class could treat the actual type as an OO “component”, but I feel it's very different from a regular field.

CAS and concurrent access to a simple C++ array of pointers

(Some 2010 MS interviewer asked me about this concurrency hazard.) This array could be part of a hash table.

Thread 1 is about to remove an element from a hash table. It needs to first substitute a NULL address into the array to prevent Thread 2 from seeing the to-be-deleted entry. Then it will delete on the obsolete ptr … but actually it has to save that address before storing the NULL.

The critical operation is the atomic load-and-store — “load current element and substitute a NULL”. XCHG is the way to go. But what if another thread is doing the same operation? I feel a CAS loop is better — Thread 1 first loads current value into a register. Then it attempts to compareAndSet. If current value is unchanged, it puts in the NULL. Otherwise it should retry.

Q: What if in the same clock cycle, 2 threads (on separate processors) succeed in the load-and-store. Both loads the obsolete address and both try to delete on it… double-free
%%A: I think the hardware spec should cover this scenario. Should not be left to chances.

This situation is virtually impossible to test. But if they don’t happen in the same clock cycle, then the slow thread will see a NULL in the array – lock-free thread safety.

MSVS ^ other c++ IDEs on windows

–regarding apps FOR linux
Options: eclipse, codeblocks? Well, I don’t trust the GUI on linux. I’d avoid all GUI IDEs. the Barcap FI c++ team basically uses visual studio + vi to develop c++ apps for Linux.

case closed — no IDE on linux for me.
On windows, front runners are eclipse, codeblocks and msvs. I tried CB — too complex to learn. To be fair, these 3 IDEs are equally complex but I have prior experience with eclipse (due to java) and msvs (due to c#).

Msvs has the most books, online resources and user base — largest support network. Reason? I guess for anyone building apps for windows, msvs is the defacto standard. Many textbooks use msvs

http://www.boost.org/doc/libs/1_52_0/more/getting_started/windows.html shows Boost also supports VS as the primary windows IDE.

Msvs is not free, but some say the freeware MSVSE has c++ http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express#Visual_C.2B.2B_Express

Both eclipse and CB uses mingw/gcc, but for apps running on windows, the microsoft compilier is the standard.

Management trec vs tech trec

(At least In theory) An experienced developer can do a basic job as PM, architect, BA … but not vice versa. I have seen some examples — Yang, Lance (Lab49), Jerry, Rob Westlaken (Citi), myself in NIE, in EOS+SIM, … Management skill and experience requires less serious training IMO. Many people are born managers. Some people even told me I have good management skill. In a trading system, managers’ competences include

* managing business users
* managing team
* managing the senior manager
* #2) delivering biz value. Finish projects on time, in budget. This is what a keen hiring manager would tell a reluctant candidate. In trading, time to market is a priority.
* #1) meeting senior manager’s expectations, and help him rise.

I feel an experienced developer can meet all these basic requirements.

Miao Weishan pointed out an elite class of managers actually manage very well. I  guess the evidence is that given an ordinary team of resources, such a manager could achieve well above the expectation.  Beside technical know-how, I guess such a manager would demonstrate exceptional judgment (判断力, including strategic insight) and inter-personal skills. Many books talk about the “top 5 fundamental qualities” of a manager, things like
* planning/execution,
* motivation,
* persuasion,
* loyalty of staff,
* energy,
* perseverance/endurance….

I guess many of these qualities are relevant to a parent like me, too. I feel these qualities are well above the basic requirements listed above, so a competent developer isn’t enough.

bond trade capture system use-cases

Trading system architect must know such essential use cases:

A hypothetical bond trade booking sys – named Blo (for Blotter)

Blo use case 1: phone execution, then trader enter trade into Blo.

Blo use case 2: traders advertise offers and bids on an internal network. Our salesperson lifts an offer. Trade is confirmed on the spot. System automatically books trade into Blo. This flow converts the Order into a Trade automatically. It’s possible for 2 salespersons to lift the same offer. System will reject A and book B.

Blo use case 3: advertise offers to external venue, lifted automatically. External venue sends us confirmation and trade booked.

Blo use case 4: trader responds to external bid-wanted (RFQ) and her bid is selected, becoming a trade. External venue sends confirmation to us, trade booked.

In Eq, there’s often a big OMS to manage the order state from an initial request to a completed trade.

JMPC FX pricing data-struct IV

Q: drawback and advantage of ref-counting memory-cleanup vs java GC algorithms
%A: Ref-counting can’t deal with islands of circular references. I don’t know any advantage of RC.
%A: ref-counting is proven in c++ shared pointers, string implementations and a lot of STL containers.

Q: ref-counting is faster than mark-and-sweep? (No pauses.)
A: counter updates must be thread-safe
%A: more predictable. No sudden loss of cpu resources
%A: memory allocation for the counter is a major cost to boost authors.

Q3: how do you implement a queue in a single-threaded world?
%A: linked-list vs circular array.

Q3b: What if your circular array is out of capacity?
%%A: cc array is best for bounded data structure. So this occurrence is probably a design error.
%%A: Follow ArrayList. copy to a new array with 200% capacity.
%%A: Alternatively allocate an “overflow” array. This will break random access iterator but our queue need no random access.

Xtap uses circular buffer to pre-allocate memory.

Q3c: advantage of cc-array?
A: memory allocation is rare (or never).
A: For linked-list, the payload is already a full object, so memory allocation needed for new Node – the “wrapper” over the payload object.

will swing be pushed out from front office@@

Is swing slow and ugly? only before java 5.  Search for “java swing” in eFC.

– I think on windows WPF has an inherent advantage due to excellent integration with win32.
+ If server-side is java (not c++ or c#), then i feel swing has an inherent advantage over WPF. RMI, JMS, serialization, shared domain entity classes, distributed memory…
+ requires no installation
+ free and available out of the box

DB as audit trail for distributed cache and MOM

MOM and distributed cache are popular in trading apps. Developers tend to shy away from DB due to latency. However, for rapid development, relational DB offers excellent debugging, tracing, and correlation capabilities in a context of event-driven, callback-driven, concurrent processing. When things fail mysteriously and intermittently, logging is the key, but u often have multiple log files. You can query the cache but much less easily than DB.

Important events can be logged in DB tables and

* joined (#1 most powerful)
* sorted,
* searched in complex ways
* indexed
* log data-mining. We can discover baselines, trends and anti-trends.
* Log files are usually archived (less accessible) and then removed, but DB data are usually more permanent. Don't ask me why:)
* selectively delete log events, easily, quickly.

* Data can be transformed.
* accessible by web service
* concurrent access
* extracted into another, more usable table.
* More powerful than XML.

Perhaps the biggest logistical advantage of DB is easy availability. Most applications can access the DB.

Adding db-logging requires careful design. When time to market is priority, I feel the debug capability of DB can be a justification for the effort.

A GS senior manager preferred logging in DB. Pershing developers generally prefer searching the same data in DB rather than file.

##common IV questions@arch xp

To build and strengthen a lead over non-trading developers, you need to demonstrate architectural experience. Shuo described how to demonstrate management experience. Same idea.

I think a “mainstream” [2] hiring manager in a trading system often looks at in-depth understanding, fundamentals, architecture experience. Now, what kind of questions test your arch?

  • * your favorite pattern — u r expected to know it inside out
  • * describe some difficult design discussion in your team
  • * ….How would you design a solution to this problem?
  • * How did you improve performance (or throughput or latency)
  • * When did you choose async over sync?
  • * how did you use xml?
  • * When in your experience is DB not a good data source?
  • * pros/cons of stored proc?
  • * How did you systematically handle exceptions in your system?

Some of these questions don’t sound like arch-questions. Be careful. I believe some hiring teams actually divide interview questions into categories, with one of them on arch. They actually want to hear your “presentation” on arch. If you talk about other things, they might quietly give you a 0 mark — “unable to operate at a higher level”.

Compared to the average developer, an architect thinks with clarity and focus, and zooms in on the key factors quickly, and probably communicates the same. I remember Yang, Chad (Billing)… Arch questions open up the candidate and reveal design thought process and technical communication style.

[2] neither the sharpest nor the laziest.

file descriptor redirection, exec

–Annotations on http://tldp.org/LDP/abs/html/ioredirintro.html

bash$ lsof -a -p $$ -d0,1,2
bash 363 bozo 0u CHR 136,1 3 /dev/pts/1
bash 363 bozo 1u CHR 136,1 3 /dev/pts/1
bash 363 bozo 2u CHR 136,1 3 /dev/pts/1

bash$ exec 2> /dev/null
bash$ lsof -a -p $$ -d0,1,2
bash 371 bozo 0u CHR 136,1 3 /dev/pts/1
bash 371 bozo 1u CHR 136,1 3 /dev/pts/1
bash 371 bozo 2w CHR 1,3 120 /dev/null <—

http://tldp.org/LDP/abs/html/x17601.html#USINGEXECREF shows —

exec 6>&1 # Link file descriptor #6 with stdout.
# I think this creates a new file descriptor FD#6 as alias of FD#1. FD#6 is probably a **pointer** to the in-memory object FD#1. The object IS the original file descriptor.

exec > $LOGFILE 2>&1 # stdout replaced with file “logfile.txt”.
# the object is not discarded. FD#6 still points to it, but the current process no longer uses that object.

#### this is a useful thing to put into your script, if someone calls your script.

# now the current process will use the original “object” from now on.
exec 1>&6 6>&- # Restore stdout and close file descriptor #6.

javascript lookup-hash implemented as object

Javascript syntax is rich and confusing. Better get the underlying idea before you try to memorize the syntax.

There's no builtin construct to get the length of an associative array, since it's an object.


Everything in javascript is an object. Everything. Arrays, functions, even numbers! Because of this, you can do some really interesting things, such as modifying the prototypes of Objects, Arrays, etc

Javascript arrays are a type of object used for storing multiple values in a single variable. Each value gets numeric index and may be any data type.

http://docstore.mik.ua/orelly/webprog/jscript/ch08_06.htm OReilly's javascript book:

JavaScript objects are much more like Perl hashes than C++ or Java objects.


In JavaScript, objects are also associative arrays (or hashes). That is, the property


can also be read or written by calling


Thus, you can access each property by entering the name of the property as a string into this array. Such an array associates each key with a value (in this case the key Home is associated with the value normal). In the Perl programming language it is also called a hash.

Unlike **Perl**, which requires you to create such an associative array explicitly, JavaScript automatically creates a associative array for each object.

SmartLifecycle used in neo

Neo classes include a lot of start() and stop(). These are inherited from SmartLifecycle.java.

Compared to super-interface Lifecycle.java, SmartLifecycle interface provides more sophisticated integration with the container's startup and shutdown phases.

I think Neo uses this to implement a lot of “services”. IOC Container must be alive throughout.

## std::string cheatsheet

(c-string is fairly popular and more widespread)

An experienced java developer usually memorizes 10 methods of String.java. ditto for std::string. (See the STL book or the Absolute c++ book.)

  • insert() has many overloads
  • push_back() a single char
  • append() and operator+=() can even take in a single char, or a repetition of a char
  • operator+() to concat
  • substr() returns a COPY
  • find(a char or cStr or std::string)
  • find_first_of(a collection of candidate chars, passed in as a string),
    • find_first_of(char) is same as find(char), according to my test
  • find_last_not_of() //trim
  • at() can read-WRITE a single element.
    • operator[] is faster, but without range check, as with std::vector!
  • front() back() can read-WRITE the character
  • transform(word.begin(), word.end(), word.begin(), ::tolower)
  • std::string trailing space trim
  • c++split string on custom delimiter char
  • begin(), rbegin(), end(), rend()
  • replace() has many overloads
  • to_string(int_or_float) // c++11
  • clear()
  • empty()
  • myStr.capacity() // like vector

…. see http://www.cplusplus.com/reference/string/string/

option rule – delta converges to 50/50 with increasing vol

Better develop reflexes — Across all maturities, all ITM/OTM options’ delta would converge towards 50% when perceived and implied volatility intensifies. Option premium rises.

50 delta means ATM.

50 delta also means no-prediction about my option finishing ITM or OTM. When vol spikes, it becomes harder for “gamblers” to assess any given strike — will it finish ITM or OTM?

Let’s use a put for illustration. When underlier becomes very volatile,
– a previously deep OTM (hopeless) suddenly looks a useful insurance protection. eg – A ultra-low-strike put.
– a previously deep ITM (sure-win) suddenly looks “unsafe” — may finish worthless.

Rule) At expiry, underlier volatility doesn’t bother us and is treated as 0
Rule) At expiry, option delta == either 0 or 1/-1 never something else. Fully diverged
Rule) In general, 0 implied volatility means all options’ deltas == either 0 or 100%
Rule) Similarly low implied volatility means all options’ deltas are close to the 2 extremes.

reflection on a c# enum instance



        /// An enum type
        /// Could be the enum name like OneDay or declared value like “1D”
        public static T StrToEnum(object obj)
            if (obj == null) throw new Exception();
            foreach (T anEnumeratedValue in GetValues())
                MemberInfo[] memInfoArray = typeof(T).GetMember(anEnumeratedValue.ToString());
                if (memInfoArray.Length == 0) break;
                object[] attributes = memInfoArray[0].GetCustomAttributes(typeof(EnumMemberAttribute), false);
                if (attributes.Length == 0) break;
                string declaredValue = ((EnumMemberAttribute)attributes[0]).Value;
                if (obj.ToString() == declaredValue)
                    return anEnumeratedValue;
            string aNameToLookFor = obj.ToString();
            return (T)Enum.Parse(typeof(T), aNameToLookFor, ignoreCase: true);

portable value-adding xp]financial systems

Q: Suppose a developer X works shorter hours and on the peripheral, and Developer Y works longer hours, and in the core modules of a complex financial system, and they join another finance company after 2 years. Does Y bring more value to the new team? Suppose both are smart, ambitious developers.
A1: Yes for a hands-off architect role. The intimate knowledge of the previous system are relevant and somehow “portable”.

(For the rest of this email, let’s assume it’s a developer role.)

A2: Yes if X’s projects are really, really peripheral, like database clean-up, wrapper scripts, high-level testing without touching java/c#/SQL source code.

Now suppose X does touch source code. Many trading systems have core components as non-web components, so if X only works on the web layer, then I would be worried. Similarly, if X only works on some nice-to-have reporting module, without any exposure to the core business logic in the system, I’d be worried too.

Actually a business intelligence module can have complex SQL logic and also technically challenging if data volume is huge. A complex SQL join often defines relationships between tables, so whoever writing the join knows that business logic. Now suppose the tables joined are the important tables (like positions, trades, prices, risk, volatility, model parameters) in a financial system, then that business logic is rather critical. In short, there are important value-adding work as well as a ton of unimportant work in the BI space.
Another role to avoid (for a hardcore developer like me) is non-developer roles like trading floor support or BA. I feel they know quite a bit about trader’s world, and also the IT world, but they don’t see the link between the 2 i.e. the implementation.

A3: the level of value-add depends on asset class. For equities (including eq-derivative) front-office trading, volume and latency are a real challenge, so pure generic technical experience might be valuable even without domain knowledge. I was told FX and Treasuries trading are similar. Note middle office and back office equities trading is said to be less demanding, so technical expertise is probably less valued. If our original question is about a high speed eq trading system, Y probably gets more exposure to the technical challenges.

gemfire data distribution among nodes

This is one of the most frequently asked questions. Info below comes from http://xml.gov/presentations/gemstone/gemfire.ppt

1) Consistency Model —
* Distribution without ACKs
* Distribution With ACKs
* Distribution With global locking

2) Pub-Sub semantics —

3) Multiple transports —
UDP MultiCast
(See sys admin guide http://www.gemstone.com/docs/6.5.0/product/docs/html/Manuals/wwhelp/wwhimpl/js/html/wwhelp.htm#href=SystemAdministratorsGuide/SAG%20Title/TitlePageHTML.html)

4) multi-site member discovery/communication


You need to keep your distributed system from splitting into two separate running systems when members lose the ability to see each other, as shown in Network Failure-Network Partition Configurations. When a network failure, or partitioning, occurs, the problem could result in data inconsistencies or a forced disconnect. The solution for this problem is to stop one of the two subgroups from continuing to operate independently.

VaR for cash bonds

I believe Reo doesn’t calculates VaR. However, the cash bond positions might be analyzed by some other system. Result is probably posted to the Risk website, but what data?


Most basic is Perhaps dv01 at position level and rolled up to account level. If you have a price-yield convertor, and you know the current price (perhaps chosen by a trader), you can calculate the price at 1 bps above the present yield and the price 1 bps below the present yield. You can get your own dv01.

low-level language features — c++ ^ java

Low-level features include
– ptr
– func ptr — usually quite complicated
– func ptr rather than java interface
– func ptr rather than method inheritance and overriding
– arrays rather than collections
– ptr rather than iterators
– *char rather than std::string
We operate “lower” when
– At runtime rather than compile time
– doing Memory management
– doing I/O
– interfacing with OS. I think sys calls are usually c-API
– Overloading operator new
– Max efficiency in terms of memory and time
– Handling exceptions
– Serializing
– Composing your own customized data structures instead of standard containers

These usually call for c/c++.

break the 4 deadlock conditions

My long-time java friend told me lock ordering and lock timeout are the 2 standard solutions, but here are additional suggestions directly or indirectly addressing deadlocks.

(“[top x]” means one of my favorite x  techniques.)

For want of a better word, “stuck” is my general term meaning “no-progress” and includes
– lock grab,
– Object.wait(), waking up and grabbing lock
– join(),
– socket accept(),
– long sleep(),
– endless loop,
– unbounded *recursion*

Now the solutions.
–to provide preemption
* [top 3] remain interruptible while getting “stuck”
** even if a recursion/loop calls no blocking method, the thread can still check for the interrupt status from time to time and exit if necessary. see http://download.oracle.com/javase/tutorial/essential/concurrency/interrupt.html
* tryInterruptibly(). Now, if thread 1 knows another thread is holding a mutex it can forcibly grab it, but how does it know which thread? –to break incremental acquisition

*[top 2] have a timeout while getting “stuck” — a wide-spread implementation
** example — in an endless loop, check how long we have been stuck and exit if necessary.
** example — lock timeout — A thread tries to acquire a lock in a specified period. Upon timeout, it release all it’s locks and go to wait status for a period. For example, release 1st chopstick if 2nd chopstick remains unavailable for x seconds. Achievable with tryLock()? Yes P279 [[ java concurrency in practice ]] I believe tryLock() can tell u the 2nd chopstick is unavailable and give you a chance to give up 1st chopstick held. See P69 [[pthreads]] and deadlock avoidance: release all locks voluntarily
* open call? impractical

–to break circular wait
* lockInterruptibly() of the Lock interface. It let’s u try to acquire a lock and remain responsive to interruption.
* reentrant/recursive lock. By default pthreads locks aren’t so a single thread can deadlock itself.
* tryLock()
* [top 2] globally fixed resource acquisition order
* if you identify that 3 threads form a wait-for circle, then reverse one of the threads’ acquisition order
* finally() to release lock if using Lock objects. “synchronized” doesn’t need this.
* Release locks asap. minimize lock scope.
* [top 5] Make all methods finite. Avoid using locks while inside infinite loops or unbounded recursions.

–to break the need for mutex resources
* immutables. no need to lock anything to access them. CopyOnWrite is thread safe because it’s immutable.
* ThreadLocal
* copy On Write
* copy the data for each thread, and sync up later
* replacing sync with atomic variables? both options can be criticized as risky

[10] y locality @ reference

When data volume threatens latency, why is it important to /host/ application and its required data physically close? Why LoR?

J4: fewer hops on traceroute.
J4: network bandwidth is shared. Look at email traffic. Most GS emails travel only inside GS intranet, and don’t add load to email gateways.
J4: ethernet is collision-sensitive. When ethernet is saturated, performance degrades. LoR reduces satuation.
J4: the backbone link between 2 “email gateways” tend to be an expensive and limited resource, so the less you use it, the more you can save on equipment and bandwidth lease.

In low-latency systems, it’s best to avoid distributed cache. Use a single-JVM design to eliminate all serialization costs. Probably at least 2 orders of magnitude faster.

If all the required data by a particular application is physically close by (ideally single-jvm) then less serialization, less replication, less I/O stream synchronization (thread-unsafe by default)…

swing IV questions

Q: jide, swingx?
Q: paint vs repain?
Q: how do you create your own jcomponent class? 
Q: what multi-threading challenges in your projects? What strategies or best practices?
Q: describe your swing projects and the challenges
Q: how do you load lots of data in the background but keep the app still responsive?
Q: undo? No one asked

Q: how do you use property change events?
A: AbstractAction blog

[10]STL complicated: iwt java collections

  • Collections.java and Arrays.java offer a smaller, simpler set of operations than the free functions in STL, which are important and complex.
  • functor and function ptr as inputs. Java uses interfaces, much cleaner.
  • pointers as container elements
  • unary, binary and generator functors. java offers some clean and simple interfaces
  • algorithms usually take iterator arguments but not just any iterator. You need to know what iterators.
  • function adapters

Basic semantics are identical between STL and java collections. Nested container is fine.