hazard rate – online resources

is decent —

Average failure rate is the fraction of the number of units that fail during an interval, divided by the number of units alive at the beginning of the interval. In the limit of smaller time intervals, the average failure rate measures the rate of failure in the next instant for those units surviving to time t, known as instantaneous failure rate.

is more mathematical.

http://www.omdec.com/articles/reliability/TimeToFailure.html has short list of jargon


ccy swap^ IRS^ outright FX fwd

currency swap vs IRS
– Similar – exchange interest payments
– diff — Ccy swap requires a final exchange of principal. FX rate is set up front on deal date

currency swap vs outright fx fwd?
– diff — outright involves no interest payments
– similar — the far-date principal exchange has an FX rate. Rate is set on deal date
– diff — the negotiated rate is the spot rate on deal date for ccy swap, but in the outright deal, it is the fwd rate.

currency swap vs FX swap? Less comparable. Quite a confusing comparison.
– FX swap is more common more popular

hazard rate – my first lesson

Imagine credit default is caused only by a natural disaster (say hurricane or tsunami). For a brief duration ΔT (measured in Years), we assume the chance of disaster hitting is λ*ΔT, with a constant [1] λ .

Pr(no hit during    A N Y   5-year period)
= Pr (surviving 5 years)
= Pr (no default for the next 5 years from now)
= Pr (T > 5) = exp(-5λ) , denoted V(5) on P522 [[Hull]]

, where T :=  # of years from now to next hit.

This is an exponential distribution. This λ is called the hazard rate, to be estimated from market data. Therefore it has a term structure, just like the term structure of vol.

More generally,  λ could be assumed a function of t, i.e. time-varying variable, but a slow-moving variable, just like the instantaneous vol. In a noisegen, λ  and vol function as configurable parameters.

In http://www.financial-risk-manager.com/risks/credit/edf.html, λ is denoted “h”, which is assumed constant over each 12-month interval.

“Hazard rate” is the standard terminology, and also known as “default intensity” or “failure rate”.

I feel hazard rate is perhaps the #1 or among top 3 applications of
conditional probability,
conditional distribution,
conditional expectation

So the big effort in studying the conditional probability is largely to help understand credit risk.

conditional independence, learning notes

Remember — Discrete is always easier to understand …

Q: does conditional independence imply unconditional independence?

Simple example – among guys, weight is unrelated to income – conditional independence, but removing the condition, among all genders weight has a bearing on income.

However, in this math problem the terminology can be confusing – Given W = w, the 2 random variables X and Y are conditionally iid exp(w) distributed. W itself follows a G(alpha, beta) distribution. Are X and Y unconditionally independent?

I feel the key is the symbol “w”, which is neither a variable nor a number, but rather a configurable parameter. In the noisegens, this w is a constant, like 39.8. However, as operator of the noisegen, we could set this parameter and potentially modify the distribution(s).

If for all w values, X and Y are independent, then I believe X and Y are unconditionally independent.

intuitive – stdev(A+B) when independent ^ 100% correlated

(see also post on linear combo of random variables…)

Develop quick intuitions — Quiz: consider A + B under independence assumption and then under 100% correlation assumption. When is variance additive, and when is stdev additive?

(First, recognize A+B is not a regular variable like “A=3, B=2, so A+B=5”. No, A and B are random variables, from 2 noisegens. A+B is a derived random variable that’s controlled from the same 2 noisegens.)

If you can’t remember which is which, remember independence means good diversification[intuitive], lower dispersion, lower spread-out around the expected return, thinner bell, lower variance and stdev.

Conversely, remember strong correlation means poor diversification [intuitive] , magnified variance/stdev.

–Case: 100% correlated, then A+B is exactly a multiple of A [intuitive], like 2*A or 2.4*A. If you think of a normal (bell) or uniform (rectangle) distribution, you realize 2.4*A is proportionally magnified horizontally by a factor of 2.4, so the width of the distribution increases by 2.4, so stdev increases by 2.4. In Conclusion, stdev is additive.

–Case: independent
“variance is additive” applicable in the multi-period iid context.

simple rule — variance of independent[1] A + B is the sum of the variances.

[1] 0 correlation is sufficient

–Case: generalized — http://www.stat.ucla.edu/~hqxu/stat105/pdf/ch01.pdf P27 Eq5-36 is a good generalized formula.

V(A+B) = V(A) + V(B) + 2 Cov(A,B)  …. easiest form

2*Cov(A,B) := 2ρ V(A)V(B)

V( 7A ) = 7*7 V(A)

## 5 expertise I could teach #thread

The most sought-after Expertise I could develop.

#1 personal investment – FX/option, HY and unit trust investment

# tech IV by top employers, including brain teasers
# Wall St techie work culture
# financial dnlg, appealing to pure techies
However, some of these are hard to make a teaching career. So which domain can i teach for a living, perhaps with a PhD
  1. programming
  2. data science, combining finance with…
  3. evergreen comp science, esp concurrency theory .. data structure .. algorithm
  4. fin math

notation tips for probability puzzles

* There are many alternative notations for “probability of A and B”. I prefer p(A . B) — good for hand writing and computers

* There are many alternative notations for “probability of not-A”. I prefer p(A’ ) — good for computers. How about p(!A)? Alien to many mathematicians.

* Favor shortest abbreviations for event names. For example, probability of “getting two 6’s in 2 consecutive dice tosses” should NOT be written as p(66), but as p(K) by denoting the event as K.
* Avoid numbers in event short names — things like 2 Pr(3) very ambiguous. If feasible, avoid number subscripts too.
* Favor single letters including greek letters and Chinese characters. If feasible, avoid any subscript.

Venn diagram – good at showing mutual exclusion between 2 events.
tree diagram – good at showing cond prob between 2 events
tree diagram – good at showing independence between 2 events

Note — Mutual exclusion => independence,  but not vice versa.

Independence is intuitive most of the time but can be non-intuitive when you are deep into a tough puzzle.

Independence can be counter-intuitive and not captured in tree diagrams. Let h denote “salary above 100,000”; f=female. The 2 events happen to be indie in one firm but not another. In general, we have to assume not-independent.

Tossing a coin in the morning vs afternoon. Toss Should be independent of timing, but actual observation may not prove it.

prob integral transform (percentile), intuitively

I find the PIT concept unintuitive …Here’s some learning notes Based on http://www.quora.com/What-is-an-intuitive-explanation-of-the-Probability-Integral-Transform-aka-Universality-of-the-Uniform answer by William Chen.

Let’s say that we just took a midterm (or brainbench or IKM) and the test scores are distributed according to some weird distribution. Collect all the percentile numbers (each between 1 and 100). Based on PIT, these numbers are invariably uniformly distributed. In other words, the 100 “bins” would each have exactly the same count! The 83rd percentile students would tell you

“82% of the students scored below us, and 17% of the students scored above us, and we are exactly 1% of the batch”

Treat the bins as histogram bars… equal bars … uniform pdf.

The CDF is like the percentile function, which accepts a score and returns the percentile, a real number between 0 and 1.00.

quantile (+ quartile + percentile), briefly

http://en.wikipedia.org/wiki/Quantile_function is decent.

For a concrete example of quaNtile, i like the quaRtile concept. Wikipedia shows there are 3 quartile values q1, q2 and q3. On the pdf graph (usually bell-shaped, since both ends must show tails), these 3 quartile values are like 3 knifes cutting the probability mass “area-under-curve” into 4 equal slices consisting of 2 tails and 2 bodies.

Quantile function is related to inverse of the CDF function. Standard notation —

F(x) is the CDF function , strongly increasing from 0 to 1.
F -1() is the inverse function, whose support is (0,1)
F -1(0.25) = q1 , assuming one-to-one mapping

http://www.quora.com/What-is-an-intuitive-explanation-of-the-Probability-Integral-Transform-aka-Universality-of-the-Uniform explains in plain English that percentile function is a simplified, discrete version of our quantile function (or perhaps the inverse of it). The CDF is like a robot. You say your score, and he give you the percentage like “94% of test takers scored below you”.

Conversely, the quantile function is another robot. You say a percentage like 25%, and she gives the score “25% of the test takers scored below 362 marks”

Obvious assumption — one to one mapping, or equivalently, strongly increasing CDF.

(reverse) transforming a N -> LN RV

A LogNormality random var —- goes through the log() transform —-> a Normality random variable. The log() transform pushes probability mass to the left.

A Normality random var —- goes through the exp() transform—-> a LogNormality random variable. The exp() transform is like a snow bulldozer clearing the snow off the left side (50% of the probability mass) to the right side

In short form,
LN –log()–> N
N –exp()–> LN

These are the 2 “Tanbin” rules to internalize. One of them is just a variation of the sound byte “Something is LogNormal means log of it is Normal”

Some self-quizzes —

Q: how can log() help transform a LN var to a N var?
Q: what if I apply exp() on a LN var?
A: unfamiliar distribution. Note exp() can accept -inf to +inf, underutilized by the input LN variable.
A: N –exp()–> LN –exp()–> … Note you are double-hitting exp()

Q: how can exp() help transform a LN var to a N var?
Q: what if I apply log() on a LN var?
Q: given a LN var, how to get a N var?
Q: how can log() help transform a N var to a LN var?
Q: how can exp() help transform a N var to a LN var?
Q: given a N var, how to get a LN var?
Q: how can a N var be transformed to a LN var?
Q: what if I apply exp() on a N var?
Q: how can a LN var be transformed to a N var?
Q: what if I apply log() on a N var?
A: crash and burn! N variable can be -inf, breaking log()

physical, intuitive feel for matrix shape – fingers on keyboards

Most matrices I have seen so far in real world (not that many actually) are either
– square matrices or
– column/row vectors

However it is good to develop a really quick and intuitive feel for matrix shape. When you are told there’s some mystical 3×2 matrix i.e. 3-row 2-column.
– imagine a rectangle box
– on its left imagine a vertical keyboard
– on it put Left fingers, curling. 3 fingers only.
– Next, imagine a horizontal keyboard below (or above, if comfortable) the rectangle.
– put Right fingers there. 2 fingers only

For me, this gives a physical feel for the matrix size. Now let’s try it on a column matrix of 11. The LHS vertical keyboard is long – 11 fingers. Bottom keyboard is very short — 1 finger only. So it’s 11×1

The goal is to connect the 3×2 (abstract) notation to the visual layout. To achieve that,
– I connect the notation to — the hand gesture, then to — the visual. Conversely,
– I connect the visual to — the hand gesture, then to — the notation
Now consider matrix multiplication. Consider a 11×2. Note a 11×1 columnar matrix is more common, but it’s harmless to get a more general feel.

An 11x2 * 2x9 gives a 11x9.

Finger-wise, the left 11 fingers on the LHS matrix stay glued; and the right 9 fingers on the RHS matrix stay glued. In other words,

The left hand fingers on the LHS matrix remain.
The right hand fingers on the RHS matrix remain.

Consider a 11×1 columnar matrix X, which is more common.

X * X’ is like what we just showed — 11×11 matrix matrix
X’ * X is 1×11 multiplying 11×1 — 1×1 tiny matrix

What could be the#1 task4a manager #Simplistic

Disclaimer – I’m no expert on management. Let me limit my perspective to the only subset I know i.e. IT management either in development, support, infra, delivery …

$ Some American author (P. Drucker?) said the #1 element of leadership is people motivation. Perhaps relevant in a start-up. I feel for a typical middle manager, even if half the team is non-productive her own performance would be unaffected.
$ Some (XXH) characterize manager’s role as managing relationships. (I guess you could say the same about a salesman, a PM, a BA, an architect or almost any role.) I feel in most cases the #1 relationship to manage is the guy who determines the manager’s own performance.  Typically it’s the boss, or perhaps the big customer being served if the manager is client-facing. As to the relationship with team members, actually not that important to him.
$ A senior manager (SCS) once told me “complete project on time within budget” is everything. Sounds like it requires the right people in the team. However, in that context I feel the more important relationship to manage might be the (internal) customer.
$ Many experienced managers jokingly say “my job is coordinator and dispatcher”, since all the real work is done by the people below.
$ Chunmei liked to emphasize judgement or pan-duan-li as the key to management (key to any success). I like this view.
$ Some management science researchers found planning and esp. Execution is the key challenge of management. Good theory. In IT and esp. software development there’s such a great deal of details to get right. Execution is about getting the important details right.
$ Managers are measured and ranked (by their superiors) according to their numbers. A self-preserving manager would be unwise to focus on anything else.
$ For a manager at a higher level, perhaps the really important job is to identify key individuals to run the sub-teams. But I feel it’s /farfetched/ to put it as #1 task

Fwd: Markit phone interview, full time position, 10/13/14

———- Forwarded message ———-
Date: Tue, Oct 14, 2014 at 4:02 AM
Subject: Markit phone interview, full time position, 10/13/14

Which Java package do you particularly like?

To design a cache framework, in such a scenario, you have already 50 objects in the map, that's its capacity. Now 51st object comes in, you have to remove the first object in the cache (this implies the map is sorted) to make room for the new comer. How do you go with that?
The answer is to use LinkedBlockingQueue as the map's placeholder
What's weak reference? Explain how GC works? Do you know any GC algorithm? If to choose one GC algo for your application, how do you set the JVM parameter?
Java Serialization. If there is a serializable Singleton to be wired from one JVM to another, what do you do to guarantee the other JVM to have only one instance of the Singleton class v.s multiple instances?
Threadpool. Can you set the max size of a threadpool? How do you go about it? What if the max size is 10, what will happen to the new coming task but not serviced? What is the queue used in Thread pool? What if the queue is full? Why uses block queue?
Database. How do you detect deadlock in database? How do you read Threaddump?
Database. If you were handed with a complex query running against 10 tables, and there is a performance issue, how do you proceed to resolve it? Have you used Execution plan?

bonds ^ swaps – 2 subdomains in FI

3rd and 4th domains would be credit (including muni) and mortgage, but let’s put them aside, despite their very large market sizes.

There’s huge demand for IR swaps and riskfree bonds. To keep things simple (perhaps over-simplifying), we can say
– bonds are income-generation Investments, needed by every investor esp. serious investors including banks, fund managers and pension/insurance.
– swaps (on the long end of YC) and IR futures (on the short end) are needed for risk management (hedging) by large enterprises with interest rate exposures.
Both domains rely on their respective yield curves. The so-called curve instruments are never mixed. Let’s illustrate using USD
– swap curve is built from Libor instruments like Libor swaps, Libor FRA and ED deposits, but not Treasury instruments. In AUD market, there’s no Libor so people use BBSW.
– Treasury curve is built from T and T-futures, not Libor instruments

In Lida’s words, these would be the risky curve (AA curve) vs the riskfree curve (government curve).

Q: how about the OIS curve? I think it’s based on OIS instruments

OIS^Libor — 2 indices

contract maturity –up to 50Y, for both OIS and Libor swaps.

payment frequency – 1Y for long-term OIS swaps. Example – 50 payments for a 50Y OIS swap. If term (ie maturity) is below 1Y, then there’s just one payment, at maturity. See http://www.frbsf.org/economic-research/events/2013/january/federal-reserve-day-ahead-financial-markets-institutions/files/Session_1_Paper_1_Filipovic_Trolle_interbank.pdf

fixing frequency – 1D for OIS. In contrast, for USD Libor swap, typically 3M.

accrual period — Assuming a 3M payment frequency on the floating leg. The underlying “assumption” is a 3M (unsecured) loan to an AA-rated bank. In contrast, the OIS underlying loan is a 1D (unsecured) loan, typically to a bank. The underlying loan tenor is what I call the “accrual period”. Taking USD as example, the standard “accrual period” is 3M. So if you want a swap with floating accrual period of 6M, then you need to do a tenor basis swap. I feel OIS is simple. The accrual period is always 1D, as the underlying loan is 1D. The 1Y payment frequency is less important.

Both are unsecured loans, but OIS is a closer proxy for the riskfree rate. I guess overnight borrowing by gov (of the named currency) would be a better riskfree rate, but no such thing.

Libor IRS has zero value at inception. The trade execution price is the fixed rate, which equals the “average” of the expected floating payments… Overnight Index swap is a similar contract. The average is geometric, and the reference (i.e. floating) rate is the FF/EONIA/SONIA/…

https://quant.stackexchange.com/questions/29644/difference-between-ois-rate-and-fed-funds-rate has concise details.

Producer-Consumer threading question by YH

(publishing this example on my blog)

https://community.oracle.com/thread/1142629?tstart=120 presents a simple but tricky threading scenario. Without the sleep(), we get random output like

Putting : 0
Putting : 1
Getting : 0
Q: how could Putting 1 happen before “Getting 0”?
Explanation — Actually, the assignment to this.hasPut does happen in lock steps like true false true false true …. (Can confirm by printing its value immediately after assignment). This is thanks to the “synchronized” keyword. Problem is the Putting/Getting prints. These statements are outside synchronized blocks, and get badly delayed, like in the above scenario —
put() returns -> “Putting 0” -> get() returns but consumer thread preempted before “Getting 0” -> put() returns -> “Putting 1” -> “Getting 0”

another (2nd) numeraire paradox

(This scenario is actually a 2-period world, well-covered in [[math of financial modeling and inv mgmt]]. However, this is NOT the simplest problem using a bank account or bond as numeraire. )
Consider a one-period market with exactly 2 possible time-T outcomes w1 and w2. Among the tradable assets is G. At termination,  
                G_T(w1) = $6
                G_T(w2) = $12.
Under G-measure, we are given RN PrG (w1) = PrG (w2) = 50%. It seems at time-0 (right now) G_0 must be 9, but it turns out to be 7!
Key – this RNPG is inferred from (and must be consistent with) the current market price of another asset [1]. In fact I believe any asset’s current price must be consistent with this G-measure RNPG. I guess the discounted expected payout equals the time-0 price.
Now can there be a 0% interest bank account B? In other words, is it possible to have B_T = B_0 = $1? Well, this actually implies a PrG (w1) = 5/7 (Verified!), not 50%. So this bank account’s current price is inconsistent with whatever asset used in [1] above. Arbitrage? I guess so.
I think it’s useful to work out (from the [1] asset’s current price) the bond current price  Z_0 = $0.875. This implies a predicable drift rate. I would say all assets (G, X, Z etc) have the same drift rate as the bond numeraire.
Next, it’s useful to work out that under Z-measure the RN Prz (w1) = 66.66% and Prz (w2) = 33.33%, very different RNPG values.
Q: under Z-measure, what’s G’s drift?
A: $7 -> $8
1) The most common numeraires (bank accounts and discount bonds) have just one “outcome”. (In a more advanced context, bank account outcome is uncertain, due to stoch interest rates.) This stylized example is different and more tricky. Given such a numeraire with multiple outcomes, it’s useful to infer the bond numeraire.
2) When I must work with such a numeraire, I usually have
* If I also have X_0 then I can back out Risk Neutral PrG(w1) and PrG(w2)
* alternatively, I can use X as numeraire and back out PrX(w1) and PrX(w1)
* If on the other hand we are given some of the PG numbers, then we can compute X_0 i.e. price the asset X.
[1] Here’s one such asset X_0 = 70 and X(w1) = 60 and X(w2) = 120.

process-wide exception handling, across lang

label – not sure…

I blogged before that one of the “services” a managed environment offers is (uncaught) exception handling.

By design, try/catch exception handling is per-thread. However, an innovative feature is the app-domain-wide exception handler that handles any “unhandled” exception on any thread. JVM and CLR both support this feature. (Actually they aren’t bullet-proof. They can’t handle stack overflow for example. I think it all boils down to the design of the VM.)

Q: Why doesn’t c++ have this feature (except set_terminate())?  No VM, but exactly how?

Now I think any VM (CLR, JVM etc) offers “containers” to contain your applications. A CLR can contain 2 app domains. When some thread in an app domain throws an exception and you don’t catch it, the container can “notice” it and fire the event. At least it has a chance to print the stack trace, which is sometimes impossible in c++.

I think the CLR is the “container” or “host” to the app-domain. The OS doesn’t see the code running in the app-domain; OS sees the CLR only. If app-domain generates an uncaught exception then the host/container VM won’t let it bring down entire VM. VM will print the exception and continue to live and host the other app-domains.

In contrast, in a traditional compiled application like c++, the uncaught exception would bring down entire process, as if the CLR itself throws an exception.

In a crude analogy, suppose I write a container (like a CLR) in C that evaluates a byte array containing some byte code. If the byte code throws exception, my container can print the error and continue to live.

I feel an OS is also a container. Without the OS, a program (compiled into assembly) can run directly on a CPU. Any error would crash the entire CPU. The OS isolates one such program from other programs, so one crasher doesn’t bring down entire OS.

capm – learning notes

capm is a “baby model”. capm is the simplest of linear models. I guess capm popularity is partly due to this simplicity. 2 big assumptions —
Ass1a: Over 1 period, every individual security has a return that’s normal i.e. from a Gaussian noisegen with a time-invariant mean and variance.

Ass1b: there’s a unique correlation between every pair of security’s noisegen. Joint normal. Therefore any portfolio (2 assets or more) return is normal.

Ass2: over a 2-period horizon, the 2 serial returns are iid.

In the above idealized world, capm holds. (All assumptions challenged by real data.) In real stock markets, these assumptions could hold reasonably well in some contexts.

capm tries to forecast expected return of a stock (say google). Other models like ARCH (not capm) would forecast variance of the return.

Expected return is important in the industry. Investors compare expected return. Mark said the expected return will provide risk neutral probability values and enable us to price a security i.e. determine a fair value.

Personally, i don’t have faith in any forecast over the next 5 years because I have seen many forecasts failing to anticipate crashes. However, the 100Y stock market history does give me comfort that over 20 years stock mkt is likely to provide a positive return that’s higher than the risk-free rate.

Suppose Team AA comes up with a forecast mkt return of 10% over the next 12 months. Team BB uses capm to infer a beta of 1.5 (often using past 5 years of historical returns). Then using capm model, Team CC forecasts the google 12M expected return to be 1.5 * 10%.

In the idealized world, beta_google is a constant. In practice, practitioners assume beta could be slow-changing. Over 12M, we could say 1.5 is the average or aggregate beta_google.

Personally I always feel expected return of 15% is misleading if I suspect variance is large. However, I do want to compare expected returns. High uncertainty doesn’t discredit the reasonable estimate of expected return.

“Market portfolio” is defined as the combined portfolio of all investor’s portfolios. In practice, practitioners use a stock index. The index return is used as mkt return. Capm claims that under strict conditions, 12M expected return on google is proportional to 12M expected mkt return and the scaling factor is beta_google. Capm assumes the mkt return and google return are random (noisegen) but if you repeat the experiment 99 million times the average returns would follow capm.

fx swap – mostly used for funding

Soundbyte — FX swap is a popular alternative to (secured) bank loan.

www.rba.gov.au/publications/bulletin/2010/jun/pdf/bu-0610-7.pdf is the best article to shed light on the “funding” usage of FX swap. (By the way, It also covers the ccy swap i.e. xccy IRS, which tends to be confused with fx swap.)

The term “funding” is unnatural to me. “Funding” basically means borrowing money for a fixed repayment period. Say I have a big project and need $555m. I typically borrow from a bank or issue a bond. Note with each “funding” requirement, there's a pre-defined repayment timeframe.

A similar verb is “raising” fund.

Fwd: Barcap onsite interview, 10/09/14

———- Forwarded message ———-
Date: Fri, Oct 10, 2014 at 7:56 AM
Subject: Barcap onsite interview, 10/09/14
Coding, no pseudo code, must be workable code. On paper.

1. Read a file, find out the occurrence of the alphanumeric letters, like “122113, Hello world”, returns 1:3; 2:2; 3:1; H:1;e:1; l:3; o:2; r:1;d:1
2. find out if a string brackets come in pairs. For example, “[{}]{([])}” will return true, but “[(])” will return false;
An algo: from an array of length of n, pick up m elements randomly, m<=n. Must be no dups, meaning once an element has been picked, it can't be picked again. Best way to implement it.
In an extreme, for a length of 1000, pick up 999 elements.
A bunch of multi-choice stupid Java questions, like “What's AWT stand for”
Some designing questions, how to implement N-Tiers applications; What's its pro and cons;
What's it that you don't like about Java? 
This is just some open discussion: my answer was that Java is now too huge a monster that tries to please everyone, which is against its original philosophy of simplicity. And I gave example of lamda expression, and multiple inheritance in Java 8, which is the center of debates. 
Then he asked if w/o lamda, how to do functional programming in java? and my answer was that other JVM language such as Scala can do it just fine or even better since it's created for that purpose. Also since it's in JVM ecosystem it can fit in seamlessly.
How to sync up with database in Hibernate?
What's asynchronous IO? How to achieve highly efficient concurrent processing services. 
I couldn't impress him as I didn't know it but it seems that I managed to get his attention by mentioning the emerging technologies such as Node.js, which is designed for that purpose
In a scenario, we have 10 requests being handled by all available threads in a thread pool, they are long processing tasks, thus more requests come in but can't be processed, then what? How to design an architecture that can prioritize the requests so that clients can have reasonable responsiveness.

Fwd: 10/08/14 phone interview with BNP Paribas, GWT UI developer position, Jersey City

———- Forwarded message ———-
From: Hai Yi


1. How GWT communicate from frontend to backend;

2. what's interface?
3. What's serialization? How to customize serialization
4. hashing in Java, explain.
5. How to tune GC parameters
6. By default, Spring bean is singlton, what's the other type?
7. What's autowired?
8. In Hibernate, whats the difference b/w Session and Transaction?
9. There are classes of inheritance relationships, for example, a Person class, a Employee class and a Manager class, what's the different strategies to design tables to map these classes? If only one table is used, how to differentiate those classes?
10. How does Hibernate handle multiple databases?
11. Whats table partition?
12. How do you do to improve performance for data retrival/saving?
13. What's composite primary key?
14. XML. Efficiency compare: SAXand DOM. Whats API do you use?
15. Web service. SOAP/RESET, what tools do you use?
16. How do you do unit test and integration test? Have you used mockit?
17. Maven. The “Runtime” or “Test” inside Dependency tag, what are they used for?

Fwd: onsite BofA IV{phone IV 10/01/14

———- Forwarded message ———-
From: Hai Yi
Date: Wed, Oct 8, 2014 at 9:42 AM
Subject: onsite BofA interview, continuance of the phone interview on 10/01/14

Coding on the computer and white board

1) code on Eclipse
There is a folder containing stock files, each line of which includes info as below, and delimiter is “t”.
date in the format “YYYY-MM-DD”
indicator (BUY/SELL), this is counter party BUY from or SELL to BofA
counter party
There are 100 such files and each file contains 10,000 lines.
In the same folder there is also a short file, marks.txt in which there are two columns in each line showing the symbol and market price, for example:
AAPL 350.00
Task: reading the file and figure out the long positions that BofA hold on the stocks, list top 20 in the descendant order with regard to value (quantity*price) and the respective market value. For instance, BofA might buy/sell AAPL, if the net is long, you have to figure it out and count it as required above.
2) white board
Create a high efficient cache solution for computation, it must be thread safe.
public interface Computable {
  public V compute(K k);
public class Cache implements Computable{
    //the Caculator below is a delegate to do the heavy lift, but the result can be cached so it's supposed to call only once
    private Computable caculator = new Caculator();
    private Map cache = new HashMap();
    public V compute(K k){
              return cache.get(k);
            V val = caculator.compute(k);
             return val; 
What's the problem with the above implementation? How to make it highly performant and thread safe?
I wrote a good implementation with synchronization and he complimented “nearly perfect” but he continue to request to create a “lock-free” solution, I couldn't do it and he wrote one using FutureTask, I don't remember the details. And he also suggested a even better one using AKKA's actor.
I didn't say but IMHO the common idea that synchronization is a performance penalty is just a urban legend – with the nowaday's modern Java compiler the overhead of synchronization is just trivial.
3) White board Singlton pattern.
4) Eclipse a Lock implementation, use only AtomicBoolean
public interface Lock {
  public void lock();
  public void unlock();
public class LockImpl implements Lock{
  private AtomicBoolean bool = new AtomicBoolean();
  public void lock(){
    //What's in here?
  public void unlock(){
    //what's in here?

local jargon,local domain knowledge = local sys knowledge

I agree that finance IT skills tend to “converge” across big banks, so we poor developers need not learn so many damn shit new stuff like git, python, continuous build…

On the domain knowledge side, the “local system knowledge” has no convergence as such, so each time I take up a new system, I must spend the time on the stored procs, table relationships, batch jobs, feed files, etc. There are also a lot of non-technical local knowledge. I hear you when your manager complained “what do you know about the system?”

Local system knowledge can be a long learning curve. Those who write the code in the first place has a huge advantage —

“It takes me 3 months to write this damn shit, then we add new features and fix bugs, but it’s still familiar to me. A new guy would take a year to get familiar code-wise, provided he has chance to explore all the key components. If he’s only exposed to half the system, then he would never know  the other half.”

(Therefore, I like to rewrite stuff.)

In http://bigblog.tanbin.com/2011/04/3-types-of-domain-knowledge-in-finance.html I mentioned 3 types of domain knowledge — Jargon, Math, and Architecture.The Math part is stable. Local system knowledge includes a lot of local jargon. Sometimes generic jargon can help us pick up the local jargon.

Fwd: 10/01/14, 5:30PM, BofA phone interview with Wilson

———- Forwarded message ———-

From: Hai Yi

Date: Thu, Oct 2, 2014 at 11:47 PM

Subject: 10/01/14, 5:30PM, BofA phone interview with Wilson


1. Explain how HashMap works

2. Compare HashTable and ConcurrentHashMap. Explain how CHM handle concurrency.

3. There is an arraylist of 1,2,2,3, how do you output unique values?

how do you only output dup values?

4. Can you remove an element during iteration? How do you do it properly?

5. Can you update elements in an arrayList if its reference is defined

as “final”. If so, what do you do to prevent it?

6. Name JSP internal objects. If in URL there is “id=12345”, how to

retrieve that value?

7. Difference b/w StringBuffer and StringBuilder; and their difference

with String?

8. What design patterns can you name? What's singleton?

9. How do you implement Producer-consumer pattern?

10. Explain Executor framework and Threadpool

11. Explain volatile and transient

12. Explain Breath-first traversal and depth-first traversal

13. What's the new feature in JDK 8? What's the “default” keyword used

for in JDK 8 context?


1. What's Union and Union all?

2. explain left join and inner join

3. There is a table “Salary” with two columns “id” and “salary”, this

is oracle, write sql to list first 4. 100 record with salary from

highest to lowest

4. How do you dump the data from table A to table B, if table B

doesn't exist. Do it in one SQL statement.

5. Difference b/w function and store procedure

6. What's view? What's trigger?

7. How to call a store procedure from Java? The JDBC API.

8. What are the transaction isolation levels?

9. How do you get the current date using Oracle?

10. In PL/SQL, how do you throw an exception and how to catch it?


1. what's the command to find the files that were updated in the past 10 days?

2. How to find a file with a particular name, like “hello.java”?

3. What's the command to kill a running Java process and generate threaddump?

4. There is a file of 10 million lines, whats' the command to list

first 10 line?

5. What's the command to count the line number in a file, what parameter to use?

6. In shell script, how to split a string with dilimiter?

7. In shell script, how to check if a file exists or not?

8. what's the command to sort a file?

9. what's the command to list all running processes?

10. In VI, how to replace a repeated word in the whole text?