środa, 22 lutego 2012

You can retroactively simulate anything

A new systemic risk insurance fund was launched yesterday - Eurogeddon.

The fund aims at the collapse of the euro and the run on the European banks over the next three years.

According the fund's marketing materials, Eurogeddon would have made nearly +150% return at the time when Lehman Brothers went bust, if only it was active at that time (it was launched yesterday):

Chart: Simulation of the Eurogeddon hypothetical returns over the past five years

The simulation presented above, shows purely hypothetical Eurogeddon returns employing posterior knowledge about the events in the analyzed period, the macroeconomic view retroactively adapted to them and  trading strategy devised on the extrapolation of the past trends.

Therefore I hereby present an even better approach :)

I take a number of liquid assets, such as currencies, index and commodity futures and take positions in them (both long and short), based on the past knowledge of the daily movements of these assets.

As you can imagine, the results over just a couple of years would have been amazing...

Chart: Simulation of the returns of a hypothetical perfect knowledge fund over 4 years

Chart: Asset allocation of a hypothetical perfect knowledge fund

Chart: Simulated daily trades of a hypothetical perfect knowledge fund

Chart: Distribution of simulated daily trades

Isn't such SIMULATED TRACK RECORD impressive? :)

More information about the Eurogeddon fund: http://opera.pl/pl/oferta/fundusze/eurogeddon/co-wyroznia-eurogeddon/


[ R source code ]

Searching for Facebook value with differential evaluation


I have mentioned recently the Facebook's IPO preparations and its desire to sell its share at the $100 billion valuation.

A little later I have read an interesting analysis of the Facebook valuation based on the logistic growth model fitting by Peter Cauwels and Didier Sornette.

Taking this opportunity, I decided to test a brute force logistic model fitting to the actual data, using both simulated annealing and differential evolution optimization methods as implemented in R.

The results of such an approach are a little but not substantially different from the Cauwels-Sornette approach, at least in the differential evaluation case:


> # p0, k, r
> x    # differential evolution
      par1       par2       par3 
  1.000000 920.729890   1.262142 
> x2   # simulated annealing
[1]   0.1005737 505.2465850   1.9097082



środa, 15 lutego 2012

Playing with intraday pair trading

Chart: Simulated intraday pair trading visualized

I consider a true hedge fund to employ market neutral strategies. Such strategies should be indifferent to the market conditions and not correlated with market performance.

Market neutral strategies usually employ statistical arbitrage. This mainly means two things: 

1) trades generate positive returns ON AVERAGE, 

2) trades usually have at least TWO OPPOSITE LEGS, such as long position in an undervalued asset and short position in the overvalued asset.

A classical example of such statistical market neutral strategy is pair trading.

Pair trading is a simple strategy in principle. But you can implement it in very many different ways.

And the devil and the returns are in the details... :)

środa, 8 lutego 2012

Analyzing draw-downs

Chart: Cumulative 500 random returns

Let's take a series of randomly generated 500 returns in the range of 0.92 to 1.10 (or -8% to +10%).

Now, let's try to calculate some basic potential loss statistics for this series based on the observed draw-downs:

Number of the draw-down losing sequences:

> downsN
[1] 228

First draw-downs losing sequences:


d(dd_stats)
     start stop length         loss
[1,]     1    1      1 -0.005949528
[2,]     2    3      2 -0.122208798
[3,]     4    4      1 -0.024784714
[4,]     5    6      2 -0.098330307
[5,]     7    8      2 -0.060649554
[6,]     9   11      3 -0.137897672

The worst draw-down losing sequence in terms of value:


> min(sapply(drawdowns, function(x) x$result-1))
[1] -0.2625977

The longest draw-down losing sequence:

> max(sapply(drawdowns, function(x) x$length))
[1] 6

Average loss of draw-down losing sequences:

> mean(sapply(drawdowns, function(x) x$result-1))
[1] -0.07221781

The bottom, peak and the last value of the process:

> min(cumreturns)-1; max(cumreturns)-1; cumreturns[length(cumreturns)]-1
[1] -0.0683741
[1] 46.30488
[1] 38.46427

UPDATE 2012-02-10

Chart: Cumulative random sequence of 500 returns [-8%, +10%] and draw-down line

Above I did calculate the statistics for losing sequences not draw down.

The correct results (for a different random process) should be:

> downsN # number of losing sequences
[1] 214
> 
> head(dd_stats)
     start stop length         loss
[1,]     1    1      1 -0.039665746
[2,]     2    3      2 -0.097175026
[3,]     4    4      1 -0.001900723
[4,]     5    6      2 -0.076761609
[5,]     7    8      2 -0.083846687
[6,]     9   10      2 -0.062338201
> 
> min(sapply(drawdowns, function(x) x$result-1)) # worst sequence
[1] -0.2556858
> 
> mean(sapply(drawdowns, function(x) x$result-1)) # average sequence
[1] -0.06519456
> 
> max(sapply(drawdowns, function(x) x$length)) # longest sequence
[1] 6
> 
> mean(sapply(drawdowns, function(x) x$length)) # average length of sequence
[1] 1.658915
> 
> # bottom, top, last result
> min(cumreturns)-1; max(cumreturns)-1; cumreturns[length(cumreturns)]-1
[1] -0.06119829
[1] 161.2614
[1] 85.06354
> 
> 
> min(dd) # worst draw down
[1] -0.5623983


R Source

czwartek, 2 lutego 2012

$100 billion Facebook IPO


Facebook has filled to raise $5 billion in the IPO yesterday. The valuation is told to be between $75 and $100 billion. How this compares to the public tech companies?


Data: Google Finance, Bloomberg

As Bloomberg notes, $100B valuation is equivalent to 26.9x Facebook's SALES. Not EARNINGS. By comparison Google's current P/E is 19.51 and P/S = 4.06.

At the time of its IPO, Google's P/S ratio stood at 8.7.

niedziela, 22 stycznia 2012

What do you get for the fund management fees?

I've recently mentioned that only some small Polish non-benchmark (semi-hedge) funds decoupled from the general market deterioration in 2011.

But how they really compare to the market and how they are correlated between themselves?

From June 2009 till January 2012 Gandalf SFIO virtually didn't change its value:


The annualized return over this period is -0.14%. Meanwhile, WIG20 returned +12.15%.


The main feature of Gandalf SFIO is its low negative correlation with the index.

As for Opera Alfa-Plus, the fund returned +22.8% since inception and +8.62% annualized:


Still that's worse than WIG20 which grew by +31.2%:



In contrast to Gandalf SFIO, the correlation between Opera Alfa-Plus and WIG20 is slightly positive.

It gets quite interesting when you compare performance between the funds:



Opera Alfa-Plus has clearly been better performing than Gandalf SFIO so far, but the funds have been negatively correlated, so the future may change that.

Nevertheless, beating the index (basic buy and hold strategy) is not an easy task. So what do you get for the management fees?



piątek, 20 stycznia 2012

Distance and dimensions




Something totally different, today :)

At least as measured by Minkowski distance, distance between three-dimensional objects is inversely proportional to the number of dimensions of the space in which one measures distance.

For example, distance between two randomly selected points may be 150.90 units in R^3, while it drops to 129.86 units, or by 13,94%, in R^96.

So, if one would be able to make shortcuts through some hypothetical additional dimensions, one could  travel faster than others moving in plain R^3. The potential gains are not huge, though.

The difference between distances in various R^n spaces decreases quite significantly and around R^20, the incremental gains are usually smaller than 1% per additional dimension:


      dimensions distance    difference   difference%
 [1,]          3 150.9008  1.509008e+02           Inf
 [2,]          4 140.6339 -1.026687e+01 -6.8037222878
 [3,]          5 135.7465 -4.887388e+00 -3.4752557745
 [4,]          6 133.1936 -2.552873e+00 -1.8806176731
 [5,]          7 131.7919 -1.401690e+00 -1.0523697580
 [6,]          8 130.9986 -7.933852e-01 -0.6019982623
 [7,]          9 130.5400 -4.585113e-01 -0.3500124575
 [8,]         10 130.2709 -2.691661e-01 -0.2061942603
 [9,]         11 130.1109 -1.600260e-01 -0.1228409661
[10,]         12 130.0147 -9.616443e-02 -0.0739096136
[11,]         13 129.9564 -5.832922e-02 -0.0448635601
[12,]         14 129.9207 -3.567275e-02 -0.0274497876
[13,]         15 129.8987 -2.197770e-02 -0.0169162448
[14,]         16 129.8851 -1.363012e-02 -0.0104928834
[15,]         17 129.8766 -8.503742e-03 -0.0065471273
[16,]         18 129.8712 -5.334217e-03 -0.0041071429
[17,]         19 129.8679 -3.362549e-03 -0.0025891404
[18,]         20 129.8658 -2.129199e-03 -0.0016395115
[19,]         21 129.8644 -1.353778e-03 -0.0010424441
[20,]         22 129.8635 -8.640018e-04 -0.0006653107

czwartek, 12 stycznia 2012

Reconstructing missing observations with R

I've been playing with reconstruction of missing observations for the last couple of days.

Say you've got a quotations of some equity that miss some data points.

You may want to have them reconstructed for example for pairs trading.

What do you do then?

Chart: example of VAR reconstruction of missing data


I've preliminary tested a number of potential methods from simple mean to Dynamic Linear Models to Random Forest.

Performance varies, but for the moment three reconstruction methods seems to lead the pack: simple mean, some Dynamic Linear Model and Vector Autoregression.

Chart: comparison of various reconstruction methods for one case




Some thoughts on the Polish pension funds


The Polish (mandatory) pension funds - OFEs - were down in 2011. Average one year performance (as of yesterday) was -3.72%.

Nevertheless, they are on average +192% up over their 13 year period of existence. And that translates into a quite nice +8,6% CAGR.

And - what's important - they have clearly beaten the stock market:

Chart: ING OFE vs WIG20, 1999-2012, stooq.com

However, what's worrying is a very high correlation between all the funds:

Chart: OFE prices 1999-2011

The correlation rank between OFEs keeps between amazingly thin range of 99,51% and 99,97%:


Chart: OFE correlation distribution 1999-2011

Clearly, OFEs are not competitive. For extremely high correlation they are also a potential source of systemic risk.


środa, 11 stycznia 2012

WIG20 - S&P500 decoupling

Chart: WIG20 vs S&P500 futures 5 days, 2012-01-10, stooq.com

The Polish stock market index WIG20 has recently decoupled from the US market index S&P500 quite significantly.

This divergence has lasted for some time now:

Chart: WIG20 vs S&P500 futures 3 months, 2012-01-10, stooq.com

Something will have to correct... But which one?

Or is it just an opportunity for a convergence trade without trying to guess the direction?

Was the yesterday's funny WIG20 action a signal of the future developments?

Questions, questions and more questions... :)

Nevertheless, it's worth keeping in mind that even though Polish and US markets are highly correlated, correlation is not a stable measure. It's much safer to check the spread between the markets based on their cointegration.