matlab | sscanf performance imt str2double

trFolder = 'datammmSH600519T';

trFiles = dir(fullfile(trFolder, 'trade*2013013*.csv'));

tr1D =read1csv(fullfile(trFolder, trFiles(1).name));


for i=1:length(tr1D.textdata(:,4))


dummy = sscanf(tt{:}, '%f');








mean reversion, deviation detector, pattern recognition

Nothing, including real time mkt data analyzers, can predict the future. They can point out unusual deviations which often precede reversions to norm. In such a case timing is unpredictable though.

Case in point — When I saw historical highs in copper price, I thought it would drop (reversion) within hours, or at most couple of days, but it just kept rising and destroyed my position. (A necessary condition for my undoing is margin. No margin, no collapse.)

I guess China Aviation Oil might have something like this?

Such a reversion is one type of pattern. Some patterns have a strong rational, logical basis. Consider historical vol’s mean reversion pattern. Consider the widening spread on-the-run vs off-the-run.
Mean reversion is one type of deviation detector.

dark pools – a few observations

Most common Alt Trading Service is the dark pool, often operated by a sell-side bank (GS, Normura etc).

A “transparent” exchange (my own lingo) provides the important task of _price_discovery_. A dark pool doesn’t. It receives the price from the exchanges and executes trades at the mid-quote.

Market order can’t specify a price. You can think of a market buy order as a marketable limit order with price = infinity. Therefore, when a market order hits a limit order, they execute at the limit price. When 2 limit orders cross, they execute at the “earlier” limit price.

Therefore, on the exchange, I believe all trades execute either on the best bid price or best ask. I guess all the mid-quote executions happen on the ATS’s.

Dark pool is required to report trades to the regulator, but often with a few sec longer delay than an exchange.

Dark pool may define special order types beside the standard types like limit orders or market orders.

Forex is quote driven, not order driven. Forex has no exchange. The dominant market is the interbank market. Only limit orders [1] are used. However, within a private market operated by a single dealer, a “market order” type can be defined. I feel the rules are defined by the operator, rather than some exchange regulator.

[1] A Forex limit order is kind of fake – unlike the exchange’s guarantee, when you hit a fake limit order that dealer may withdraw it! I believe this is frowned upon by the market operator (often a club of FX banks), so dealers are pressured to avoid this practice. But I guess a dealer may need this “protection” in a fast market.

use YC slope to predict 5Y bond’s return over the next 12M

Mark’s lecture 4 describes a famous “YC” carry trade strategy using T bonds. To keep things simple, we use zero bonds (coupon bonds same). Given a bond of 5Y maturity, next year’s return is defined as the NAV 12M from now vs the current NAV. In other words, the ratio of next year’s price over today’s price. It’s probably slightly above 1.0 or perhaps below 1.0.

This return factor is observable 365 days later, but we can predict it using the currently observable term spread, i.e. the 5Y yield – the 3M yield seen today. 
Idea is, if the slope is steep, then we expect that return to be high. Steep slope basically means we observe high yield at the 5Y point on today’s yield curve. Suppose it’s a high 8.8%. If we were to hold the 5Y bond to maturity, we would realize approx. (without compounding) 44% return. Instead, we actually plan to sell the bond next year, so we are forecasting this bond price next year, effectively the 4Y point on next year’s yield curve. (Apply P/Y conversion)
We expect that yield to remain around 8.8%, or equivalently, we expect the market yield on this same bond to remain. That would be higher than the riskfree rate (represented by the 1Y yield, say 0.8%).

However, If we are unlucky, the return factor (observable in a year) could come below the riskfree return factor today. (Note both deals cover the same loan period.)
* But then, we could cancel our plan and hold the bond to maturity and realize a total return of 44%. This is somewhat risky, because bond yield could rise further beyond 8.8%, hurting our NAV before maturity.
* Crucially, if the return over the next 12 months turns out to be lower than riskfree rate, then the subsequent 4 years must return more than 8.8% pa, since the return-till-maturity is fixed at 44%.

I have a spreadsheet illustrating that yield shifts in the next year may hurt the then NAV but the total return till maturity is unaffected.

EH (expectation hypothesis) actually says there’s no reason to prefer the 5Y vs the riskfree rate. Contrary to EH, empirical data show that today’s slope is a good predictor of the return over the next 12 months.

increasing corporate bond issues -> swap spread narrowing

Look at the LTCM case.

Almost all the issuers are paying fixed coupons. Many of them want to swap to Receive fixed (and pay floating). This creates an (increasing supply for the LFS i.e. Libor floating stream and) increasing demand on the fixed rate. Suppose Mark is the only swap dealer out there, so he could lower the swap spread to be as Low as he likes, so low that Mark’s paying fixed rate is barely above the treasury yield.

Note increasing demand on the fixed rate doesn’t raise it higher but rather hammer it down. Here’s why — if more job seekers now want to earn a fixed salary as a carpenter, then that fixed salary would Drop.

Oversupply to bonds would suppress bond prices, and increase bond yields. Oversupply of bank loans suppresses interest rate. I get many credit line promotion calls offering very low interest rates.

Now I feel it’s easier to treat the Libor floating stream (LFS) as an asset. The price is the swap spread.

When there’s over-supply of LFS, swap spread will tighten;
When there’s over-demand of LFS, swap spread will widen.

IRS – off-balancesheet #T-bond repo

The LTCM case P12 illustrated (with an example) a key motivation/benefit of IRS — off balance sheet. The example is related to the swap spread trade briefly described in other posts.

For a simple T-bond purchase with repo financing, the full values (say $500m) of the bond and the loan appear on the balance sheet, increasing the fund’s leverage ratio. In contrast, if there’s no T-bond purchase, and instead we enter an IRS providing the same(?? [1]) interest rate exposure, then the notional $500m won’t appear on balance sheet, resulting in a much lower leverage ratio. Only the net market value of the existing IRS position is included, usually a small value above or below $0. (Note IRS market value is $0 at inception.)

[1] An IRS position receiving fixed (paying float) is considered similar to the repo scenario. The (overnight?) rollling repo rate is kind of floating i.e. determined at each rollover.

Other positions to be recorded off balance sheet ? I only know futures, FX swaps, …

UIP carry trade n risk premium

India INR interest could be 8.8% while USD earns 1.1% a year. Economically, from an asset pricing perspective, to earn the IR differential (carry trade), you have to assume FX risk, specifically the possible devaluation of INR and INR inflation during the hold period. 

In reality, I think INR doesn't devalue by 7.7% as predicted by UIC, but inflation is indeed higher in India.
In a lagged OLS regression, today's IR differential is a reasonable leading indicator or predictor of next year's exchange rate. Once we have the alpha and beta from that OLS, we can also write down the expected return (of the carry trade) in terms of today's IR differential. Such a formula provides a predicted excess return, which means the carry trade earns a so-called “risk premium”. 
Note, similar to the DP, this expected return is a dynamic risk premium (lead/lag) whereas CAPM (+FamaFrench?) assumes a constant time-invariant expected excess return..