#1 driver of long term FX #my take

Q: what is the #1 fundamental driver of long term FX rate between 2 currencies?

Is it PPP? I don’t think so.
Is it supply/demand? Short term yes; long term … this seems less relevant
%%A: “gold” backing.

In the beginning, every pound issued by the British monarch is as good as an ounce of gold (or whatever fixed amount of gold). Therefore anyone holding a pound note can exchange it for the equivalent amount of gold.  The monarch then decided to print more pound notes. Logically, all the existing and new pounds devalue. But the country also exports and, in a world of universal gold standard, earns gold. In a more realistic world, What is earned is foreign currency.

I believe Every Singapore dollar issued is backed by some amount of “gold” which in modern context means foreign reserve in a basket of hard currencies. By the way, there’s nothing harder than gold. As the national economy expands, more goods are produced domestically so the CB could issue more SGD, but I guess the CB waits until the goods are exported[2] and foreign currency earned. Such a prudent practice helps ensure every SGD is fully backed by sufficient “gold”.

[2] incoming tourists also spend their own currency, therefore contributing to the Singapore foreign reserve.

In general, a hard currency is more deeply *backed* by gold than a weak currency. Alternatively, the issuing central bank has other capabilities (besides gold reserve) to maintain the *strength* of her currency. This strength depends on Current Account and economic growth — the 2 fundamentals. Another factor is global competitiveness, but this is often measured by the capacity to export and compete on global markets. After all, it still seems to boil down to earning enough foreign currency to back our own currency — “gold” backing in disguise.

insert() — more versatile than assign() and range-ctor

[[effSTL]] P31 points out that range-iterators are used consistently across containers —

– Every (yes both sequence/associative) container supports a ctor taking a couple of range iterators
– All sequence (not associative) containers support assign() method taking a couple
– Every (yes both sequence/associative) container supports erase() method taking a couple

However, I’d argue the most versatile is the insert() method in Every Sequence and Associative containers.
* insert() can emulate the range-ctor
* insert() can emulate assign()

This is also more versatile than operator=().
This member function is also simpler than the free function copy().

why create custom STL iterators, briefly

Q: when would you write your own STL iterator?

I think if you create your own customized container, you probably need custom iterator Objects. You probably need to return such an Object from rbegin() etc.

In python, c# and (less commonly) in java, many data structures can be made iterable. There’s an implicit iterator.

[[STL tutorial]] has a 3-page chapter showing a debuggable-iterator that reveals interesting details of the inner workings of STL containers and STL algorithms.

unix signal, briefly

A Unix signal is picked up only at start of a time slice by the recipient “cpu-driver”. See P126[[art of debugging]]. Postman drops a letter on your doorstep when you step out. This is the best way to deliver the signal. It’s uncommon (impossible?) to interrupt a process /midstream/ a sequence of instructions. I guess the reason is efficiency — no efficient implementation of that interrupt mechanism. In Unix, what is common is the signal mechanism.

Unix signals can be generated from interactive user, from any other process, from kernel or from hardware, but they all have a target PID.

Unix Signal is at a lower level than threading. Thread preemption often depends on Unix signals

Unix Signal is a kernel-level mechanism.

Unix Signals target a process, not a thread.

A Unix Signal is an event. A Signal handler is an event callback function whose address is associated with one specific signal.

libor vs gov bond — 2 benchmarks

Most credit instruments, all (secured/unsecured) loans, all IR products, most derivatives based on FX, IR or credit (I'd say virtually all derivatives) need to apply a spread on a reference yield. If the deal has a “maturity date” or “delivery date”, “call date” [1], then we look for that date on the reference yield curve and read a yield number like (222 bps pa) off that curve. That number is the reference yield, a.k.a reference spot rate. You can convert that to a discount factor easily. There are also straightforward and well-defined conversions to/from fwd rates, driven by arbitrage principles.

[1] perhaps among a series such dates.

Question is which reference yield curve to use. Most companies use a single, consolidated curve for each currency. One of the biggest muni security trading desks in the world has just one yield curve for USD, which is typical. Another megabank has a single live Libor curve for the entire bank, updated by the minute.

If you use more than one yield curve built from different data sources, then for any maturity date, you would read 2 yield numbers off them. If sufficiently different, you create arbitrage opportunity and your valuations are inconsistent.

On the short end of the IR space the reference curves are 1) Libor 2) Fed Funding (USD only). Libor is more popular.

On the long end, T-bond dominates the USD market. Many governments issue similar bonds to create a reference riskless rate.

However, the most liquid IR instruments are probably more realistic and reliable as a reflection of market sentiment. ED futures, Bund futures, T-bond inter-dealer market rates are examples.

double-ptr usage #2b — swap 2 pointers

(Note this is a special case of “special reseating” — http://bigblog.tanbin.com/2011/04/double-pointer-usage-2-special.html)

Q1: write a utility function to swap 2 pointer’s content.
%%A: swap(int** a, int** b) {….}
Obviously, the 2 pointer Variables must be declared to be compatible — to be elaborated [1], such as
int* a1, b1; …. swap(&a1, &b1);

To really understand why we need double pointers, consider

Q2: function to swap 2 nonref variables. In other words, after i call swap(..), x should have the value of y. If y used to be -17.2, x now has that value. Note this number isn’t an address.

In this case, you need to pass the address of x like &x….

To understand this Q2, it’s actually important to be be thoroughly familiar with

Q3: what does swap(char i, char j) do?
%%A: something other than swapping. I doubt it does anything meaningful at all. It receives two 8-bit chars by value. It doesn’t know where the original variables are physically, so it can’t put new values into those original variables, so it can’t swap them.

Any swap must use some form of pass-by-reference.

Q1b: function to swap 2 arrays. After the swap, array1 is still a pointer but it points to the physical location of array2
%%A: same signature as Q1.

[1] void ** is probably a feasible idea but may require casting. Usually the 2 arguments a1 and b1 should have the same declaration. If a1 is Animal* and b1 is Dog* (Note the single asterisks), then such a polymorphic swap is no longer straight-forward and fool-proof.