QuantRead: Yieldbook MBS LMM Term Structure Model

The most celebrated part is the calculation done in Appendix 1.
claim: Increase short vol decreases the serial correlation of 10yr swap rates.
the proof applies the “roughly const coefficient” trick.
note that “short” vol means the tenor. To show a proof for 10yr swap rates starting N yrs from now and M yrs from now, we need N * (M-N) vol. M-N must be small.

Higher serial correlation means if option is in-the-money now, it will be highly likely in-the-money later. Hence the embedded option value decreases.
Such argument is kind of like: for CMO pricing, junior tranche likes the fact all collaterals are highly correlated, while senior tranche prefers all collaterals are lowly correlated.

QuantRead: Vol Skew and Valuation of Mtg

It is a whitepaper from Citi Yieldbook. Fair detailed to understand.

when we assume different distribution on fwd rates, we end up with different vol numbers.

Skew can be classified as OTM skew and ATM skew.

Black’s model assumes lognormal distribution. i.e. fwd rate change is proportional to rate level. Fig5 in the paper shows that empirical data contradicts this intuition; in fact, fwd rate changes are almost independent of rate level. In other words, our world is more like normal, not log-normal.

The skewness observed in log-normal model can actually come from the fact that the distribution is [almost] normal.

Study the impact of OAS (or price, as dual) on different fwd rates distributions.

 

When rates rally (i.e. decrease), vol increase — i.e. we encounter extra skew. If OAS is const, such extra skew will reduce price.

If we have several different distributions, more skew, the price drop is more visible. Or inversely, if price is same, more OAS pick up.

How to make use of this paper?

Suppose we are assigned with two MBS valuation systems (S1 and S2), which give different prices on TBAs? How to explain the difference?

This paper says: we can study the price/OAS or duration relation w.r.t. to vol skewness.  Study the OTM and ATM skews from S1 and S2!

Source: Volatility Skew and the valuations of mortages, 2005.

 

Fast implementation of duo exp() evaluations using SSE2

It comes from a practical problem: I need evaluate tension spline very frequently. The most expensive part is to compute: sinh(x-l), sinh(r-l), sinh(r-x).

It is simple to see that I only need evaluate exp(x-l) and exp(r-x), it leads to 40% performance boost. essentially, we replace 3 slow calls by 2 slow calls.

Caveat: mathematically, we are correctly. But numerically, it is less obvious or arguable. To be strict, compiler will not be able to assume (a+b)+c = a+(b+c).

We can defend us (and the approximation below): all calculations in computers are approximate, even hardware from different vendors have slightly different implementation. We should ONLY focus on the study if the approximation is sufficient.

See the links below for general defense line.

http://forums.amd.com/devforum/messageview.cfm?catid=390&threadid=126611&highlight_key=y

http://forums.nvidia.com/index.php?showtopic=152829

Now our task is to compute exp(x-l) and exp(r-x); or a duo exp evaluation. Recall that SSE2 has 128bit register to hold 2 doubles and perform parallel calculations on them. It should help me. In fact, my code below achieves 40% speed up, when compiled with VS 2010 Express.

Caveats

1. our calculation is approximate, and I did not study the accuracy yet. But simply compare to even rougher approximation shows: the speedup is real.

2. VS2008 Express can not give me any gain.

3. Intel C++? good idea, but need rewrite the code, as I use Microsoft C++ intrinsics.

Implementation

First, know how to evaluate one exp() in C++. Then parallelize it and write the code for double-double pair in SSE2 intrinsics.

First of all, there is no assembly instruction for exp(). We only have MUL, ADD, SQRT, etc. So we need polynomial approximation. The classic way of doing this is via Taylor expansion. Also, we need pay attention on a few coding tricks to save more time in Taylor expansion evaluation.

I don’t need write my version. Just use Cephes library from Netlib. http://www.netlib.org/cephes/

Then we can see SSE/SSE2 at SF version of Cephes as SseMath.

http://gruntthepeon.free.fr/ssemath/

But I need DF precision! Easy, do some translation. We end up with the following code.

// SSE2
#include <emmintrin.h>

#define SSE2_DOUBLE_CONST(Key, v) \
    static const __declspec(align(16)) double _D_##Key[2] = { v, v }
// repeat a const to be in packed form

#define SSE2_INT_CONST(Key, v) \
    static const __declspec(align(16)) int _I_##Key[4] = {v, v, v, v}

/*  SSE2 defs start */
SSE2_DOUBLE_CONST(1, 1.0);
SSE2_DOUBLE_CONST(0p5, 0.5);

SSE2_DOUBLE_CONST(cephes_LOG2, 1.44269504088896341);
SSE2_DOUBLE_CONST(cephes_C1, 0.693359375);
SSE2_DOUBLE_CONST(cephes_C2, -2.12194440e-4);

SSE2_DOUBLE_CONST(cephes_p0, 1.9875691500E-4);
SSE2_DOUBLE_CONST(cephes_p1, 1.3981999507E-3);
SSE2_DOUBLE_CONST(cephes_p2, 8.3334519073E-3);
SSE2_DOUBLE_CONST(cephes_p3, 4.1665795894E-2);
SSE2_DOUBLE_CONST(cephes_p4, 1.6666665459E-1);
SSE2_DOUBLE_CONST(cephes_p5, 5.0000001201E-1);

SSE2_DOUBLE_CONST(exp_upper,    88.3762626647949);
SSE2_DOUBLE_CONST(exp_lower,    -88.3762626647949);

SSE2_INT_CONST(0x7f, 0x7f);
/*  SSE2 defs end */

void exp_sse2(double in[2], double out[2])
{
    __m128d x = _mm_load_pd(in);

    __m128d tmp = _mm_setzero_pd();

    __m128d fx;

    __m128i emm0;

    __m128d oneD = *(__m128d*) _D_1;

    x = _mm_min_pd(x, *(__m128d*)_D_exp_upper);
    x = _mm_max_pd(x, *(__m128d*)_D_exp_lower);

    // exp(x) = exp( z + n log(2) ) = exp(z) * n^2 , where 0<=z < 1

    fx = _mm_mul_pd(x, *(__m128d*)_D_cephes_LOG2);
    fx = _mm_add_pd(fx, *(__m128d*)_D_0p5);

    emm0 = _mm_cvttpd_epi32(fx); //overloaded to handle _m128d
    tmp = _mm_cvtepi32_pd(emm0);

    __m128d flag = _mm_cmpgt_pd(tmp, fx); // ? 0xffffffffffffffff : 0x0
    flag = _mm_and_pd(flag, oneD);
    fx = _mm_sub_pd(tmp, flag);

    tmp = _mm_mul_pd(fx, *(__m128d*)_D_cephes_C1);
    __m128d tmp2 = _mm_mul_pd(fx, *(__m128d*)_D_cephes_C2);
    x = _mm_sub_pd(x, tmp);

    x = _mm_mul_pd(x, tmp2);

    __m128d z = _mm_mul_pd(x, x);

    __m128d y = *(__m128d*)_D_cephes_p0;
    y = _mm_mul_pd(y, x);
    y = _mm_add_pd(y, *(__m128d*)_D_cephes_p1);
    y = _mm_mul_pd(y, x);
    y = _mm_add_pd(y, *(__m128d*)_D_cephes_p2);
    y = _mm_mul_pd(y, x);
    y = _mm_add_pd(y, *(__m128d*)_D_cephes_p3);
    y = _mm_mul_pd(y, x);
    y = _mm_add_pd(y, *(__m128d*)_D_cephes_p4);
    y = _mm_mul_pd(y, x);
    y = _mm_add_pd(y, *(__m128d*)_D_cephes_p5);
    y = _mm_mul_pd(y, z);
    y = _mm_add_pd(y, x);
    y = _mm_add_pd(y, oneD);

    /* build 2^n */

    emm0 = _mm_cvttpd_epi32(fx);
    emm0 = _mm_add_epi32(emm0, *(__m128i*)_I_0x7f);
    emm0 = _mm_slli_epi32(emm0, 23);
    __m128d pow2n = _mm_castsi128_pd(emm0);

  y = _mm_mul_pd(y, pow2n);
    _mm_store_pd(out, y);

}

MISC

http://eigen.tuxfamily.org/index.php?title=FAQ#Vectorization

A linear algebra library, with SSE.

http://simdx86.sourceforge.net/

libSIMDx86 v0.4.0
The optimized SIMD library for x86 processors.

libSVM experiment: SSE extension

see source code for exp() kernel implementation in SSE2.

http://bazaar.launchpad.net/~olivier-grisel/simd4libsvm/libsvm.og.main/view/head:/src/kernel/kernel_sse2.cpp

Build out two more machines

 

The HTPC under build

Fired the trigger on Nov 27, 2011.

Antec Sonata III + 500W :

$99 + $17 = $116.

J&R. I owned one from last December build, it works well. So I buy it again :-) Note that Newegg.com current price is $129! Even higher than last year. So I buy it from J&R, but somehow it can only ship and cannot be picked up in store.

All other stuff are from Newegg.com

Intel Core i3-2105 Sandy Bridge 3.1GHz LGA 1155 65W Dual-Core Desktop Processor Intel HD Graphics 3000 : $135

Yes, I can save 20 bucks if I go for a 35W model. However, HD3000 graphics doubles the graphics engine from 6 to 12, compared to HD2000. As I will NOT buy discrete graphic card on HTPC. I decide to stick to HD3000.

Kingston 4GB 240-Pin DDR3 SDRAM DDR3 1333 (PC3 10600) Desktop Memory: $15

Yes, it is $15! Not on sale, just $15.

MSI P67A-G43 (B3) LGA 1155 Intel P67 SATA 6Gb/s USB 3.0 ATX Intel Motherboard: $115 – $20 MIR = $95

Surprisingly, cannot see a decent Gigabyte/Asus board with a decent price.  I used to think about Micro ATX board, but abandoned the idea. Yes, I can save a little space. But upgrading will be a big headache. Sometimes I have to upgrade, e.g. power supply may fail. Small box may come with a non-standard power supply, which means there is no cheap upgrade(though smaller).

Intel 320 Series SSDSA2CW080G3K5 2.5″ 80GB SATA II SSD. $150 – 70 = $80 (with free game and T-shirt)

well, HTPC ONLY need 40GB to load Win7 … But 40GB price is $99 while 80 GB is $80 after rebate. So math rules.

Grand total: $441 (after $90 MIR)

Let us see how this HTPC goes!

 

Random Thoughts before the Action

 

I have a plan to build two machines.

Current boxes:

1. Work machine: Q6600 + 4GB.

problem: no SSD, a little slow (esp. for video editing),  inefficient ( Q6600 marked at 130W). DVD drive dead.

2. Media PC: 2002-built P4 1.8G + 1GB

problem: very slow, even for simply task like turning it on then watch Video.

Grand plan:

1. New work PC: i7 2600K + 8GB (or 16?)

Use Intel SSD as boot disk, reuse existing hard drive as storage (until the hard drive price drops back to normal)

But, what to do with current Q6600? It is too energy inefficient for HTPC.

I may need an external BD burner. There is no point for an internal one. This will allow me later to buy MBA instead of MBP.

2. HTPC: due to configuration concern, I may go to full-size ATX case. Mini case is abundant, but I have to be very careful which board/aux to buy. Time wasting.

Basic idea: i3 + 4GB + SSD only

i3: $150?

4GB: $40

SSD: $100

board: $100

No video card required. But slot must be there.

Can we go fan-less?

Also, can we have GREAT remote experience? My current HP remote kb/mouse work, but rather clumsy

:

1) mouse is slow

2) kb is almost always out-of-power or not-in-sync. need reset repeatedly. So rarely used — even though it should be used more frequently to search video titles; or perform tasks like copying files around.

Some interesting remotes designed for HTPC are here.

Profiling on VS2008 platform

Stumpled upon “Very Sleepy”.

http://www.codersnotes.com/sleepy

It only requires code compiled with Debug symbol on. Note that it works only on 1st thread of the process — so does it work well with Excel XLL?

 

 

Template-based type-conversion operator cannot compile

class Base

{

public:

template<typename T> operator T(); // convert it to type T

};

 

client side code:

string vStrValue = myData["Key"];  //xxx

It works well for VS2008, gcc 3.4. However, Mingw c++ 3.4.5 complains the line with xxx cannot compile

call of overloaded function basic_string(Base& ) is ambiguous.

In fact, basic_string does have two constructors with 1 argument:

either it takes _CharT, or it takes _Traits.

 

This problem is still OPEN.

Why does MF matter?

only 0.5 bln missing. why does it matter?

 

Global Deriv has a talk that mentioned the different clearing models: CME v.s. ICE. It DOES matter.

 

In CME model, if MF commits fraud and goes belly up, other member firms have to share the loss. It is quite unfair and surprising ( being good guy is apparently penalized).

What happens in ICE model for CDS?

What will be the direction for central swap clearing?

 

Another big question is: how comes that 500m can be unaccounted for? why does CME bookkeeping system cannot tell (even after MF death) to tell who owns which? Details should be interesting.

 

Upgrading Thinkpad X61T to Windows 7 with SSD

Intel SSD 320.

key challenges: X61T does not have a CD/DVD bay. If we simply replace HDD by SSD: 1) is it bootable at all? 2) where to grab the installation ISO?

Below seems a workable plan.

http://matthewammann.com/2011/05/24/thinkpads-and-ssds-part-1-preparation/

I will highlight a few key points here.

 

1. MS releases a Win7 -> USB tool

Use it to copy Win7 ISO contents to USB pen.

Note that many complains that “ISO error” problem occurs. See here for a fix.

 

2. Make USD pen bootable.

http://www.intowindows.com/bootable-usb/

 

3. Make X61T allow to boot from USB

 

 

 

Recommended Softwares

http://forum.tabletpcreview.com/lenovo-ibm/23491-windows-7-clean-install-x61t.html

Also, if anyone is interested, here is what I’m running on my machine…

VLC: This is the best video player out there. HUGE codec support.
Handbrake: Good for converting video to play on different devices (iPhone)
Office 2007: Good ink support
Google Earth: Mapping app.
SketchUp 7: Open-Source 3D modeling App.
Open Pandora: A smaller version of Pandora
iTunes: Duh
Paint.NET: Free replacement for MS Paint
Picasa 3: BEST photo management and simple editing tool
Skype: free VoIP tool with video, file transfer, etc.
Digsby: simple app that manages chat clients and social networks (facebook, AIM, etc)
Evernote: Great Note-Taking App.
Chrome: Google’s browser, but no real add-in support yet.
Firefox: INSTALL THE BETA (3.1.2) the current version crashed
Crayon Physics: If you own a Tablet, you MUST get this game. It just came out final this week and it is absolutely amazing. I haven’t bought the full version yet, but I probably will soon.


Last edited by Jimmy Sky : 01-14-2009 at 07:49 AM. Reason: Expanded the post to include install instructions

Jimmy Sky is offline Reply With Quote

Crisis Review Reading

1. The Devils in the tails, The actuarial math and subprime mortgage crisis. Donelly

2. Credit model and crisis. Brigo

The preprint is freely available.

3. The formula that fell Wall Street. Sam Jones. FT.com 2009

It is about David Li, who studied at Waterloo (!). Note that Wired.com ran a similar article in 2009.

4. [name forgotten]

It is about how Intex ruined MBS world, as everyone used it and made it possible to “standardize” the contracts and hence the pricing.

Build XercesC

Recently had a lot of fun to get XercesC working for a big project.

First of all, highlight two commands very handy.

$file foo.so

Show how foo.so is built (flags, 32 bit or 64, platform)

$ldd foo.so

<- /home/bunny/bar.so

<- /usr/lib/libm.so

Show the dependency! It is critical as program won’t link if we only supply foo.so but some of its dependencies are missing.

 

 

1. There are two main release series, 2.x.x and 3.x.x both are listed on the website. They co-exist for a reason.

1) VS2008 cannot build v2.x ; in fact, there is no VS2008 solution file. If force an upgrading conversion, the build will fail.

2) v2.x cannot be built [I could be wrong, but it was not working out of box] for 64bit on Solaris.

3) Some old apps are wired with v2.x.

Lastly, v2 and v2 are not strictly API compatible.

2. How to create a MinGW build.

MinGW (ministic Gnu Windows) has a nice compiler suite. I used it to create .a on Solaris_i386 platform. The .a is in turn linked against other .a files, all compiled by MinGW C++, to create DLL and EXE. They are used on Win32.

The caveat is we have to use the entire MinGW compiler suite. It is easy to forget to use its ranlib. Then we can still generate .a, but it cannot be linked with other .a files.

Use command line below for Xerces-C-3.0.0

$./configure CC=/opt/mingw32/bin/gcc CXX=/opt/mingw32/bin/g++ RANLIB=/opt/mingw32/bin/ranlib –build=mingw32 –host=i386-mingw32msvc –disable-network  –prefix=~/homebrew/xercesc-v3

3. Makefile made adaptable

How to tell Makefile use proper headers/libs? Try below. For me, there are 3 targets: solaris_sparc, solaris_i386, windows.

XER = /opt/xercesc

ifeq ($(TARGET), solaris_i386)
INCL   += -I$(XER)/v3/solaris_i386/include
else
ifeq ($(TARGETTYPE), windows)
INCL   += -I$(XER)/v3/windows/include
else
INCL   += -I$(XER)/v2/solaris_sparc/include
endif
endif

ifeq ($(TARGETTYPE), solaris_i386)

    LIBS +=  $(XER)/v3/windows/lib/libxerces-c.a
else

    ifeq ($(TARGETTYPE), windows)
INCL += $(XER)/v3/windows/lib/libxerces-c.a
else

        $(XER)/v3/windows/lib/libxerces-c.a
    endif

endif

Follow

Get every new post delivered to your Inbox.