easiest way to display a DB record in jtable

DefaultTableModel model = new DefaultTableModel(new Object[] {“Col”,”Value” }, 0);

model.addRow(new Object[] {selection});

Map map = new JdbcTemplate().queryForMap(“select * from table1 where …”);

for (Map.Entry entry : map.entrySet()) {
  model.addRow(new Object[] { entry.getKey(),
  entry.getValue() });
}
this.table.setModel(model);
this.table.repaint(); // thread safe

custom allocator usage

Some container classes have custom allocators, because the default allocator (allocator) leads to memory fragmentation. — tip from Wang, c++ veteran in Nomura.

Custom allocators can also increase “locality of reference”, to allow hardware to exploit locality of reference.

Overall, custom allocators are an optimization technique.

[[STL tutorial]] has a small example

Linq, extension method etc – random thoughts

I find the c#3.0 center piece — the LINQ feature — a lot of fancy beautification features and syntactic sugar. I don’t feel they
add any real capability that was completely “not doable” in C# 2.0.

However, Linq is indeed adopted in investment banks.

They certainly make c# source code more elegant, more natural, more like English, more “dense” but I feel in so doing they also add
additional layers of complexity. I don’t know if this is the best direction for a language.

Linq requires extension methods. Compiler magically converts static methods into functions that appear to be instance methods of the
IEnumerable type.

Linq encourage lambda (in place of plain old delegates). Compiler converts each lambda expression into a delegate instance.

Linq encourages anonymous types. Compiler converts each such type to a real type whose generated name is known only to the compiler.

Q: What problems do you have with Linq?
A(from a veteran): slow for SQL

interpolating on vol surface between tenors (worked eg

Q: how do you query the vol surface at a fitted strike but between 2 fitted maturities — Jun and next Dec, assuming today is Jan 1.

First Take sigma_J*sigma_J and sigma_D*sigma_D. Say we get Something like 20%^2 and 30%^2. Remember these are annualized sigmas. Suppose those maturities are 6 months and 24 months out. Raw variance values would be

Variance_J = (20%^2)* 6m/12m = .02
Variance_D = (30%^2)* 24m/12m = .18

Our assumption is that variance is linear with TTL, so let’s line up our raw variance values

6 months to expiry –> .02
15 months to expiry -> x
24 months to expiry -> .18

==> x = .10 (not annualized)

Annualized variance_x == x /(15/12) = .08
Annualized sigma_x = 28.28%

This estimate is better than a naïve linear interpolation like

6 -> 20%
15 -> ?????? — 25%
24 -> 30%

delegate invocation list, briefly

— based on http://www.ikriv.com/en/prog/info/dotnet/Delegates.html
An invocation list is a reverse singly linked list, with the last appended “single” as head. Like in hash table buckets, this is optimized for insertion. 

Invocation time — Since this is a singly linked list, we need recursion. Head node’s method (last appended) starts first, invoking 2nd-last-appended.

When you append [d1,d2, d3, d4] to an existing invocation list, system effectively adds d1, then adds d2… (Internally, it could do it faster with pointers.), so I call these d1, d2 .. items “single-method delegates”, or “singles”.

Note the link pointer between link nodes is named “PreviousNode”.

Remove() is by logical-equality, not by reference equality.

##implicit compiler acts on delegates

— Based on http://www.yoda.arachsys.com/csharp/events.html

# MyDelegate d1 = new MyDelegate(this.InstanceMethod1); // when you add this code in a non-static context, the “this.” is implicited added by compiler, but you can add it explicitly

# MyDelegate d2 = new MyDelegate(Class4.StaticMethod2); // the class name, if omitted, is inferred by compiler

# when you call d1(someArg), compiler implicitly calls d1.Invoke(someArg). You do not have to call this method explicitly. Invoke() is useful in reflection. See MSDN

# when you perform d3 = d1 + d2, compiler implicit calls the static Delegate.Combine(d1, d2)
# when you perofrm d3 – d2, compiler implicitly calls Delegate.Remove(d3, d2)