Monday, December 31, 2012

Year 2012 in review and a new hope


The beginning of winter is usually quite depressing. And the end of the year invites some recollections.

Source: Flickr

This was a really busy year, mostly devoid of any pleasures.

Source: Flickr

There was no much time for rest either...

Source: Flickr

Some pretty complex ideas emerged from intensive research, heavy head banging and crazy brain storming.

Prepared with Wordle




But there is a great hope for 2013! And the outlook is promising :)

Source: Flickr






Tuesday, December 25, 2012

WIG is 20%+ up YTD... mostly thanks to overnight gaps

The end of the year is near.

In the previous (nearly) 24 months, the broadest index of the Warsaw Stock Exchange - WIG - has gained more than 20%:

Fig. WIG performance YTD till 2012-12-21; source: stooq.com

This noticeable result has been generated thanks to a pretty small positive drift in daily returns - less than 0.1%:

Fig. WIG daily returns in 2012

But what's more interesting, a major part of this year's growth is a result of overnight WIG changes - i.e. gaps between previous day close and the following day's open:

Fig. WIG open-close and close-close daily returns

Meanwhile, while the 20%+ WIG's return is quite impressive, it is quite distant from the theoretical maximum gain possible to be realized with perfect prior knowledge.

Fig. Maximum theoretical WIG gain at 1H frequency.



Saturday, December 22, 2012

Eurogeddon - or how NOT to play Black Swans

Risky bet against ECB

In February this year a new fund aiming at the collapse of the EU was launched. The founders of the fund called Eurogeddon claimed 150%+ returns if the assumed scenario comes true.

After some 9 months, the actual fund performance is totally different from what was promised. The fund is 36,4% down since February 22, 2012. And chances of recovering from this drawdown are remote.

Fig. Eurogeddon performance February-December 2012; source: analizy.pl

I don't intend to discuss whether the investment theme (i.e. collapse of the EU) was right or not. Also, I do not plan to dispute the idea of launching a fund targeting ECB's unwillingness to support the Eurozone in critical situation.

As George Soros demonstrated in 1992 it is possible to successfully bet against a major central bank, but only if you are on the right side of the trade...

Eurogeddon design flaws

Instead I would like to focus on two key design flaws in construction of Eurogeddon.

1. using futures instead of options and CDS

Eurogeddon strategy was implemented mostly through purchases of symmetric futures contracts - index futures, currency futures and bond futures. Hence, the fund was (and still is) fully exposed to developments contrary to its assumed scenario.

Nassim Taleb, the person who coined the term Black Swan, recommended Black Swan-type strategies to be implemented using a portfolio consisting of mostly secure bonds, supplemented by a small portion allocated in out-of-the money options adequate to a given low probability scenario (or scenarios... - see next point).

Taleb's recommended implementation significantly reduces the risk of a adverse scenario development for potential loses are limited to premiums paid for the options. In addition, some of the premium should be covered by interest paid by the bonds.

2. reliance on a single low probability potential event

In addition, unlike typical Black Swan funds, like Universa or Pine River, Eurogeddon bet everything on a single scenario. Hence, if such assumed scenario does not materialize, Eurogeddon had nothing else it could benefit from. 

Most low probability high impact funds try to play numerous different scenarios. Sometimes they bet on contrary large developments in one particular area (i.e. possibility of huge decrease or huge increase in a price of some asset). They do not know which scenario will come true. They just want some of them to materialize over time.

There is a need for Black Swan type funds, but Eurogeddon is simply an inadequate vehicle.

I'm convinced there is a need for more Black Swan type funds. Unfortunately the construction proposed by the founders of Eurogeddon is incorrect.

Yes, there was a slight chance that the fund may bring substantial gains if the single scenario on which the fund was based comes true.

But the expected return based on the probability of the event and risk connected with the selected implementation employing symmetric instrument was too low. Even negative :(

I hope, the Eurogeddon story will not discourage people from Black Swan type funds. And I wish somebody launches a new better designed fund of this type.

[---]

Eurogeddon - offical results
http://opera.pl/pl/oferta/fundusze/eurogeddon/wycena/

Eurogeddon - peformance at analizy.pl
http://www.analizy.pl/fundusze/fundusze-inwestycyjne/profil-funduszu/notowania/OPE23/Eurogeddon-%28Opera-SFIO%29.html

Friday, December 21, 2012

Raising volatility before turning points?

For many people this may be quite obvious, but often volatility raises before local extremes (such as turning points).

This may serve as either the signal to close existing position or open the new position opposite to the current trend.

But of course, this is not always this simple :)

Fig. FW20 and volatility

BTW: The currently increased FW20 volatility may signal that some local extremum, or even a turning point, may be close for the main index of the Warsaw Stock Exchange.

Nevertheless, the mid term outlook for the market seems pretty bright as based on the volume-price analysis presented yesterday.

Thursday, December 20, 2012

When price action follows volume changes

Have you noticed the recent correlation between WIG20's (the key index of the Warsaw Stock Exchange) average volume and its value?

Seems that after the huge volume collapse since 2009, the trading in stocks constituting the WIG20 index has been gradually increasing for about a year.

What's interesting, this growth is accompanied by earlier stabilization and currently gradual increase in the value of WIG20:
Fig. WIG20 - average volume (n=252) and price

Meanwhile, the recovery in trading in WIG20 does not correspond with similar action in FW20 (WIG20 futures) volume.

Strangely, its quite the opposite. While average WIG20 volume raises, FW20 volume continues to fall:
Fig. WIG20 and FW20 average volume

The correlation between WIG20 and FW20 volumes seems broken.

Fig. WIG20 and FW20 volume details

Nevertheless, based on the observed WIG20 volume action, it is possible that we currently entering a longer period of stabilization or growth.

However, it is likely that the Warsaw market may face some correction in the short term - see the next post about volatility and turning points.


Beating market with technical analysis... by pure chance

Many people believe in power of technical analysis. Plenty of trading strategies are based on signals generated by technical indicators.

Much fewer people are trying to verify the quality of these indicators, though.

While working on some prediction models I have decided to put some of these technical indicators to the test.

First I would like to see, how these indicators are correlated among each other:

Fig. Cluster Dendogram for selected Technical Indicators

One can clearly see that some indicators - like RSI and CCI for example - are pretty close to each other.

Nevertheless none of the indicators were found to be correlated 0.95 or more to any other (note: the methodology for checking correlations between indicators was a little different than the one used for constructing the dendrogram)

Knowing something about the connections between the indicators is one thing. The totally different story is to verify their predictive power in relation to returns.

Here we can once more start with correlation:

FEATURES-RETURNS CORRELATION: 0.2 
     [,1]       [,2]        [,3]              [,4]         [,5]           [,6]             [,7]           [,8]            
[1,] "x.skew25" "x.trend25" "x.HH_LL.25.High" "x.change25" "x.up.ratio25" "x.MACD.12.26.9" "x.Ultimate.7" "x.kpss.level25"
[2,] "0.23541"  "0.22487"   "0.20162"         "0.18177"    "0.16651"      "0.16404"        "0.14708"      "0.14135"       

     [,9]      [,10]      [,11]      [,12]      [,13]       [,14]       [,15]            [,16]           [,17]    
[1,] "x.sd25"  "x.CCI.20" "x.ADX.14" "x.RSI.14" "x.OBV.252" "x.DVI.252" "x.kpss.trend25" "x.scaleTau225" "x.adf25"
[2,] "0.12177" "0.12023"  "0.11260"  "0.10858"  "0.10350"   "0.09826"   "0.09149"        "0.06537"       "0.05890"

     [,18]      
[1,] "x.hurst25"
[2,] "0.03247"  


As you can see, correlation coefficient rarely reaches 0.2.

Additionally, we can use RELIEF algorithm, that should help us identify non-linear relations in our model:


RELIEF: 0.2 
         x.sd25 x.HH_LL.25.High       x.OBV.252   x.scaleTau225  x.MACD.12.26.9        x.ADX.14      x.change25 
    0.194510019     0.193041550     0.189254007     0.168264622     0.137401102     0.125753731     0.083702019 
   x.up.ratio25       x.hurst25        x.skew25        x.RSI.14       x.DVI.252       x.trend25  x.kpss.level25 
    0.071718162     0.069785953     0.062099966     0.053276906     0.042572825     0.028786406     0.018634994 
 x.kpss.trend25    x.Ultimate.7         x.adf25        x.CCI.20 
    0.018233187     0.011072828     0.009101300     0.003876559 


Unfortunately, RELIEF seems to confirm the low correlation scores we got in the previous step :(

We can also try to combine some of our features (i.e. technical indicators in this case), using PCA:

Fig. PCA components for selected technical indicators

However, while ordinary PCA gives us some hopes for increasing the predictive value of the features we use here, the much powerful Kernel PCA is not so promising:

Fig. Kernel PCA for selected technical indicators

While the predictive power of technical indicators (at least as used in this analysis) seems to be virtually non-existent, it is not impossible to beat the market using it. Occasionally...

Fig. Some AT-based model realization
(market=+0.9%; strategy=+6.3%)

Sunday, November 25, 2012

Open source scientific computing: R, GNU Octave and.. Julia

I must admit a couple of year ago I felt in love at the first sight with R :)

R

For R is simply about creating algorithmic representations of numerical formulas.

R language is beautifully pure. You do not have to worry about all the overhead present in general-purpose languages like C++ or Java. There is no user interface to design either.

Probably the most serious R competitor is Matlab.

Since Matlab is a proprietary software, the development of cutting-edge tools seems to lag behind R.

However, there is an open source Matlab alternative available (for Linux and OS X, but unfortunately not for Windows): GNU Octave.



And the number of packages for GNU Octave has been (rather slowly...) raising: http://octave.sourceforge.net/packages.php
(although it seems development of many packages stopped in 2009)

I wasn't able to find an actively maintained IDE for GNU Octave (similar to R studio for R).



At least you can easily get Octave syntax highlighting in gedit.

The biggest shortcoming of both R and GNU Octave is probably their debugging capability. In case of R you can try Revolution R Enterprise from Revolution Analytics.

Revolution Analytics Enterprise Statistical Computing & Predictive Analysis using Open Source R


To familiarize yourself with GNU Octave you can start with Introduction to Octave. Much more details can be found in Octave online documentation.

R users should probably consult a list of similarities and differences between R and Octave, available in R for Octave users.

There is also a number of blogs about GNU Octave, conveniently aggregated at http://planet.octave.org/

And when you need a physical guide, you can read "GNU Octave Beginner's Guide" by Jesper Schmidt Hansen.

The most recent newcomer to the open source scientific computing area is Julia.

According to the information on the Julia's site:

"Julia is a high-level, high-performance dynamic programming language for technical computing (...)  
It provides a sophisticated compiler, distributed parallel execution... Julia itself, also integrates mature, best-of-breed C and Fortran libraries for linear algebra, random number generation, FFTs, and string processing. (...) 
"The syntax of Julia is similar to MATLAB®"

Julia is presumably faster than both R and Matlab and GNU Octave.

But its future is uncertain at this moment...

You can find some links to Julia resources at: http://www.statalgo.com/julia/

Friday, November 2, 2012

Downloading stooq market data in bulk

A couple of weeks ago I noted that there is some problem with reading market data from stooq.com using the method described in one of my previous posts.

It seems that after a number of consecutive successful downloads, stooq blocks access to single files from a given IP.

Probably downloading a large number of single files may be recognized as an unwelcome activity endangering accessibility of the site - a kind of a small DoS attack ;)

Nevertheless, there is another way to get the stooq market data without risking being blocked - you can download the complete database of stooq data or its section from the historical data archive: http://stooq.com/db/h/

One small hurdle - files in stooq historical market data archive are zipped, so you need to deal with compression. Fortunately, handling zip files is easily available in R :)

# download the complete archive

download.file("http://s.stooq.com/db/h/d_all_txt.zip",
              "stooq data.zip")

# unzip a selected file
unzip("stooq data.zip",file="data/daily/pl/wse indices/wig20.txt")

# access data from the unzippped file
quotes <- read.csv("data/daily/pl/wse indices/wig20.txt",header=TRUE)

After that you have the needed data loaded:

> head(quotes)
      Date  Open  High   Low Close Volume OpenInt
1 19910416 100.0 100.0 100.0 100.0    325       0
2 19910423  95.7  95.7  95.7  95.7   5905       0
3 19910430  93.5  93.5  93.5  93.5   7162       0
4 19910514  92.9  92.9  92.9  92.9  18300       0
5 19910521  95.5  95.5  95.5  95.5  14750       0
6 19910528  94.6  94.6  94.6  94.6  31440       0

When you know the name but not the exact path of the desired data file inside the zip, you can find it like that:

> (idx <- grep("wig20.txt",zip.content[[1]]))
[1] 6908
> 
> as.character(zip.content[[1]])[idx]
[1] "data/daily/pl/wse indices/wig20.txt"

That's it!


Thursday, November 1, 2012

How to play correlation?

On August 31st, I wrote about correlation characteristics of some currencies and stocks.

I haven't previously mention connections between stock indexes.

It is worth to note that the correlation relationship between indexes is disturbed by different hours when markets are open. For example, the Frankfurt Stock Exchange closes at 15:35 UTC, while the New York Stock Exchange trades till 20:00 UTC. You can partially reduce this discrepancy by using index futures which trade longer hours.

Nevertheless the average n=25 correlation between daily changes of S&P500 and DAX index of the German stock exchange is around 0.25.

However, at the end of August it stood at 0.797, or very close to its historical maximum:


Fig. S&P500 - DAX n=25 correlation of daily changes, 2012-08-31

It has retraced since then to a little modest, but still pretty strong 0.59:

Fig. S&P500 - DAX n=25 correlation of daily changes, 2012-10-31

In the meanttime the value of S&P500 moved from 1406.58 to 1412.16 (+0.39%), while DAX changed from 6970.79 to 7260.63 (+4.07%).

Fig. S&P500 and DAX 1M, 2012-08-31, source: stooq.com

Fig. S&P500 and DAX 3M, 2012-10-31, source: stooq.com

Correlation is a mean reverting process. But taking advantage of it is not an easy task...
Fig. S&P500 and DAX 25 days correlations



Wednesday, October 24, 2012

How to generate safe investment strategy?


I've wondering today whether it is possible to achieve a stable low risk equity line for a number for non-correlated investment strategies with mostly positive average returns and various individual volatilities.

Not all of the strategies needs to have positive averages - some very bad apples may happen in the portfolio:


Chart: Returns density of the worst strategy

When the number of combined strategies is low, it is quite easy to produce a loss:
Chart: 5 strategies

However, with the increase in the number of strategies, the equity line for the combined portfolio becomes stable. The problem is, the number of strategies you need to combine in order to achieve the desired result is quite large:

Chart: 1000 strategies
  

Thursday, October 18, 2012

There is a new algo player coming to town

There is a new player coming to town, and I'm very happy about it.

UniSystem FIZ is a new algorithmic fund run by Union Investment and managed by Robert Ślepaczuk, a Ph.D. from University of Warsaw.

You can get some idea about his views on investment strategies from a working paper he co-authored: "Investment Strategies Beating the Market. What Can We Squeeze From The Market?"

I've mentioned that I'm very happy about this development, since the Polish investment fund market cries for a radical change. I wrote about this here, herehere and here among others.

There are two things that worry me a little though.

First, I assume that better management practices require fund managers to put their money where their mouth is. In other words, they should invest a substantial part of their financial resources in the fund they manage for both sharing its successes and feeling the pain of losses.

Second, the UniSystem marketing site seems to present only the SIMULATED past results of the fund. I have not been able to find actual fund results there, but will return to this a bit later.


We've recently seen such an approach to selling investment products in the case of Eurogeddon and it didn't go very well so far:

Source: Analizy.pl



Nevertheless, I've finally found the actual official results of UniSystem FIZ - they're slightly positive YTD  and I hope this tendency will hold :)

The marketing simulation compares UniSystem to two market indexes: WIG20 and S&P500.

So how they really fared so far (till 2012-09-28) against these two benchmarks?



  • UniSystem:   +3.50%
  • WIG20:        +4.37%
  • S&P500:      +16.30%

The results seems quite stable even if inferior to the benchmarks.

But wait! I've seen somewhere such consistency of returns... Let's hope, some Black Swan will not strike another Union Investment fund...

Some more information about the UniSystem fund can be found here; http://www.union-investment.pl/fundusze-inwestycyjne/unisystem-1

Friday, August 31, 2012

Testing the significancy of correlations on the financial markets


The current one year EURPLN - USDPLN daily changes correlation is at amazing 0.9024.

And I'm not talking about the nominal values of these currency crosses, but about their daily changes, which in aggregate seem to apparently resemble random walk:

Fig. EURPLN - USDPLN n=250 changes correlation

Meanwhile, the historical average correlations over 250 days is 0.3996 for them - still pretty high, but far from the current level.

The historical correlation mean is at the far right of the simulated correlation based on the stable distribution fitted to the changes of these currency crosses, and pretty much above the theoretical correlations based on N(0,1) changes.

Fig. Theoretical correlations based on fitted stable distribution to EURPLN and USDPLN changes,
as well as N(0,1) distributions

Still, the current level of the correlation between these two currencies may be an outlier for the historical distribution of the n=250 correlation is rather flat, i.e. pretty uninformative.

You can find some other assets with much more stronger correlations, though,

Take for an example two companies listed on the Warsaw Stock Exchange: PKO and PEO.

Their current one year correlation is 0.7366. While this is still a little over the average of 0.6705, the historical distribution of correlations points to a stable and strong relation between these companies:

Fig. PKO - PEO n=250 changes correlation


On the basis of the analysis of correlations of random data, you can clearly say, that the relation between PKO and PEO is hardly an accident:

Fig. Theoretical correlations based on fitted stable distribution to PKO and PEO changes,
as well as N(0,1) distributions

The strong connection between PKO and PEO is additionally confirmed by their cross correlation:
Fig. Crosscorrelation and Average Mutual Information for PKO and PEO


Nevertheless, predicting market movements with correlation, may not be an easy task...




Tuesday, August 28, 2012

For Dummies: Intro to Generalized Method of Moments


FOR DUMMIES :)

While researching various concepts from statistics and econometrics I constantly find, that many of the materials describing the concepts I'm researching are often too obscure.

Before I get through history, definitions, derivations of formulas, proofs and lemmas to applications and examples - things that I'm really interested in when I'm just starting to research something - I'm usually too bored to care... :(

In addition, many authors of the research papers and article assume, the reader knows everything the author does, and sometimes some authors are simply reluctant to reveal all the details of their approach. As a result, descriptions of the methods or experiments sometimes lack crucial parts, while the examples are not very informative for being as unclear as the description of the method itself.

Hence, I decided to write a couple of posts that will try to present some concepts in layman's terms.

Hope, you will enjoy :)

*   *   *

Generalized Method of Moments (GMM)  is a method of estimating parameters of a probability distribution (such as mean and standard deviation in the case of normal distribution), by checking what possible values of distribution parameters lead to the best fitting moments of the sample drawn from the distribution.

Moments are some measures describing the shape of the distribution. In case of the normal distribution, the four first moments are:

1. mean
2. variance -> standard deviation
3. skewness
4. kurtosis

So let's say, we have n=100 observations x drawn from the normal distribution which has some unknown parameters:

x ~ N(mean, standard deviation)

> x <- rnorm(n,x.mean,x.sd)

Fig. Density of the sample


We would like to find out, what these parameters are.

Since, we are dealing with the normal distribution, it is very simple to find mean and standard deviation of the sample:


> mean(x)
[1] -7.176239

> sd(x)
[1] 6.105964

However, the sample parameters may not equal the distribution parameters.

Here we can use the before mentioned Generalized Method of Moments. It uses not only mean and variance (-> standard deviation), but also other moments of the distribution, to find better parameters.


You can use the sample estimates as starting points in searching for distribution parameters:


> t0 <- c(mean(x),sd(x)) # starting points <- sample estimates

> coef(gmm(g2,x,t0)) # GMM 2 moments

 Theta[1]  Theta[2] 
-7.176255  6.075357 

> coef(gmm(g3,x,t0)) # GMM 3 moments
 Theta[1]  Theta[2] 
-7.099134  5.981886 

> coef(gmm(g4,x,t0)) # GMM 4 moments
 Theta[1]  Theta[2] 
-6.995580  5.838024





In this case the more moments GMM uses, the value of mean increases while standard deviation decreases. As a results, the parameters estimated by GMM are getting closer to the true values of the distribution parameters, which are:


> x.mean
[1] -6.701526

> x.sd
[1] 5.493381


And that's Generalized Method of Moments in a nutshell ;)

BTW: You can alternatively use the Maximum Likelihood Method for the same task.

The results are very similar to GMM with 2 moments:


> o <- optim(c(0,1),objFun)

> o$par
[1] -7.176543  6.072980

But that's a totally different story :)

GMM portion of the R code based on Pierre Chausse, "Computing Generalized Method of Moments and Generalized Empirical Likelihood with R"

[ R source ]






Thursday, August 16, 2012

A simple way to simulate volatility clustering

Nearly a year ago I have mentioned an important characteristic of financial markets returns, i.e. volatility clustering.

This phenomenon was analyzed by Benoit Mandelbrot and presented in a work he co-authored: "A Multifractal Model of Asset Returns".

Volatility clustering is closely connected with heteroscedasticity (existence of periods of different variance) of financial times series. It can be said that volatility clustering is a special case of heteroscedasticity of time series. In presence of volatility clustering, variance is not only variable, but tends to cluster in time.

As I've mentioned in my previous post, volatility clustering needs to be addressed by risk management. But that's not all. It is also important in development of quantitative investment models, which should recognize and adapt to changes in volatility.

The simplest solution is to get rid of hetorscedasticity by normalizing the data:


But is is even more important, to understand what is really going on under the hood. For that you can generate a time series demonstrating volatility clustering behavior. Since you have full control over the simulated data, you can easily experiment with it and look for effects you can trade on.

MMAR is definitely a superior approach to simulate behavior of financial data, but sometimes a much simpler approach may be enough:

[ R code ]

Friday, August 3, 2012

Knight Fall or how to profit from a HFT computer glitch

On August 1st, a glitch in trading software at Knight Capital caused unusual behavior of various stocks listed on the NYSE.

At least one trader was able to profit from market disturbance caused by Knight Capital, by taking a short-time position in some affected asset.

Since, brief and limited in scope mini flash crashes and jumps are pretty common these days, it seems potentially profitable to create a high frequency strategy that identifies and trades such mispricings caused by other HFT algorithms.

Even that the Warsaw Stock Exchange has not implemented a HFT trading platform yet, unusual short-time disturbances are not total strangers here.

The chart below presents one such situation: the price of PZU, the largest Polish insurance company, decreased by 2.76% in one second on substantial volume on 27. July 2010.

Since PZU was a constituent of WIG20 index at that time, such a move should be reflected in the price of FW20 index futures. And in fact, the price of FW20 changed. But only after 5 seconds. It is a very long time in HFT terms...

Chart: PZU vs. FW20 futures contract, 2010-07-27, 10:47:39 -60 / +200 seconds
the blue bars represent volume


Wednesday, August 1, 2012

Random in, random out or how NOT to use artificial neural networks for prediction

In May last year I experimented a little with Google's machine learning tool - Google Prediction API.

One - I must admit stupid - experiment was to try to make Google Prediction API to forecast stock prices.

Quite unsurprisingly, all I received from Google Prediction API was a "flat line" at the level of the average stock price - meaning that the Google's machine learning engine was unable to estimate how the price will change.

The stock price returns/changes follow a random path which distribution is concentrated around zero, with fat and long tails (see: "Comparing probability distributions" and "Characterizing financial assets by Power Law alpha exponent")

Chart: Density of FW20(*) price changes
(*) FW20 - futures contract based on WIG20 index of the Warsaw Stock Exchange

There is a lot of noise that makes forecasting difficult.

I recently performed another experiment that confirms that observation. I tried to use artificial neural networks to find predictive patterns in raw returns series.

To simplify the task, I was trying to predict the direction of the changes, only.

In some cases, the proposed prediction model was able to correctly forecast between 70% and 100% of the changes. Pretty good, isn't it?

Chart: Actual (black) vs predicted changes (red)

Unfortunately, when you increase the number of tests, the performance rapidly deteriorates.

Ultimately, it settles at the 0.5 efficiency level - i.e. it is indistinguishable from random guesses:

> summary(random.fit)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.0000000 0.4285714 0.4285714 0.4957143 0.5714286 1.0000000 

> summary(fit.ratio)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.0000000 0.4285714 0.5714286 0.5085714 0.5714286 0.8571429

Chart: Change direction match - ANN vs random model

It does not necessarily mean, that neural networks are worthless in modeling financial markets.

But the described here approach is incorrect.

One have to pre-process financial market data before feeding them into models such as ANN.

[ R code ]


Wednesday, July 25, 2012

Much more red than you expect is lurking in Apple financial results

At the beginning of March I've written about the possibility that the Apple share price may be reaching inflection point.

This hypotheses was based on the George Soros' Boom-Bust Model.

Since then the previously dynamic growth of Apple stock prices has rather visibly lost steam:

Chart: Apple stock price, 1 year; source: stooq.com

Yesterday Apple reported its financial results for calendar Q2.

The company performance was pretty solid, overall. But it wasn't stellar as in the past. And the company reported the second consecutive decrease in revenues, that in addition were significantly lower than what analysts expected.

Still, it doesn't mean that Apple's existence is endangered in any way. At least not yet and most probably not in the nearest future.

However, when you take a deeper look on the financial data, you will notice a menacing trend - increasing number of Apple's financial dynamics (1st and 2nd order derivatives) is turning negative:

Spreadsheet: Apple Financials

You may combine that with market dynamics for iOS vs Android.

I wonder whether you can draw any analogies from the experiences of Motorola, Nokia or Research in Motion?


VaR: you cannot estimate the unknown

In previous post I have introduced the concept of Value at Risk (VaR).

I have mentioned that there is (at least) one serious problem with VaR.

This problem stems from the fact, that VaR uses historical data to estimate future risk.

But what if the historical data simply does not contain information allowing predicting the future?

In an earlier post I presented the case of UniWIBID fixed income fund which after 9 years of amazingly stable returns (albeit small - some 2 bps per day), experienced an unprecedented single day 2.7% drop that wiped out six months of gains.
Chart: UniWIBID daily returns from inception (2003-05-22) till the shock (2012-06-04)

As a result of extremely low pre shock volatility, VaR for UniWIBID was totally uninformative till the very last moment.

Based on the probability distribution of historical returns, it seemed not possible UniWIBID could generate loss at either 5% or 1% probability level. A remote chance of an extremely low loss - 0.0064% - was signaled at cumulative 1% level, only.

The probability that the fund will generate return equal to or below 0%, was 0.004403347, or 0.44%.

Chart: VaR and CVaR potential percentage losses based on pre shock historical returns for UniWIBID

Historical UniWIBID returns did not give any way to properly asses the risk of the fund.

UniWIBID returns alone did not tell anything about fund's concentration in particular assets, potential losses on such assets, probability of generating such losses and dependencies (correlations) between assets.

Meanwhile, based on the fund's annual report, close to 6,7% of UniWIBID's assets were invested in bonds of a development group PBG which recently declared insolvency. This means potential losses on PBG debt anywhere between 40% and 100%.

An extremely low probability event, such as bankruptcy of one of the largest companies in Poland which derives much of its revenues from government-financed contracts, that can potentially have a high impact outcome for UniWIBID value is a classic example of a Black Swan. And Black Swan-type risks cannot be properly modeled using VaR.
Chart: UniWIBID daily returns from inception (2003-05-22) till 2012-07-23, including shock on 2012-06-04

Chart: VaR and CVaR potential percentage losses after the shock

Two possible ways of dealing with shortcomings of VaR-type analysis and adjusting for previously absent situations are stress testing and comparative / multivariate analysis.

The first approach depends on proper identification of critical factors affecting the system, their dependencies, scale of possible shocks, as well their potential individual and joint impacts. The key problem here is predicting the unknown.

The second approach assumes similarity in performance of related systems and reversion to the mean (see my previous post "Black Swans and multivariate time series analysis")

[ R source for VaR / CVaR calculations & visualization in R ]