Monday, September 29, 2014

How to consistenly lose the money on the stock market?


I have recently written about back-testing some fundamental investment strategy using GieldowyRadar stock scanner for the Polish stock market.

The results of the back-test were quite impressive (even if one should not believe in them too much), but can we do the opposite? Can we create a strategy that consistently loses money?

YES, we can! :)

Sunday, September 28, 2014

Does you asset manager have a substantial stake in the fund he manages?


I first wrote about the Eurogeddon investment fund - the one betting on the collapse of the European Union - in February 2012. Now it is -62% down.

Source: analizy.pl

I was nonplussed by the simulations presented by the fund marketing team.

The execution strategy employed also seemed too much aggressive to me, especially taking into consideration the nature of the bet.

Nassim Taleb in his "Antifragile" book, stresses the importance of the convexity (i.e. a favorable assymetry) of the trades.

Convexity doesn't make you an automatic winner, but limits your loses and increases potential profits, when situation turns in your favor.

Otherwise, you risk turning your portfolio into a zombie with virtually no chance of raising up:




Many money / asset managers are not better in investing than monkeys, but usually they charge pretty step fees for their services.

Is there anything that can be done about it?

One possibility is to make asset managers to invest substantial part of their net worth into the funds they manage.

I am pretty sure they would be a little bit more careful with the investments they make... And it would not neccessarily diminsh the returns.


Saturday, September 27, 2014

KGHM: hedging copper with the seagull




The 14H1 KGHM report mentions a copper hedging strategy called the Seagull.


Basically, it hedges part of the revenues (40,5k tons in H2 vs. 283k tons produced in H1, or less than 15%) against copper prices falling below $7,500 / ton.

Since the copper price was approx. $6,800 / ton on Friday, the Seagull was in the air:

(assumes no premiums)
Notes: see post about visualizing option strategies

Friday, September 26, 2014

Back-testing value investing


I have been recently playing with a fundamental stock scanner designed for the Polish market - GieldowyRadar.

This scanner offers a number of predefined strategies based on some gurus stock selection criteria and allows to back-test them over 7 years.

The best back-test results are currently produced by "the Warren Buffett" strategy.

The average annual return of this strategy is 29.3% vs. -1.85% for WIG index.

The strategy takes into consideration indebtness, EBIT profitability, cash/free cash flow ratio, return on equity and market capitalization.

The scanner makes possible to back-test your own strategies. Unfortunatelly, some more complex conditions - including some used in the pre-programmed guru strategies - are currently not available.

Still, I was wondering whether it is possible to beat the best guru strategy using the limited scanner's back-test functionality while keeping the criteria fundamentally reasonable.

The answer is - YES! :)

"Buy Cheap" strategy: 1014% over 7 years

Thursday, September 25, 2014

Commodity prices and KGHM stock price


The stock price of KGHM is falling since the late August.

The KGHM moves follow changes in prices of copper and silver - two key KGHM products.


Source: stooq

Predicting commodity prices may be tricky, so let's focus instead on their past behavior in Q2 and - nearly finished - Q3.

Even though the prices of both copper and silver have decreased from the begining of Q3 till now, the average price of them actually increased - by 3% in case of copper and by 1,1% for silver.

Since KGHM reports its results in PLN, we should also take currency into consideration.

Because USD has strenghted in Q3, in PLN terms, copper price increased by 6.3% and silver by 4,4%.


black - Q2 prices and average
red - Q3 prices and average


                  Q2        Q3     Q3/Q2%
copper USD  309.0300  317.8600 0.03000000
copper PLN  938.0078  997.6208 0.06355287
silver USD 1965.0969 1987.2661 0.01128151
silver PLN 5965.5656 6232.2229 0.04469943

One additional element that may influence the KGHM Q3 results scheduled for publication in November, is the recently started Sierra Gorda mine production.

The effect of Sierra Gorda will be marginal in Q3, but should increase in the following quaters - posittivelly affecting both production and average cost levels.


Sunday, June 29, 2014

What the UK grid status data tells us about the renewable energy sources?


Thanks to the data available at the UK National Grid Status website, we are able to watch the evolution of the wind power generation in the United Kingdom from May 2009.

Over the last three years, the peak wind generation exceeded 20% of the total country electricity demand.

Even that this is lower than over 50% in Denmark, this number still looks impressive. However...


Saturday, June 21, 2014

A first look at the potential arbitrage opportunities in the electricity market


As previously observed, electricity markets can be strange at times.

Especially when there are two (or more) separate markets dealing with virtually the same article.

Usually such situation leads to arbitrage opportunities.

In case of electricity, we often have the separation of the Day Ahead Market (DAM) - when one declares amount of electricity he will provide or consume - and balancing market - when differences between DAM declarations are settled.

When you are a Renewable Energy Producer (RES), and forecasting your energy generation is not perfect, you face two possible scenarios:

  1. production excess - you have produced more than you declared (sold on the DAM)
  2. production deficit - you have produced less than you declared (sold on the DAM)
Let's focus on the later - production deficit.

Regulations differ, but usually when you are short (in deficit), you must buy the amount of the "missing" energy (forecasted amount declared/sold on the DAM minus the actual production). Unless you are able to do it on the Intraday Market (IDM), you must settled on the balancing market.

Normally the deficit prices are higher than the DAM prices, meaning that you pay for the errors in your production forecast.

For example, in Romania, the average difference between DAM and deficit prices was minus 98 RON / MWh (approx. minus 23 EUR / MWh) over the October 2013 - May 2014 period (some preliminary data used).

However, on rare occasions (<5% of the cases), deficit prices were lower than DAM prices.

Fig. Distribution of the differences between DAM and deficit prices in Romania, 2013-10 - 2014-05

Hence, selling as much energy as possible (for example your whole installed capacity) on the DAM, for the moments when DAM price is expected to be higher than deficit price would bring you a profit (on average 21 RON / MWh).

A "tiny" problem remains though. How to predict when DAM>deficit? :)

Fig. Differences between DAM and deficit prices by the hour

Fig. Average differences between DAM and deficit by months and hours
Note: all values negative, best -39 RON

Wednesday, June 11, 2014

Let the wind blow or forecasting the wind power

I have mentioned recently, that the production of renewable energy sources is difficult to predict. Let's examine some of the challenges.

The difference between production and forecast can fluctuate wildly, sometimes exceeding +/-50% of the installed wind farm capacity.

Chart: differences between production and P50 forecast
(P50 forecast is the average expected energy production)

The distributions of differences between production and forecast have high kurtosis, and both tails are pretty long. 

Chart: Distribution of differences between production and P50 forecast
(P50 forecast is the average expected energy production)

It seems, assumption of the normal distribution of the production, customarily used in wind power forecasting, may not always be correct.

Chart: Assumed normal distribution of (long term) power production
(P50 forecast is the average expected energy production)

It shouldn't surprise then that production often exceeds both conservative P50 and aggressive P90 forecast levels.

Chart: Production (gray bars) vs. P05-P90 forecast band (red and green dotted lines)

On the other hand, production significantly lower than forecast is also not welcome. Since forecasts are the basis of the declared planned production levels on the Day-Ahead Market (DAM), all deviations require costly balancing.

The forecast spread, or the width of the forecast (difference between P90 and P05), which should reflect the forecast probability does not always add any value.

Chart: Forecast spread vs. production


Also, it doesn't help that in addition to the weather-related production forecast, one needs to deal with planned availability of a plant. The planned availability is connected among others with scheduled maintenance, but not everything always goes according to the plan.

As a result, a plant operator needs to deal with additional random variable. It sometimes happens that the plant stops producing long before the planned availability goes to zero, and starts producing, when the planned availability still equals zero.

Chart: Production (black line) vs. planned availability (grey area)

Weather is a factor that affects both production forecast and availability. While wind may be strong, suggesting high production, temperature may lead to operational problems that may not be fully reflected in planned availability. As a result, one may experience noticeable periodic disparity between forecast and production.

Chart: Average monthly difference between production and P50 forecast for different farms

Even with operational information, less than one year of data is too little to decide whether we face here a seasonal effect which should be adjusted for in the next years, or one time event.

To get better alignment between forecast and production the following directions seems promising:
  • use energy storage
  • develop better weather forecasting models
  • include farm operational data it into the production forecast models
  • utilize prices, and price forecasts, where adequate
For more about wind forecasting, see: https://pinboard.in/u:mjaniec/t:res/t:wind_forecasting/

Sunday, June 8, 2014

Some curiosities of the European power markets


It should not be a surprise that power markets in Europe are amazingly complex.

There are both many different market segments, and rules governing the segments in various countries are often very different.

Among the key market segments we have:

  • day ahead market (DAM) - where planned electricity deliveries and prices for the next day are set
  • intraday market (IDM) - where both electricity generators and users try to adjust their positions
  • balancing market - where differences between plans (forecasts) and physical delivery/consumption are settled
  • futures and derivatives market - when expected mid- and long-term prices are established
The growth of the renewable energy sources (RES) such as wind and solar put this structure to a test and also added new market segment:
  • green energy rights market - where various green energy-related rights such as green certificates / certificates of origin / guarantees of origin are traded
The key problem with renewable energy sources is that they are intermittent (they work when the required "fuel" such as wind or sun is available) and the production is hard to forecast. This problem is exacerbated by the difficulties with energy storage.

This leads to many curious market behaviors like negative prices:

Fig. DAM prices on FELIX
Source: EEX

-2 EUR does not look too scary, but minimum theoretical prices on EEX are -500 EUR for DAM and... -10,000 EUR for IDM!

Fortunately, over the recent year the prices have "just" touched -250 EUR a couple of time:

Fig. Germany/Austria IDM 1yr
Source: EEX

I am going to examine the characteristics and behavior of the power exchanges and the impact of the renewable sources in the next posts, so stay tuned :)


Saturday, May 3, 2014

AES CBC

A couple of months after my first post about the AES encryption in R, I decided to update the code with more stronger AES CBC.

Also some minor errors were corrected :)

I hope to start posting some more interesting stuff soon.

In the meantime, there is no beach in Madrid :)



[ R source ]

BTW: Maybe someone know how to handle the whole encryption process in memory with R?

UPDATE 2014-05-19
In-memory decryption problem solved thanks to r2evans! :)