simple solution to a simple Markov chain

MarkovChain1.png

Suppose there are 10000 particles. In the steady state, a number of them (say U) are in Bull state, a number of them (say E) are in Bear state, and R are in Recession state. They add up to the total population of 10000. Let’s find the values of U/E/R, i.e. in the steady state, how many particles will be in each state. Note unlike most MC problems, there’s no absorption in this problem.

After one step, all the particles each decide its next state, according to the transition probabilities. 2.5% of those in Bull state would change to Recession, while 90% of them would remain  in Bull.

0.025 U + 0.05 E + 0.5 R = R ….. one of 3 equations. 3 equations and 3 unknowns. U is found to be 6250, E = 3125 and R = 625

But why the ” … = R” part? Answer is the steady state. After one step, if 0.025 U + 0.05 E + 0.5 R is 0.000001% more than R, then this is not steady state and the R population will increase at every step and it would capture all 10000 particles.

java method taking a single argument but 2 alternative types

Requirement: method read() in an interface IReader needs to accept a single argument but of various types

read(Book b) to be implemented by one concrete class BookReader
read(Score s) to be implemented by another concrete class ScoreReader

Suppose we want to unify the 2 read() methods into one unified method, so a “client” can get an instance of Reader and simply pass in either a book or a score. C# probably has language support for this, but in Java …

Solution 1: use Object argument

Solution 2: declare
read(T content, Class argumentClass);

BookReader.java implements
read(T content, Class argumentClass){
if (content instanceof Book){….
}

Paradoxically IDE may warn you that argumentClass is an unused variable inside the method. However Compiler use it to enforce type safety —

myReader.read(someBook, Integer.class);// won’t compile. Book.class required

vega of a vanilla IRS?

Q: if Libor interest rate volatility moves by a tiny bit (for eg from 22% to 22.1%), how much would a long IRS position’s current PnL change?  To keep things simple, consider a IRS with a single payment at the end of 2013.

Jargon — Long position is the fixed-payer’s position, who stands to receive the floating payments. See http://bigblog.tanbin.com/2011/01/going-long-on-libor-means.html

%%A: I feel this is similar to a long position in Gold futures. You have already agreed to pay a fixed price of $9000 for the asset. The asset you have bought may have a market value higher or lower today, tomorrow and and on delivery date. Futures exchange uses end-of-day mark to market to issue margin calls… Very familiar.

Now, how about vega? I feel a Gold future has no vega. I think it’s delta-1. When the Implied[1] vol of gold moves from 22% to 22.1%, the gold futures position doesn’t undergo a definite amount of MV change. It can dip or surge or stay flat.

Similarly, I would assume an IRS long position has no vega.

[1] Note vega is measured against Implied vol, not realized vol.

weekend IV – Ab Initio

Which project has the largest data volume and complexity?

How do you usually implement xml transform — in java or using stylesheet?

How do you manage both latency and throughput?

What’s the level of latency you deal with — micros or millis?

(Real time fraud detection 2000 transactions/sec, with millis latency.)

How do you diagnose latency issues?

How do you measure latency?

If you use simple logging technique to record latency, then how do you minimize the latency added by logger itself?

In-memory databases — how do you manage the disk read/write.

time-series databases — how do you query them?

Complex data analysis — use RDBMS or implement in java?

Experience with http://en.wikipedia.org/wiki/OLAP_cube?

Experience with SybaseIQ?

Many real world data processing systems receive xml messages, process it in DB then send back an xml reply. How would you deal with this? XSL transform is slower than parsing in java. I feel xml transform needs to traverse the entire xml tree, so it needs the DOM tree, which is slower than SAX parser.

Present a past project with parallel processing, large volume, possibly async messaging, good latency and throughput.

IV – local volatility – OCBC

Q: tell me 1 or 2 low-latency challenges in your projects.
Q: what’s a variance swap?
Q: what’s your favorite messaging vendor product? (MQ is firm standard but too slow for this team.)
Q: Where do you get your implied vol numbers? From exchange or you do your own inversion? (I guess exchanges do publish quotes in vol.)
Q: how many tenors on your vol surface?
Q: how do you model term structure of vol?
Q: how do you perform interpolation when you query the vol surface?
Q: you mentioned various vol models (taylor, cubic etc) but how do you decide which model to use for each name?
Q: describe BS equation in simple language, and what are the inputs?
Q: FX vol is delta sticky. On X-axis you see 25 delta, 10 delta, atm vol etc. How about eq?
Q: any example of structured vol products?
Q: what’s dv01?
Q: which asset class are you most comfortable with?
Q: in your systems there are often multiple languages. How do you make them interoperable?
Q: what’s java generic?
Q: value type vs reference type in c#
%%Q: who will validate the prices and decide if it’s a reasonable or valid price?
A: traders. Even though they aren’t fully trained as quants are. Some managers also have pricing knowledge. Perhaps no real quants.
———
Q1: what’s fwd vol vs local vol?
Q: you said variance is additive? Can you elaborate?
Q: have you heard of total variance?
Q3: what’s put-call parity?
%%A: C + K = P + F. Each of the 4 can be synthesized using the other 3

Q3b: can you show me one synthetic portfolio, say a synthetic long call?
Q: Can you explain PCP in terms of deltas?

Q: you mentioned code bloat due to c++ templates, so how does c++ deal with that?
Q: have you heard of c++ strong exception guarantees vs basic exception guarantees?
A: http://en.wikipedia.org/wiki/Exception_guarantees

Q: how does java generic differ from c++ and c# — take a hashmap for example?
Q: c# hashmap of integer? Is it special?
Q: you mentioned java hashmap of integer involves autoboxing, so what happens during autoboxing?
Q: What smart pointers have you used?
Q: if i were to use a smart pointer with my legacy class, do I have to modify my class?

Q7: you mentioned java generic was designed for backward compatibility, but why not add a new type HashMap in addition to the old non-generic HashMap class?
%%A: old and new must be interoperable

Q7b: what do you mean by interoperable?

Q: tell me one project with low latency

— some answers revealed —
A1: local vol is designed to explain skew. During the diffusion, instantaneous vol is assumed to be deterministic, and a function of spot price at that “instant” and TTL.

I guess what he means is, after 88 discrete steps of diffusion, the underlier could be at any of 888888 levels (in a semi-continuous context). At each of those levels, the instantaneous vol for the next step is a function of 2 inputs — that level of underlier price and the TTL.

A3: easiest way is “call premium – put premium == fwd price” (cash amount to be added to LHS?)

lambda in c#

I bought a book [[c# in depth]] by Jon Skeet, with excellent coverage of c# lambda. Now I feel lambda is added to the c# 3.0 primarily to support LINQ, though there are probably other usages.

Lambda in c# feels like nothing more than syntactic sugar over anonymous delegates (or “anonymous methods” as mentioned in MSDN).

If we understand c# delegates (built into c#  from Day 1), then lambda is simple — perhaps as simple as typedef or #define in C, or as simple as references in c++.

However, to have a good grip over lambda, we need to go beyond LINQ and have a solid understanding of delegates.