coblood – each year you worked

master -> jobjob


Each year that you spent on some job,


you earn, most important of all, some cash to keep the family financially safe.

** you also earn something to plow back. Look at my UChicago experience…

you earn some experience, insight, and hopefully some zbs, but most of it will not be relevant in future jobs

you earn/build some track record that helps maintain marketability.

you either speed up or slow down brain aging

you incur stress

you incur sacrifice of family time and exercise time


option delta hedge – local anesthesia#RogerLee…

An intuitive explanation given by Roger, who pointed out that delta hedge insulates you from only small changes in stock (or another underlier).

Say, you use 50 shares to hedge an ATM option position with delta hedge ratio = 50%. Suppose your hedge is not dynamic so you don’t adjust the hedge, until price moves so much the option delta becomes close to 100%. Now a $1 move in your option is offset by $0.50 change in the stock position – insufficient hedge.

The other scenario Roger didn’t mention is, the option becomes deeply OTM, so delta becomes 1%. Now a $0.01 change in your option position is offset by $0.50 of the stock position – overhedged.

RVR^LVR %% Lesson #1 #400w

A working definition of lval/rval on says — An L-value expression is an expression that

1) refers to a memory location (heap/stack but not a literal value), and allows us to take the address of that memory location via the address-of (&) operator.

The other key features are all obscure:
2) (my suggestion) can pass into a reference parameter of a function

3) can be the RHS of a reference variable initializer

If overwhelming/mind-boggling, just focus on 1). In short. L-value expression evaluates to a LLLocation in memory

The book [I] introduces a simple test of Rval vs Lval, introduced by Stephan T. Lavavej — An Lval expression is anything that has a name. Minor qualifications:
* function returning a reference…

An R-value expression is any expression that is not an L-value expression. C++ standard decrees “A function call is an L-value only if the result type is a reference”
Note both lval and rval refer to “expressions” including variables, but do not refer to objects. Explained more in Q: What is a rvr %%take
ALL expressions can evaluate to some value, so can appear on the RHS, but only some can appear on the LHS. But this has nothing to do with the lval/rval definitions!
Something, like a subscript expression, can appear on the RHS but it is strictly a lval expression, not a rval expression. If you (like me) find there are too many categories of lval expression, then just remember an lval expression is typically a variable.
! An expression is either a rval or lval, never both !
! An lval expression can bind only to a lval ref (, never a rval ref ) expression
! [P] a rval expression binds to either:
!! a rval reference variable, or
!! const lval reference variable
!! never to a non-const lval reference variable
* a regular variable can appear on RHS/LHS but is always always a lval, never an rval expression.
** a function call is usually an rval expression, but  sometimes an lval expression
* a literal is always an rval expression, since it is not a “place holder” and has no address.
* [P] arithmetic expressions are rval expressions
* [P] subscript expressions and unwrapped pointers are lval expressions. Most common lval expression is the variable name
[P] rval ref variable must bind to an rval expression, never a lval expression!
[P] rval ref indicates the object referenced will be “relocated” soon. Therefore it should bind to temp objects…
E=[[Eff Modern C++]]
I=[[c++for the impatient]]

common string tasks: IV+GTD

(Let’s be imprecise here… Don’t sweat the small stuff.)

We should be able to perform all of these using c-string, std::string (limited adoption since c++98), the standard string in java , c#, perl, python, php. This is a master list. Tolerate multiple names on Each task.

See basic tasks on

use string iterator with STL algorithms

–the easy

convert to vector and apply vector tricks
convert to std::string and apply tricks
count how many times a substr occurs
sort content

positioning yourself for the next tide#Avi, SunLin…

Background: Avichal pointed out ..”knowledge”. To excel in any domain we need mileage, valuable insight, non-trivial experience, and accumulation — non-trivial and doesn’t happen naturally. I have observed it with SQL, Java, Python, threading, trading system design …
Every job change presents an opportunity to reposition yourself. Bear in mind very few jobs put you right at the forefront. Positioning means incremental accu of relevant (often peripheral) knowledge. That’s probably the realistic way to assemble the jigsaw pieces.
You are unlikely to be given an architect role, but look at AOC!

ED-fut to replicate IRS

I feel FRA is the correct thing to replicate IRS…

The LTCM case P13 footnote very briefly described how to replicate IRS using ED futures.

Say we have a vanilla 10Y IRS based on 3M Libor. There are 40 payments, either incoming or outgoing. First payment is 3M after trade date (assuming Jan 1), when BBA announces the 3M Libor for Apr-Jun. Based on the differential against the pre-agreed fixed rate, one party will pay the other.

Here’s how an ED trader replicates this IRS position — On trade date she would simultaneously buy 40 (or sell 40) futures contracts each with a maturity matching those announcement dates.

In both cases, we are sensitive to all the 40 Libor rates to be announced. Each rate is a 3M spot deposit rate.

Lvalue: my definition,incl c++ func CALL

See also post on rval reference

int& foo();
int* p1 = &foo(); // ok, foo() is an lvalue
foo(5) = 42; // (A) ok, foo() is an lvalue. Java doesn’t allow it but does allow …
java ##  foo[5]=42; // (B)

p1  = … //ok
*p1 = … //ok
*(…) = …//ok. Most deference expressions can be L-value expressions

C++ lets you overload the subscript operator i.e. brackets so (B) can be implemented as a shorthand for (A).
C# indexer and property both look like fields of an object (fields are L-values), but both get converted to getter/setter functions. Therefore they don’t refer to memory locations. Therefore an indexer/property can’t be ref or out arguments. They can be used as regular method arguments though, because they are good enough as R-values.

1st theorem of equivalent MG pricing, precisely: %%best effort

Despite my best effort, I think this write-up will have
* mistakes
* unclear, ambiguous points
, but first step is to write it down. This is first phase of thin->thick->thin.

Version 1: under RN measure [1], all traded asset [2] prices follows a GBM [4] with growth rate [5] similar to the riskfree money market account. The variance parameter of the GBM is unique to each asset.
Version 2: under RN measure [1], all traded asset [2] prices discounted to PV [3] by the riskfree money market account are martingales. In fact they are 0-drift GBM with individual volatilities.
Version 3: under RN measure [1], all traded asset [2] prices show an expected [3] return equal to the riskfree rate.
[2] many things are not really traded asset prices. See post on “so-called tradable”
[3] why we need to discount to present, and why “expected” return? because we are “predicting” the level of random walker /towards/ a target time later than the last revelation.  The value before the revelation is “realized”, “frozen” and has no uncertainty, no volatility, no diffusion, and no bell-shaped distribution.
[4] no BM here. All models are GBM.
[5] see post on drift ^ grow rate

don’t use cash instrument in replication strategies

update — use “bank account” …

Beginners like me often intuitively use cash positions when replicating some derivative position such as a fwd, option or swap.

I think that’s permissible in trivial examples, but in the literature, such a cash position is replaced by a bond position or a MMA. I think the reason is, invariably the derivative position has a maturity, so when we lend or borrow cash or deploy our savings for this replication strategy, there’s a fixed period with interest . It’s more like a holding a bond than a cash position.

3c++London bbg algo IV #all about array

Q: given a string of characters, find the longest “run” of any repeating character.

Q: given an array of integers, and a target, determine if there’s any pair that add up to the target. Return true/false.

Q: maximum profit problem. Given a time series of historical spot FX rates, find the maximum possible trading profit by exactly one buy one sell.
A: I have seen this many times. First write pseudo-code.


Q: a vector needs to allocate N instances of Account but Account has no default ctor, but it just works. How does the compiler achieve it? (Actually it won’t compile if compiler can’t synthesize the no-arg ctor)
A: indeed the call to array new would prevent the vector concrete class from compiling due to SFINAE rule or something like that. (Java and c# would use type constraints instead.) The compiler must be using 2 separate lines – one to allocate raw memory, the other to initialize the object.

However, when is vector internal array allocated by array new? I discussed with Ashish but found no answer.

Q: why did you say you needed to write your own smart ptr?
A: super simple one, just to deal with some issue of the raw ptr… probably dangle pointer, by overriding the deref operator

Q: why would anyone use unique ptr when shared ptr is general purpose
A: threading…
A: some pointee objects are designed with sole-ownership

Q: is the lambda functionality doable in c++98? what is the c++98 equivalent?
A: some functor with a challenging syntax I can’t remember.

Q: OK you don’t use c++11 at work, but do you hack around at home?

Q: why is  the bid/ask spread much wider in options than the underlier?
A: must be the risk to the writer. Competition didn’t drive down the bid/ask spread like it did in FX and cash equities.
AA: delta hedge adjustment can’t be done every second. Before the next adjust, the risk to the writer (market maker and quoter) would be quite high.

[15]Eclipse C++11/mingw xp

The default mingw download is too old for c++11. I tried mingw-builds project. Hit some problems. Probably failed to install or something else.

mingw-w64 — I found some workaround using a gcc 4.9 build — good for c++11. This 32-bit version worked in win7 and winxp —\

Note this is not an installer. When I tried the installer of mingw-w64 , it could (!) compile my c++11 code on the command line, but CDT couldn’t detect mingw gcc. Even after I cloned mingw32-gcc.exe, i still faced issues with #include . These are all well-known issues on the internet. Clearly this mingw-w64 installer isn’t better than the 7z download.

Lessons learnt –
* no need to upgrade. If your installation is a few years outdated, it may still work perfectly.
* standard installers may be “proven” for common tasks only, and a non-standard download could be high quality.
* Consistent with my past experience, env set-up is time consuming, esp. on the bleeding edge. In this case, both CDT and mingw have more than a single unified, consolidated release stream. Some users download from stream ABC and follow the versions therein. Other users download stream XYZ. Hard to share technical problems. Many of my installation issues were complicated by this “proliferation”.
* java (and py, c#) are easier since a single vendor releases all the versions

c++ OO vs templates – evolution from C

Am no expert on language evolution, but I feel c++ extends C primarily in two directions — 1) OO and 2) templates (and perhaps 3) exceptions)

Most introductory texts focus on OO. C++ sister (derivative) languages — java, c# etc — focused mostly on enhancing the c++ OO features and only added templates as an afterthought. OO, not template, has been the dominant paradigm since the 90’s. In contrast, I feel the art of template meta-programming feels kind of a dark and dying art.
Compared to OO, I feel c++ template meta-programming is more powerful more complex. Note STL is all template and no virtual function. I guess so are many popular Boost libraries.
C++ OO can become unwieldy (MI, hiding, slicing etc) and was significantly simplified in java. In comparison, I feel c++ template techniques are even more complex.
When a language feature becomes so complex, the number of competent practitioners will remain small. Case in point — threading. Most developers stick to battle-tested threading constructs only. Similarly, most app dev teams don’t bother to create templates except those trivial 50-line templates.
In fact, as of 2013, many active and influential projects are based on C not C++. With respect to language evolution, i don’t think any language has embraced the c++ template meta programming heritage wholesale, and is carrying the torch. Many new languages are more dynamic, simpler to use, and OO. They are based on C or JVM, not c++.

y a Chinese geek prefers NY/Ldn over other financial centers

1) On Wall St, many Chinese techies lament about glass ceiling. Many in their mid 30’s can’t move to leadership. Even if you have talent beyond technical,  even if you invest in non-technical areas, you may hit that ceiling.

Even among those who rose to entry level VPs, there’s a dearth of further promotions. I could be wrong, but i feel 2nd promotion is harder than the first. Indian techies and locals seem to be luckier, causing complaints among the Chinese techies.
Reasons? Factors? Root causes? Many say that in any hierarchical command organization the majority race would dominate the upper echelon, though I notice many exceptions.

Many suggest “inner circle” or “old boy’s club”. Do you get invited for house parties? Are you a fan of Superbowl?

I hear many techies say they prefer non-manager, pure tech roles to people-management roles. Some say the latter is stressful. I guess the former is easier “control-wise”. You finish “your job” and can go home and sleep well.

Some geeks are not keen/ambitious about manager roles, so they don’t feel the pain or the ceiling. So Wall St is perfect for them.

In Asia, a non-manager geek often feels threatened for survival…

2) Wall St (and Si Valley) rewards tech specialists better than other financial centers. Respected, not by some vague gestures or lip service, but by hard cash. See
Remember the 4 stages of Contribution? An individual expert is valued /to the extent that/ she can “contribute through others” — some form of (knowledge) leadership.

3) On Wall St a geek can remain hands-on till 55 or 60. Less age discrimination.
4) the valuable and tough, ground breaking, money-making, really important technical work takes place in the trading hubs like Ldn, NY, or Chicago — Trend setters. If you measure the financial impact of an engineer (outside Si Valley), the hedge funds probably come out top but they employe much smalller number of techies than big banks. Anyway, most of the important work is in the trading hubs — upstream.

invest – high risk, high expected return – HY, currencies

In theory, high risk means high (expected, not historical) return. More specifically, if an asset is perceived as more risky, then investors would demand evidence that it would yield higher return.

Simplest example is the risky bond. Assuming zero coupons, both the junk bond and the gov bond has the same maturity value of $100. Junk bond is shown (Evidence!) to be more likely to default, so the current price is lower, leading to higher expected return. That’s the basic idea of risk premium.

A 2nd example is FX carry trade, like long INR/JPY. INR is expected to depreciate so investors demand higher interest.

Long spot in Turkish TRY is another example. High risk high interest.

Mark Hendrick’s YC rules of thumb, clean n simplified

Mark Hendricks’ lecture on Fixed Income introduced a nice, simplified methods of looking at many important mathematical rules of thumb on the yield curve.
We used only zero coupon government bonds without any call feature.
We used log yield, log fwd rate, log spot rate, log return, log price (usually negative) etc. This reduces compounding to addition! There’s no “1+r” factor either.
As much as possible we use one-period (1Y) loans. All the interest rates quoted are based on some hypothetical (but realistic) loan, and the loan period is for one-period, though it can forward-start 3 periods from time of observation. One of the common exceptions — 5Y point on the yield curve is the yield on a bond with 5Y time to live, so this loan period is 5Y, not one-period.
If the shortest unit of measurement is a month, then that’s the one-period, otherwise, 1Y is the one-period. All the rates and yields are annualized.
Perhaps the best illustration is the rule on fwd curve vs YC, on P4.12.

delta neutral strike FXO, briefly

d1 = 0

Therefore, |put delta| = call delta = N(d1) = 0.5

According to Fang Chao:
call delta = N(d1)
put delta = 1 – N(d1)

Q: is it always true that |put delta| + call delta = 1?
A: I think so, if without dividend. See

well-researched ≠ simple #BS, VWAP..

Some people say vwap is easy/simple, when they really mean it’s well-researched. They mean other benchmarks are lesser-known and more sexy. Actually, implementing algos to beat the vwap benchmark is not easy at all.

Some people say standard option pricing model (BS) is trivial. They basically refer to those fancy models like stoch vol etc. I think this is jargon arms race — “who knows the most jargon”. I feel the intricacies of BS model is well-researched but not simple. Is theory of relativity simple?

Some people say vanilla derivatives are simple (cf exotics). well, lots of publications, but many unsolved problems and unanswered questions.

some people say STL is simple. They probably refer to the fancier containers. I feel STL has lot of details we don’t understand.

Some people say java generics (and c#) is simple. They mean compared to c++. But still there are many design tradeoff and implementation details we don’t understand.