buy-side vs sell-side trader — real diff

buy-side (asset manager incl HF) vs sell-side trader — real diff

Both bet “house money” and keep Positions. See my acid test in What’s the real difference between both? Many friends gave me similar answers — strict hedging (though how strict is questionable — See Barings).

Sell-side trader must delta-hedge her positions. When market moves against her, her bank must be protected by the hedges. Sell-side is part of the “infrastructure” and the financial “services” (buy-side being the service-consumer). Therefore it needs more stability and less risk-taking.

In a volatile environment, a bank is supposed to /survive/ longer than a buy-side. A bank failure triggers deeper /repercussions/ and leads to larger /domino-effects/.

The best-known measure to enforce stability (and reduce risk-taking) on a sell-side trader is a strict policy of hedging. Upper management and regulators want to see VaR numbers and stress test results, periodically.

Effect of hedging should be obvious — risk should be much lower and profit also lower.

Barings didn’t hedge as market makers should. Nick Leeson hated to cut losses when market moved against him. He was acting like a buy-side and his firm failed like a buy-side.

clever use of enum(char@@) in demanding c++ app #Miami

class Der: public Base {…..}

Requirement — we need to down cast a Base pointer. dynamic_cast has overhead.

Der* returnVal = static_cast (new Base) // will compile but is potentially disastrous, because the returnVal can be a partially wild pointer.

Q: without incurring the overhead of vtbl lookup, how do I decide if a pointer to Base given to me actually points to a Base or Der instance?

%%A: type_info still uses vtbl.
%%A: use a Base field to indicate the type. Both ctor will set the field, so the Der ctor will overwrite.
A: enum. If sizeof(aBase) is a tiny 2 bytes, then adding an enum field adds just 1 byte. Adding vptr would add 8 bytes. Big difference if we instantiate billions of this class.

You can also use a char, which is always 1 byte. An enum can be configured to take 1 byte, and have meaningful longer itemized names. has my tested code

custom logger to show src line num, caller, parent caller and grandparent caller

<![CDATA[ /** based on* Class name is mentioned in C:\Program Files\Java\jre1.6.0_06\lib\ */ public class JDKLoggingForamtter extends SimpleFormatter { private final String lineSeparator; public JDKLoggingForamtter(){ lineSeparator = new“line.separator”)); } @Override public synchronized String format(LogRecord record) { String sb = super.format(record); String lineNum = getEclipseFormat(); return sb.replaceFirst(lineSeparator, ” ” + lineNum + lineSeparator); } /** * Returns caller location information in eclipse format eg ( * WARNING Generating caller location information is extremely slow. * It's use should be avoided unless execution speed is not an issue. * * @return the eclipse format */ private static String getEclipseFormat() { // getStackTrace can be expensive StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); String upstairs = “”; int lineNumber = 0; //StringBuilder sb = new StringBuilder(); // Here is an example of the typical stack trace we get back. // level 0 ( getStackTrace // level 1 ( getFileLineNumber // level 2 ( format // level 3 ( publish // level 4 ( publish // level 5 ( log // level 6 ( doLog // level 7 ( log // level 8 ( someMethod if (stackTrace.length >= 9) { String fileName = stackTrace[8].getFileName(); lineNumber = stackTrace[8].getLineNumber(); // Each of these calls back into logger.logp with the appropriate // level and message. This adds one extra level to the stack trace // logger.finest(“finest message”); // logger.finer(“finer message”); // logger.fine(“fine message”); //“info message”); // logger.warning(“warning message”); // logger.severe(“severe message”); // logger.entering(“SomeClass”, “aMethod”); // logger.exiting(“SomeClass”, “aMethod”); // logger.exiting(“SomeClass”, “aMethod”, “returnval”); // logger.config(“config message”); // // Here is an example stack trace from a call to exiting // level 0 ( getStackTrace // level 1 ( getFileLineNumber // level 2 ( format // level 3 ( publish // level 4 ( publish // level 5 ( log // level 6 ( doLog // level 7 ( logp // level 8 ( exiting // level 9 ( someMethod // // We could check the name of the method we are in and only go one level deeper // if it is one of “finest”, “finer”, “fine”, “info”, “warning”, // “severe”, “config”, “entering” or “exiting” but that would be too much trouble. // If the stack is in and we can go one level deeper – do it. if (stackTrace.length >= 10 && “”.equals(fileName)) { fileName = stackTrace[9].getFileName(); lineNumber = stackTrace[9].getLineNumber(); } if (stackTrace.length >= 10){ upstairs = ” = 11){ upstairs += “

%%broad GTD valueAdd cf3Y-younger java programmer

 (Written in 2009)
– i managed difficult teams and difficult customers for years
– real AR experience with perl
– 5 years of Unix system admin experience
– i took part in AR decisions of many projects. 1st-hand AR experience
– I dealt with more diverse challenges of trouble-shooting and problem-solving
– In small projects, I was usually the customer-facing single point of
contact, not working behind the interface person. i was the only one
to negotiate with customer.
– Over the same 3 years, i dealt with many small customers rather than
1 or 2 big customers
– since i took part in more prj over the same 3 years, i witnessed
more failed prj
– i witnessed 1st-hand the “decline” of many technologies — rare xp

computing delta value from BS formula – unrealistic

Delta is the option-valuation change due to a small change in underlier. We are asking “using the BS formula as a prediction of real market, if there’s a $.01 change in underlier, what’s the change in bid/ask of this listed option?”

Assumption — all the bid/ask quoters in the option market use roughly the same BS formula. Obviously unrealistic. I don’t feel this assumption would help make delta a random variable.

Assumption — large number of bid/ask quoters responding to the underlier change. Realistic? I doubt it. Many quotes may ignore the spot change. I guess a small number of dealers/funds might _concentrate_ on a sector and are responsible for a disproportional part of the order book on that option. If they ignore the spot change, then bid/ask will stay constant and delta is 0!

Assumption — no change in i-vol when underlier changes. I feel real players in the market are emotional and may respond emotionally to whatever event causing the $.01 change. These emotional reactions can /effect/ a change in i-vol. I think some trend recognition machines may recognize this small change as part of a trend. I don’t feel such a market response is random.

What if the change is not $.01 but a 2% change?

Assumption — underlier price change is fairly slow and small. Obviously unrealistic. Therefore the change in option bid/ask in response to underlier change doesn’t always follow math model.

More important factor — An option is often held along with an underlier position as part of a strategy. When underlier moves, the holder may want to adjust her option position. One choice is adjusting her option quotes (limit orders). If she is a powerful market maker, then her new quote can move the best bid/ask. Therefore option valuation as measured by mid price may not move according to any math model.

"increase in volatility" can mean 1 of 2 things

An “increase in volatility” actually can mean 2 different things.

@ increase in “historical volatility”, which actually means increase in recent, observed volatility on the Cash market.[1] I feel this is what “increase in volatility” usually means.
@ increase in implied volatility, reflected in higher bid/ask “insurance” premiums on the Options market.

I-vol is forward-looking and refers to predicted future volatility of an underlier (like SPX) over the next 30 days (or 90, or 365 … days). So an increase there reflects people’s anticipation of market volatility.

H-vol is backward-looking and refers to recorded, realized volatility of an underlier (like GBP) over the past few days. When people talk about increase in h-volatility, I believe it’s usually over the Recent past.

[1] if you have an option on futures, then it’s not the Cash market but the futures market, but in this context it’s better to remove this kind of noise and focus on simple concepts.

[11] 4 career(survival)struggles for trading sys developers

Update: now I feel the top 2 survival struggles for me have been techIV vs localSys. I had real pains and set-backs with localSys , figure-things-out, and GTD etc but I am extremely lucky that my techIV advantage is __BIGGER__ than my localSys disadvantage.

Focus here is the trading sys hands-on developer’s career planning. Actually all the stressors here are mild compared to those listed in ## 3 heaviest job stressors

Struggle1: compete for jobs — Without strategies, one can easily get out-shined. The older, the harder. Often the hardest and the one struggle that counts. Recall our 2011-2012 job search… For many the biggest obstacle is CV, while for others it’s IV.

Struggle1b: overcome the “relevant experience” obstacle on the CV beauty contest. No one has track record in every major area. .

Struggle2: survive first 12~24 months — Statistically, most Veterans do survive but it can be a struggle for some. Banks pay 200% for a battle-tested veteran in order to get-things-done quickly. Timeline can be extremely demanding and pushing the human limit. Long hours. Can affect health, stress on everything including family. I was told developers in Asia face additional challenges.

Struggle2b: gain insight, create truly superior designs, add long term value — in addition to get-things-done. Not necessary for survival, but fulfills the promise of an “elite” expert developer. Caliber and Differentiation — Sets you apart on the job.

Struggle3: stay marketable long term — either in this or in another job market.

Struggle4: move up. Statistically, I guess most developers move into leadership roles but it doesn’t always come to you automatically.

Methods are implemented as Fields — function pointer Fields

(It would be great to go back to the earliest OO language, but let’s just start from C++.) The class concept is very similar to the C struct. Now if you add a func ptr as a struct field, then Whoa! A method is born (Today happens to be Christmas…)

Note python treats both fields and methods as “attributes”.

Suppose your struct is named MyStruct and has methods m1(), m2(). You may need to add a pointer-to-MyStruct as a hidden field (named “this”) to MyStruct. You have to pass “this” to m1() as a first argument. Consequently, m1() can reach all the fields of the host MyStruct INSTANCE. Without such an argument, m1() doesn’t know which object it belongs to. Remember all C++ methods are free functions in disguise.

Let me repeat — each method has the same first parameter of type (HostClass*)

That’s the basic idea of a c++ class, but we need some efficiency improvements. If you instantiate 999 instances of MyStruct, then are you going to allocate 999 func-pointers for m1() and 999 func-pointers for m2()?

No. I think you can just add a single pointer-to-MyStruct-class-object as another hidden field to MyStruct. In the singleton MyStruct class object, you keep the addresses of m1() and m2(). Therefore, ARM said the struct instance holds no info about m1().

The vtbl is also part of this singleton object.

Note java puts MyStruct class object in the permanent generation.

Another optimization is where to stored the “this” pointer. Brutal force solution is to add a ptr-to-MyStruct field to MyStruct but  C++ and java compilers all avoid this. I think the compiler treats “this” as a pointer Variable not a pointer Object (like vptr). Implicit conversion —

    myStructInstnace.m1(otherArgs) // becomes
    m1(&myStructInstance, otherArgs); // [aaa]

The [aaa] form isn’t really what compiler does. In MultipleInheritance “this” isn’t the same across Base objects and Derived object.

OO scripting languageS

I see more php developers create classes than Perl developers. I guess python developers are even more likely to create classes. Every language claim to support OO, but the litmus test is how easily (and how frequently) developers create user-defined classes.

(In the same vein, C++ template is a another thing regular developers have not fully embraced. Java generic class is yet another.)

Unlikely Java/c#, these scripting languages won’t deliberately make your life difficult if you don’t “embrace” OO.

Compared to perl and php, I feel python OO is simple, clean and “full-service” (not in the call-girl sense:). Incidentally, built-in python “features” are more object-oriented than in perl and php.

However, I still feel many python applications tend to be more procedural than OO. When facing a choice, I guess many developers feel procedural is simpler even thought python OO is not complicate. If a simple tool does the job, then no motivation to change.

What about multi-module team development? Look at perl and C projects. Many team still stick to procedural.

the odds of 3 (or more) dice add-up

A lot of probability puzzles use small integers such as dice, coins, fingers, or poker cards. These puzzles are usually tractable until we encounter the *sum* of several dice. has a concise treatment on the probability when adding up 2 dice or 3 dice or 4 …..

The same _thought_process_ can help solve the probability of X + 2Y + 3Z, where X/Y/Z are integers between 1 and 10, i.e. fingers.

Basically the trick is to construct the probability function of 2 dice combined. Then use that function to work out the prob function of 3 dice, then 4 dice…. Mathematical induction.

Compared to integers, continuous random variables are harder, where the “dice” can give non-integers. Prob of sum of 2 continuous random variables requires integration. While clever people can avoid integration, 3 (uniform, independent) variables are perhaps tricky without integration. But I don’t feel many probability puzzles ask about 3 random real numbers summing up.

As a layman, I feel the best aid to the “continuous” probability is the integer result above.

who sells/buys quant algorithms and strategy

Q: what exactly is advertized, sold and implemented when we see a big bank (like GS) selling a quantitative strategy/algorithm/model?
%%A: trade signals/algo/intelligence, execution service, and trade “sponsorship”

On the buy-side, traders namely “account owners” are always users of a quant algo. I believe Retail traders or institutional traders receive trade signals from the algo (owned by the sell side) and can either ignore it or follow it.

Q2: Physically where is the trade signal generated?
%%A: either in the sell-side system or in the buy-side system These signals are never guaranteed to be profitable. Just imagine you are using your hard-earned savings to trade. Trade signals might contain size, order type (mkt order or limit order or OCO…), and price. Actually, There are resellers for this “product” ie trade signals. A small broker can be the buy-side of an algo vendor, and the sell side to its own retail clients. The algo is the IP of the algo vendor. The same vendor may also provide market data, or DMA, smart order routing …

Q2b: can a client take the signal and trade through another broker?
%%A: i believe she won’t be able to profit from it. The vendor will make sure you route your orders to them. Assuming signal is generated in the sell-side system, then you probably pay for the signals.

In a complex multilateral set-up, always ask
Q: which entity makes trading decisions?
%%A: probably not the algo vendor

In contrast, the block-trade deal is simpler. Trading decisions are made by the sell-side (say GS), on behalf of the buy-side (say Metlife). GS might be the counter-party to Metlife or just a middleman. If GS routes the order to CBOT, then GS sponsors the trade. See

who moved my cheese #extend pre-retirement

I read it 5 years ago. A powerful metaphor for our long term survival as individuals, as a profession (say software engineers), as a company, or as a nation…

When our cheese disappears, too often we try so hard to understand the “who” but (as the book author hinted) maybe we need not… Instead, we could focus on how to better identify long term trends and threats, how to strengthen our long term competitiveness, how to adapt ourselves to changing (and challenging) landscapes…

Some of the cheese-disappearances I perceive —
* Wall St big bonuses — disappearing
* Wall St big base salaries — investment banking business decline, or seismic changes eroding their profitability. High profit margin is (IMO) the key reason for the high salary.
* inequality of Wall St vs Main St, and the unfair advantage of “high finance” over other communities
* non-threaded programming — multi-processor machines and slow displacement of traditional programming
* sybase, weblogic/websphere, solaris  — more open source solutions adopted in finance such as mysql, jboss ..
* IT contractor as a profession — will they disappear?
* Aged-55 or older programmers — will they disappear as in Asia?
* comfortable retirement at age 60 — I fear more people will be forced to work till older age, because the traditional source of retirement income is under threat and becoming unreliable.
* onshore IT jobs in finance — even more of these jobs moving offshore?
* dominance of US dollar
* Singapore's geographical advantage as a transit port
* java as a language — in some areas, java is losing pole position
* SQL as a language — I see more alternatives like SecDB, google BigTable, NoSQL, gemfire/tangosol. They don't completely replace SQL but eclipse its dominance. In one of my projects, a in-house xml document store is the main data store. SQL was not selected as a solution.

If we think hard about cheese-disappearances, we may realize some things somehow won't disappear. Perhaps the WHY isn't the only thing important. I do think it's good to seek patterns.
= option mathematics — still underlying the pricing, risk-management and trading of most derivative instruments
= derivatives — some people predict derivatives trading will decline and shrink
= c/c++
= SQL — yes SQL again. This language has withstood so much competition and criticsm but remains dominant so far.

hist-vol calc using price relatives – right vs wrong ways #Piroz

(See also post on var swap PnL)

You asked me how historical volatility is computed from daily closing prices. There’s an over-simplification in my answer.

Suppose we have daily closing prices

Day 1) p1 = $30.00
Day 2) p2 = $34.50
Day 3) p3 =…
Day 4) p4
Day 5) p5

First compute p2/p1 as PR2 (price relative over day 2), p3/p2 as PR3… p5/p4 as PR5. I was CORRECT here.

Then we SHOULD compute the Natural log of PR2, PR3, PR4 and PR5. These natural logs are known as “continuously-compounded-rate-of-return” or un-annualized “daily-realized-vol”, and are denoted r2, r3, r4, r5. I missed this step.
These r2, r3, r4, r5 look like low percentages like 8.2%, 3.1%, 4%, 15%…
Realized volatility is defined as standard deviation of these percentages, usually assuming zero mean. I was right at this step.
Since the r values look like percentages, so does their stdev.

There’s also a capital “R” denoting (PriceRelative-100%). Since PR2 = 115%, so R2 = 15%. R is widely known as “Return”, return on investment, or investment return etc.

R2 is always slightly above r2 = 13.9762%. For small price movements, R is a very close approximation of r.
My oversimplification was to misuse R in place of r.

I have since verified my calc with an ex-quant and developers at a volatility trading desk.

segments to form a polygon

What is the probability that a stick of length 1 divided randomly into 3 parts can form a triangle with the three parts?

& then, General Bonus asks u…Soldier, what’s the probability that a polygon with (N+1) sides can be made from (N+1) segments obtained by randomly dividing a stick of length l into (N+1) parts?
You gave me the probability formula . Here’s my explanation —
Suppose we mark a circle’s 12 o’clock position with “0”, 3 o’clock with 90, 6 o’clock with 180 etc. So each position on the circle has a unique number from 0 to 359.999999999.
We put N+1 random dots (all at once) on the circle’s circumference, creating N+1 segments. (If any segment exceeds half the circle’s circumference, then we would fail to form a polygon.)
Rotate the clock to align 12 o’clock position to any random dot. Break the circle at that dot (and losing that dot). Now we have N dots and N+1 segments.
Now we color the segments. Say black segment is first from the 12 o’clock position, 2nd is red segment.
P (black segment exceeding half the circle) = P (all N dots landing beyond 6 o’clock position) = 2N
P (red segment exceeding half the circle) ? Now keep all the dots and the colors. Rejoin the circle. Rotate it by the length of black segment. Break circle there. Now red segment is the new 1st segment. P (red segment exceeding half) = 2N
There are N+1 segments, so P (any segment exceeding half the circle) = (N+1)*2N

tibrv is decentralized, peer-to-peer, !! hub/spoke

JMS unicast topic has a centralized [1] broker. RV is decentralized. All the rvd processes are equal in status. This is a little bit similar to
– email servers among Ivy League universities.
– file-sharing peer networks

RV is peer-to-peer; JMS is hub/spoke. Note in JMS request/response, “server” has ambiguous meanings. Here we mean the broker.

[1] You can load-balance the broker but the “outside world” views them as a single broker. It’s the Hub of hub/spoke. Scalability bottleneck.

talent + attitude = great developer

In your gym, we discussed that some developers could be very sharp, knowledgeable, analytical, fast-thinking, fast-learning, but most of these developers don’t achieve the greatness like the achievement of your “Hibernate” colleague. I can think of a few other “great” achievers.

– A Citi developer who built the pricing engine almost single-handed, with so much logic thrown in. Perhaps design wasn’t great, but this engine works — no mean achievement given the tons of functionality. There’s so much logic that it took initially 2 developers and later 3/4 full time guys to support it. (One of the guys said this implementation is overcomplicated.)

– A ML manager who knows the entire trading engine (execution, offer/bid, RFQ, PnL, pricing, ECN..) inside out. The other 4 full time developers under him can’t support the app as well as he can by himself. When he is on leave for 2 weeks, we worry about if production issues will stay unresolved.

It takes more than talent + diligence to achieve greatness. For one thing, the guy must spend a few years dedicated to researching and experimenting with the core parts of the system, without cold feat. In my GS team, everyone did this. Outside of GS, i don’t see many doing this sort of hardcore inside-out system hacking, which is mandatory to mastery. Typically it takes 3 (up to 5) years to become a master, but the great developers take 25% of the time. They focus, they work (much) harder, they go deep — fearless and relentless. They seem to (quietly) believe that they “can do it” in 25% of the time, and they stick to the timeline and finish it. Determination, confidence, commitment and drive — common qualities of a few of my team leads.

They also must know when to give up on something hopeless, fruitless, worthless, or something with poor cost/benefit ratio. Without this critical Judgment, one would invariably waste time in all kinds of situations, and lose momentum, lose opportunities, lose management support, lose confidence. I believe the few great achievements I know are all achieved with a tight deadline. Wasting time is deadly. Great developers must know how to identify and avoid deathly traps.

Almost always, they also need to work with many others to finish a big task quickly, so some people skill is required, to varying degrees. I’m not good at analyzing this so let me skip.

Needless to say, none of these qualities are testable in an interview. Everything can be faked up. Therefore I believe it’s impossible to identify powerful achievers by job interview.

trade volume/quantity stats

trade size:

20,000,000 shares is not uncommon for a single equity cash or equity swap order.

LINQ predicate delegate ^ boolean functors in STL shows a nice usage of delegate —

One such (functional programing) technique is to use them for filtering sequences of data. In this instance you would use a predicate delegate which accepts one argument and returns true or false depending on the implementation of the delegate itself.

using System;
using System.Linq;
using System.Collections.Generic;
class Program{
  static void Main() {
        List names = new List {
                "Nicole Hare",
                "Michael Hare",
                "Joe Hare",
                "Sammy Hare",
                "George Washington",
        // Here I am passing "inMyFamily" to the "Where" extension method
        // on my List.  The C# compiler automatically creates
        // a delegate instance for me.
        IEnumerable myFamily = names.Where(inMyFamily);
        foreach (String name in myFamily)
    static Boolean inMyFamily(String name){ // unary boolean functor
        return name.EndsWith("Hare");

misleading PnL graph – short option positions

PnL graph of short option position is misleading. Both call/put show a inverted hockey stick indicating huge potential loss when price move against option writer — when writer gets assigned (at or before expiration). Let's assume the writer wrote an OTM call/put, earning the premium.

Reality is, many option writers don't mind assignment.

A long term bull writes an OTM put, below spot, and doesn't mind buying at that slightly[1] low price, because she wants to buy it anyway and now she gets to buy it at a better/lower price! If you are long term bullish then you want to buy it anyway, so now you just need to hold it for a while. PnL graph shows a huge paper loss, but a long term bull won't liquidate and realize the paper loss. So the PnL graph is misleading.

[1] Usually an OTM put is slightly below spot. Most positions and trades are concentrated near ATM.

———— That's PUT. Now calls ———————

A long term bear writes an OTM call (like a “get a beer for $99 with this coupon”), above spot ($88), and doesn't mind selling $99, unless she is forced to buy it from open market at a sky high price. This unlucky scenario is uncommon because —
* PnL graph shows a huge loss assuming writer has to buy from open market, but many (if not most) OTM call writers are buy-writers, so they already hold the asset. If they end up selling at $99, they don't lose. Remember spot at the time of option sale is $88, so they sold a good price.
* stocks are less likely to rise sharply than drop sharply.

Also, a long term bear wants to sell the stock anyway. Now she gets to sell good price.

Lastly, don't forget the premium income.

full time retail traders #my take

(a blog post)

Whenever I hear someone is play the stock market or FX market full time, I wonder if this person has any stable income. Do you know any FTRT having a stable income?

It’s not uncommon to see a “winning strategy” that makes money for months even years, then suddenly suffer a big loss (or losses) that wipes out all the gains.

Some seasoned players (including day traders) accumulate many small gains. They take fewer risks. But I was told they too can suffer a big loss that wipes out all gains. (Personally, in 1997 I was a newbie trader taking small gains every day, but someday market opened with a drastic move, big enough to wipe out 100 small gains, fast enough to leave me no time to react.)

In all these unlucky stories, the annual average income of this FTRT is close to $0, when US median household income is around $55,000. This guy can’t even pay his bills!

These are retail traders, but how about investment banks? Investment banks typically make money from less unpredictable businesses — asset management fees, IPO fees, M&A advisory fees, stock lending, pass-through brokerage (commission based). In bond trading (and single-name stocks?), they tend to monopolize an entire market for an issuer — low chance of losing control, but still can lose control…

Market making is more risky for an i-bank, but should be less risky than our FTRT. The reason why market making is less risky is presumably due to systematic and disciplined hedging.

For an i-bank, the real risky business is prop trading. Apparently big banks suffered big losses just as badly as the FTRT. But I think banks often make big money for many years, then lose, so if you average their PnL, i think it’s positive. (However, some funds declare a negative average PnL, such as the hedge fund started by Citigroup CEO Vikram.)

Compared to investment banks, hedge funds have an /backdoor/ option known as “close down” — All the investors’ money is declared as lost. Effectively, traders use OPM (other people’s money) to gamble. If he’s lucky, he profits; if he bets wrong, other people lose money and he disappears, completely. In contrast, big banks often has to hang in there because it has other businesses to prop up. A family man vs an orphaned bachelor…

In conclusion, FTRT is a dubious concept to me. Big players do employ full time traders because they have more influence on specific markets they choose to play. Still trading full time with one’s own money is highly risky.

if given binary + asset-or-nothing call prices…

There’s something intuitive (and therefore important) in this scenario –

Suppose we know the current prices of
– binary call (B) on an asset like IBM stock
– asset-or-nothing call (denoted A) on that asset

Q: What can we say about the vanilla call current price?

First, remember binary call must be worth between $0 and $1 before maturity, since the
payout is either $0 or $1. In contrast, asset-or-nothing call has current value comparable to current asset price.

It’s useful to use concrete numbers, like K=$15, exp(-rT) = 0.8 …

Consider a portfolio { A – K*B } i.e.
++ long 1 unit of asset-or-nothing call
— short K (i.e. 15) units of the binary call. Note even if there’s a discount factor of 0.87 from maturity to today, we still go short K units.

If expired … easy. If (both) exercised, we end up with 1 unit of the asset, and we owe someone $15.

In a way, the (current prices of) A and B reveal the crucial N(d1) and N(d2) values as of today.

This replicating portfolio needs no rebalancing.

recombinant binomial tree, price relative and lognormal

I find the recombinant/interlock concept a nice simplification. I was told in practice, all pricing btrees are interlocked – much easier without loss of generality. wikipedia says

“The CRR method ensures that the tree is *recombinant*, i.e. if the underlying asset moves up and then down (u,d), the price will be the same as if it had moved down and then up (d,u) — here the two paths merge or recombine.”

Often (u,d) will 100% cancel each other. At each tiny step, either

newPrice = oldPrice * u (typically 1.0101010101010101) or
newPrice = oldPrice * d (typically 0.99)
u * d == 1

Note the standard definition of u and d [[CFA]] as __PriceRelative__ of day2closing/day1closing. (Useful in h-vol…)

For a simple example, u = 2, so our underlying price either doubles or halves at each step. Same result if it double-then-half, or half-then-double. Consistent with the lognormal model…

Warning: many texts use illustrations of u=1.01000000000, d=0.99, which violates lognormal assumption but still recombinant…

In binomial tree, the next value of u is kind of random. In other words, the multiply factor could change from 2.0 to 1.01 to 1.002… usually just above 1 if step is small.

More precisely, u is computed using the underlying volatility, σ, and the time duration of a step. In a complete model, the pdf of random variable “u” can be derived.

Q: in industry, are most binomial trees recombinant?
%%A: I think so.

upper bounds on vanilla call/put prices

Background — needed in many quant simple quizzes, or appetizers. There are lots of intuitions involved.

— The easy part — lower bounds —

call – $0 or the fwd contract’s price i.e. S_now – K*exp(-rT)
put – $0 or the short fwd i.e. K*exp(-rT) – S_now

— Now the upper bounds —

put ~ K*exp(-rT). Consider a super replicating {K bonds}.
call ~ S_now i.e. the current stock price itself. Consider a super replicating {1 share}. At expiration, the stock dominates the call, ditto before expiration.

diffusion start and variance

This is one the many nitty-gritty pitfalls.
Black Scholes assumes a lognormal distribution of stock price as of any given future date, including the expiration date  T —
log ST ~ N( mean = … , variance = σ2 (T – t) )
This says that the log of that yet-unrealized stock price has a normal distribution. Now, as the valuation time “t” moves from ½ T to 0.99 T (approaching expiry), why would variance shrink? I thought if the “target” date is more distant from today, then variance is wider.
Well, I would say t is the so-called diffusion-start date. The price history up until time-t is known and realized. There’s no uncertainty in St. Therefore, (T – t) represents the diffusion window remaining. The longer this window, the larger the spread of diffusing “particles”.
By the way, the “mean” above is      logS0 + [(mu – σ2/2)(T-t)], where mu and σ are parameters of the original GBM dynamics. 

learning design patterns #letter to Mithun

Another thing about design patterns – each author has a different description.

Some describe it in 2 paragraphs or a 10-line example using one dog/cat class. Others write 3 pages and 5 classes. Yet others write a whole chapter on it in a design pattern book.

If I go by the simplistic interpretation to describe a pattern, then the interviewer may think I don’t really know it.

If I give an in-depth example, then it could be too complicated to describe (I’m not extremely good at describing complexity) and interviewer may not be an expert on that pattern to understand me.

My suggestion is to focus on 1 or 2 patterns. Understand them inside out and also remember some simple examples in your own app. Our knowledge of a pattern should grown from thin to thick to thin, yes back to thin. Only when we have a streamlined understanding can we describe it with clarity.

Here are some complex patterns I have struggled with for years – visitor, bridge, strategy, composite, chain of command, memento, command, observable …. Each of them can be summarized in 1 paragraph, but let’s be honest – these aren’t simple.

make your app self-sustainable Af you are gone

I always hope that my app can run for years after I'm gone, not get killed soon after. Here are some realities and some solutions.

If your app does get killed soon after, then it's a management strategic error. Waste of resources.

For a 6-month contractor on wall street, it's quite common for the code to be maintained by an inexperienced guy. Knowledge transfer is usually rather brief and ineffective. (“Effective” means new maintainer runs the app for a few cycles and trace log/source code to resolve issues independently, with author on stand-by.)

All your hacks put into the code to “get it to work” are lost with you when you are gone.

Tip: really understand the users' priorities and likely changes. Try to identify the “invariant” business logic. The implementation of these core logic is more likely to survive longer. Probably more than 50% (possibly 90%) of your business logic aren't invariant. If really 90% of the logic isn't invariant, then requirement is unstable and any code written by anyone is likely a throw-away.

Tip: thoroughly test all the realistic use cases. Don't waste time on the imaginary —
Tip: don't waste time writing 99 nice-looking automated tests. Focus on the realistic use cases. Automated tests take too much effort to understand. Maintainer won't bother with it since she already has too much to digest.

Tip: use comment/wiki/jira to document your hacks. I don't think high-level documentation is useful, since developers can figure it out. Since time is very limited, be selective about what constitutes a “hack”. If they can figure it out then don't waste time documenting in wiki. Source code comment is usually the best.
Tip: get new maintainer involved early.
Tip: pray that requirements don't change too much too fast after you are gone.

N(d2) interpreted as a (Risk Neutral) probability

Under RN measure, underlier price process is a GBM

  dS = r S     dt +     σ S    dW
denoting L := log S
  dL = ( r – ½ σ2 )  dt +     σ    dW         …… BM, not GBM. No “L” on the RHS !
Therefore, underlier terminal price has lognormal distribution

  log ST ~ N(logS0 + T(r – ½ σ2)    ,    Tσ2 )  or N (mean, std^2)
Now, Pr(ST > K) simply translates to Pr(log ST > log K)  …. normal distro math! It’s now straightforward to standardize the condition to
  Pr ( (log ST – mean)/std  > (log K – mean)/std )
=Pr( z > [log K – logS0 – T(r – ½ σ2)] / σ sqrt(T) ) ….. which by definition is
=1 – N ( [log K – logS0 – T(r – ½ σ2)] / σ sqrt(T) )
Now be careful. 1-N(a) = N(-a), so that Pr() becomes
N([    –  [log K – logS0 – T(r – ½ σ2)] / σ sqrt(T) ) = N(d2)
For d1, recognize that under Share-measure,
dS = (r+σ2) S     dt +     σ S    dW
dL = ( r +σ2 – ½ σ2 )dt +σdW  …simplifying to
dL = ( r        + ½ σ2)dt +σdW  …differs from earlier formula (RN measure) only in the “+” sign

log ST ~ N(logS0 + T(r   +   ½ σ2)    ,    Tσ2 ) …… notice the “+” sign in front of ½ σ2
Therefore under share-measure, Pr (ST > K) = N(d1)

c# struct, java bean, propertySet

Data bundles are extremely common, perhaps inevitable — domain models; DB records; GUI data-transfer-objects; POJO…

Struct is the C solution. Every field is read-writable. One special feature is sizeof(myStruct) — all the fields live contiguously.

C# (more than java POJO) classes enhanced the struct idea to let you customize the getter and setter operations on each field…

In c++ quant library, propertySet/propertyPage is a major enhancement….

commercial banks(like ibanks) can create stress on central bank is an enlightening article.

A regulated savings bank (Say BS-Bank) is a private company but a “privileged” company. Privilege is granted by the central bank (tax payer funded) because of the “public service” nature of this company.

The privilege is a huge guarantee (by the central bank) that if careless loan officers give out many bad loans and lose 99% of the money at BS-Bank, retail depositors will be 100% “covered” by central bank when they withdraw.

To understand the rationale, let’s understand the basic risks facing a bank. Suppose BS-Bank takes in $5B deposits and lends out $25B (fractional reserve banking). If depositors panic and queue up to withdraw, BS-bank runs out of cash. As soon as it fails to hand over a single cent demanded by a depositor, BS-bank is considered insolvent and bankrupt. Such things happened in the 1930’s. Since then, most governments provide that guarantee.

A bank is providing a “public service” — collects deposits from the public and lends out to home buyers, students, small local businesses, local and central government bodies… Therefore, Government feel the need to prop up all such banks. Note investment banks aren’t banks.

The irony in the guarantee — As a private company, a greedy and chaotic bank can take excessive risks, but tax payers (through the central bank) bear the consequences. “taxpayers will provide a buffer to absorb the banks’ losses”, says the BBC article. That’s why these banks are regulated, but I don’t know how effectively.

You might ask how the central banks can “absorb” all the losses. Well it can create money out of thin air and lend to the bank. No free lunch — currency devaluation; inflation; more Treasury bond issues; higher interest cost to the government; ..

Now I know both unregulated investment banks and regulated commercial banks can create stress on central banks.

In 2008, Singapore government basically extended the guarantee beyond retail to all depositors of Singapore based banks.

JNI stack memory — my new answer

Someone asked me about memory organization in a JNI runtime. I said the java stack and C stack sections are distinct. Then I occurred to me that in most cases the java thread extends Into the c stack. See

However, I still feel my answer was correct because C can spawn new threads, perhaps in response to a call from java.

On a 2nd, unrelated, note — there can be (daemon or timer) C threads unrelated to any java thread.

Java stack can hold pointers to java heap objects, and C stack C heap objects. I don’t think they cross-reference. Consequently, the 2 stack sections are logically distinct.

trading systems – corp ^ muni bond

^ yield curve — based on Libor vs tax-exempt curve
^ stock-based hedging — less in muni
^ preferred stock — is traded in the (longer-term) corp bond desk, but no such thing in muni
^ corp bond — dealers specialize by issuer whereas muni dealers specialize by state. Each trader is licensed by that state and only sells to residents of that state.

^ Bond.Hub, tradeWeb, marketAxess vs JJKenny, TheMuniCenter, Hartfield

code change while switching JDBC library@@

When a new vendor implements JDBC api, they create classes implementing the PreparedStatement java interface. They ship the class files of new PreparedStatement classes. They don’t need to ship PreparedStatement.class which is a standard one, unchanged. Suppose i want to change my java app to use this vendor, I need to make exactly one SC (source code) change – import the new PreparedStatement class. Note we make no more and no fewer SC changes. That’s the the “state of the art” in java.

The C solution to “API standardization” is different but time-honored. For example, if a vendor implements pthreads, they implement pthread_create() function (and structs like pthread_mutex_t) in a new .C file. They ship the binary. Now suppose I want to change my working C application and switch to this vendor, from an older implementation…

Q: what SC changes?
%%A: possibly none. (None means no recompile needed.) When I compile and link, I probably need to pull in the new binary.

Q: Do they have to ship the header file?
%%A: i don’t think so. I feel header file is part of the pthreads standard.

Now the interesting bit — suppose I want to use a vendor with small extensions. SC change is different — include a slightly different header file, and change my thread function calls slightly. If the SC changes are small enough, it’s practically painless.

Now we see a real-world definition of “API” — If a vendor makes changes that require application SC change, then that impacts the API.

For java, the API includes all members public or protected. For C, it’s more about header files.

basic skills of a quant developer

trec – VBA, excel
trec – c++Excel integration using COM
trec – MSVC, “required” for COM (excel) integration
trec – visual studio — probably the #1 IDE on windows
trec – c++ debugger
trec – implemented pricing algos
trec – programmed matrix and vector
trec – back testing 
jargon – can describe popular pricing algo and related jargons
jargon – property sets

goldStandard#2:central banks2control FX rate

Q3: For a freely traded currency, how does the CB (central bank) rescue it?
A: basically CB need to spend their “reserve” to buy their own currency. There might be other means (capital control…), but this is the primary means.

Q3b: can this CB ask another CB (say Chinese CB) to help?
A: yes but the other CB must spend its reserve too. Nothing free.

When a currency is under pressure, hedge funds basically assumes [1] CB has limited capacity to save it. Note a CB can’t easily print money. Under attack, a CB has no legal power to print other country’s currencies. If CB prints its own, it weakens further. In other crises, printing money also has serious consequences. Printing money is a sign of hollowness and desperation. Investor Confidence!! Investors (domestic/foreign) will sell or short-sell the currency.

Gold-standard is good simplification with educational value…

[1] (Exception to that assumption) Central banks of smaller economies often protect their currency with another form of “gold standard” — dollar-peg backed by foreign reserve — basket of hard currencies. A hard currency refuses to weaken “randomly”, because that CB has reason and “gold reserve” to maintain it….

“Gold” standard prevents a run on the currency. Remember each SGD owned by a foreigner is a “claim” on Singapore’s reserve. If there’s obviously enough reserve, then no basis for a run.

Gold-standard obviously forbids lavish money-printing.

Gold-standard is a discipline on gov spending, productivity, export growth, wage control, inflation …

“Gold” standard shows why US trade deficit means more dollars flowing to China (claim on US gold…) so “effective US gold reserve” shrinks and dollar holders worry about that reserve — since Fed may print money and devalue the dollar.

“Gold” standard debunks the naive impression that a CB can freely raise the value of its currency so its citizens become richer when visiting overseas. Without discipline, a CB can print money and deposits to citizens’ bank accounts, but immediately purchasing power drops.

“Gold” standard is the simplest (simplistic but fairly true) explanation why hard currencies forex rate appear to be “anchored” despite gigantic daily trading volumes. The anchor is the “gold reserves”.

Gold-standard illustrates the fundamental impact of import/export on forex rates. Does private import/export go through CB? I think it does since the currency used to pay for import ultimately comes from CB. (However money earned by export may not go back to CB! )

Gold-standard clarifies that private bank lending can’t increase money supply as a CB can…

“Gold” standard answers the FAQ why everyone somehow believes paper money represents real buying power.

“Gold” standard sheds lights on how paper money is “backed” by CB…