c++ single-arg ctor is by default implicit converter

[[c++codingStandard]] point out the many subtle traps a beginner can hit when an implicit conversion is accidentally applied to her data type.

Therefore it’s good to spot any implicit conversion feature. For a custom class, there are only 2 ways to convert implicitly and one of them is a single-arg constructor. It’s implicit by default. You can disable the conversion capability by force it to be always-explicit

[13]immutability in python – fundamentals

Rule: immutability is on objects, not on variables. Actually, same as other languages.

Rule: An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.

Examples of containers are tuples, lists and dictionaries. The value of an immutable container object (like a tuple instance) that contains a reference to a mutable object can change when the latter’s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable content, it is more subtle. See http://docs.python.org/2/reference/datamodel.html

In most cases, when we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied.

I think for a custom MyClass that HAS-A object field myField, MyClass immutability means the content of myField is unchangeable. That’s the java concept of immutability.

[13]choose income^easy life #damagedGood

Update — if I avoid the coworker-benchmarking, then I don’t mind sacrificing some income.

Q: Do you prefer a job (under a boss) you are comfortable with, at a typical IT salary? Or do you prefer a job with above-average income, but demanding, suppressive(like Sourabh) boss? In both cases, let’s assume long term job security is average (far from ideal), workload is reasonable, commute is average.

A [2013]: I’d favor the income if it’s more than $1k/m diff, but not sure if I can cope with the unfriendly environmental factors.

A: in early 2018 I chose Mvea team. No regret so far

Health + employability(security) are my real, long term priorities, not “premium” salary. My parents keep reminding me the damage of long-term workplace stress…

Recall the GS/Macquarie experience – workload, job nature, security…. but all are mild compared to performance warnings.

A[2018]: now I feel $2k/m will bribe me.


compound options, basics

Based on P78 [[DerivativeFinancialProducts]].

Most popular Compound option is a call on a put. (I think vanilla Puts are the overall most popular option in Eq and FX, and embedded Calls are the most popular bond options.) Given a lot of buyers are interested in puts, there’s a natural demand for calls-on-puts.

In a Compound option there are 2 layers of fees (i.e. premiums) and 2 expiry dates —

The front fee is what you pay up front to receive the front option. If you exercise front option, you do so by buying the back option, paying the back fee as a 2nd premium to the dealer. Therefore the back fee is a conditional fee.

At end of front option’s lifespan, the back option’s protection period would start. (Remember in this case the back option is a protective put.)

It’s quite common that at end of the front window, the back option has become unnecessary, or back fee has become too expensive given the now reduced risk.

quant fund preference: y Eq/FX imt FI/commodities %%take

I feel quant funds (including HFT funds)

* does a large number of small trades and
* relies on a large volume of market data for statistical research/analysis. Sample size must be statistically meaningful.
I guess most FI and commodity markets often don’t support these. Some popular FI/Comm instruments have rich data volume, but doesn’t support small in-and-out trades. In FI/Comm, you buy and hold, rather than quick in-and-out trades. But how about high-volume listed FI instruments (like ED futures?) I hope the bid/ask is small enough to support in-and-out.
How about listed options? I feel percentage spread (bid/ask spread divided by mid-quote) is usually too large, so quick in-and-out trades are not always possible?

y do commercial banks have lots of money for trading#hearsay

Reason: a commercial bank makes money by lending to (credit worthy) borrowers but ROI of this traditional business model is modest. They get much better ROI from security trading.

Reason: a commercial bank often has excess liquidity. Out of $1b deposit, banks are regulated to lend out perhaps 75% (or 90% — known as LTD ratio) but must keep some 25% of the $1b in liquid cash. If the bank keeps 25.5%, then the .5% is excess liquidity. Note a bank can’t treat (total deposit minus total loan) as excess liquidity. Bank is regulated to keep some liquid cash to satisfy depositor withdrawals.

By default, the excess liquidity cash sits there earning 0 return. Security trading is one way to get some return.

Reason: a commercial bank often has FX risk to hedge. I think FX/derivative trading is one way to hedge. Bank must allocate some capital to the trading desk. Regulators would approve such capital allocation as it’s needed to reduce systemic risk and strengthen stability.

Reason: a commercial bank often has large enterprise customers who need tailor-made financial solutions. (I feel many mainstream derivative products originated in big bank’s structuring desks addressing the needs of big corporates.) When the corporate enters a derivative contract with the bank, the bank must hedge its risk by trading suitable securities on the open market. Bank must allocate some capital to the trading desk.

Reason: many banks started trading using it’s own excess liquidity. Then they realize ROI is sweet, so they started borrowing from other banks purely for security trading. This is another source of trading capital.

multicast – highly efficient@@ # my take

(Note virtually all MC apps use UDP.)
To understand MC efficency, we must compare with UC (unicast) and BC (broadcast). First we need some “codified” metrics —
  • TT = imposing extra Traffic on network, which happens when the same packet is sent multiple times through the same network.
  • RR = imposing extra processing workload on the Receiver host, because the packet is addressed TO “me” (pretending to be a receiver). If “my” address were not mentioned in the packet, then I would have ignored it without processing.
  • SS = imposing extra processing workload by the Sender — a relatively low priority.
Now we can contrast MC, UC and BC. Suppose there are 3 receiver hosts to be notified, and 97 other hosts to leave alone, and suppose you send the message via —
  1. UC – TT not RR — sender dispatches 3 copies each addressed to a single host.
  2. BC – RR not TT — every host on the network sees a packet addressed to it though most would process then ignore it, wasting receiver’s time. When CEO sends an announcement email, everyone is in the recipient list.
  3. MC – not RR not TT. However, MC can still flood the network.

3 basic container-cloning techniques (STL)

Note: I have never needed to clone a container.

STL containers have 3 similar (confusing) operations. Target container ends up with exactly the same content as the source container[1]. I consider them “cloning” operations, including swap.

1) generalized copy construction — from a source container to a new-born container
** I think you pass in a pair of iterators. [[c++Standard Lib Practical Tips]] P96 shows the list and vector constructors

2) assignment — from a source container to an Existing target container
** I think most containers offer an operator= and also a this->assign() method. [[c++Standard Lib Practical Tips]] P102 shows both.
[[ObjectSpace]] P14 covers operator=().

3) swap content — A ends up with B’s content, and B ends up with A’s content.
** Usually we use swap for one-way cloning. We clone from A to B and discard A.
** I think swap is a favorite among experts.

?) How about insert()? No. Insertion doesn’t meet the criteria in [1]. However, I feel insertion is often more useful more versatile more consistent. See http://bigblog.tanbin.com/2012/05/versatile-technique-to-populate-1.html

use STL Map to emulate a Set#as JDK does

Q1: is it practical to use a STL Map to emulate the Set class-template, at comparable efficiency?

We know a Map stores PAIRs in a red-black tree. Can we just put an empty thing in the PAIR.second field?

Q2: how small can the “PAIR.second” footprint be? 0 byte? 1 byte? Java is less memory efficiency … where everything is heapy thingy..
%%A: i don’t think it can be 0 byte. sizeof(PAIR) is known when you specialize the PAIR template with T1 and T2. sizeof(PAIR) depends on sizeof(T1) + sizeof(T2). Compiler needs to know sizeof(PAIR) in order to allocate memory to a new PAIR object.

Q3: is there any type T2 such that sizeof(T2) == 0?
%%A: I don’t know any.

Q4: we know (confirmed) java HashSet is implemented using HashMap physically. Is that different from C++?
A: different

Q5: java TreeSet.java source code shows a physical implementation using a map. Is that different from STL?
A: different

c++ most common nested template use case

If you feel someTemplate <anotherTemplate > is rarely needed in c++? think again.

To put any pointer into a container, you usually have a vector<shared_ptr >. In this template we have
* the most important container
* the most important smart pointer
* the most important boost library component
* the most important STL component

Also note that string is a value-like type just like int or char. You can use a string directly in a container or you can store a string smart-ptr in a container.

arb between 2 options with K1, K2

It’s not easy to get intuitive feel about arb inequality involving European put/calls of 2 strikes K1 < K2. No stoch or Black/Scholes required. Just use hockey stick diagram i.e. range-of-possibilities payoff diagram.

Essential rule #1 to internalize — if a (super-replicating) portfolio A has terminal value dominating B, then at any time before maturity, A dominates B. Proof? arbitrage. If at any time A is cheaper, we buy A and sell B and keep the profit. At maturity our long A will adequately cover our short B.

—-Q1: Exactly four assets are available: The bond Z with Z0 = $0.9; and three calls. The underlying is not available for you to trade. The calls have identical expiry T, strike K = 20; 22.5; 25, and time-0 price C0(K), where C0(20) = 6.40; C0(22.5) = 4.00; C0(25) = 1.00. Any arbitrage

Consider the portfolio B {long C(22.5) short C(25)} and A {25 Z – 22.5 Z} = {2.5 Z}

At maturity, A is worth $2.5 since the bond has maturity value $1 by definition.
At maturity, B < $2.5, obvious by hockey stick. This is the part to get intuitive with.

By Rule #1, any time before maturity, A should dominate B. In reality, A0 = 2.5 Z0 but B0 = $3 -> arb.

This trick question has some distractive information!

—-Q2: P141 [[xinfeng]] has a (simple) question — put {K=80} is worth $8 and put {K=90} is worth $9. No dividend. Covered on Slide 30 by Roger Lee. Need to remember this rule — 80/90*P(90) should dominates P(80) at time 0 or any time before expiry, otherwise arb.

Consider portfolio A {80/90 units of the K=90 calls} vs B {1 unit of the K=80 call}

If stock finishes above $80 then B = 0 so A >= B i.e. dominates
If stock finishes below $80, then B = 80-S. Hockey stick shows A = 80 – S*80/90 so A dominates.

Therefore at expiration A dominates and by Rule #1 A should be worth more at time 0. In reality, A0=B0.