Tuesday, December 23, 2014

When marginal price of a call goes to zero

Having an unlimited mobile plan is a very nice thing - you do not need to worry you will pay more than you expect for using your smartphone.

Also, at some point (often quite early in a month), successive calls become free.

Or to be precise - the marginal price of a call goes to zero.

Still, I was wondering, how much of the unlimited am I actually using.

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 your 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


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! :)

Saturday, February 15, 2014

Visualizing option strategies with R

It has been a while since I wrote something about options.

Recently I found myself in a need for simple tool for visualizing option strategies.

Option strategy is a combination of a number of option positions - both long and short - and sometimes underlying assets (such as equities) - i.e. it has multiple "legs".

To calculate the payoff (*) of the option strategy one needs to know:

  • types of assets used to construct a particular strategy - possibilities include CALL and PUT options, as well as underlying assets
  • type of positions opened - options can be bought or sold (written); underlying assets can be bought or sold short
  • option strike prices - any option has a price at which it "activates"; for example CALL option with a strike price of 100, generates profit only when the price of underlying asset is above 100
  • option premiums - buying an option has a price, writing it generates some income
  • amount of assets utilized - for example you can buy more than 1 option
Transaction costs are not cover by my simplistic model.

(*) payoff is the value of the strategy at expiration; it should not be confused with the theoretical value derived from option pricing models such as Black-Scholes

Probably the simplest options-related investment strategy is a purchase of some stock and hedging it with PUT option - as a result, while one have unlimited profit potential, his loss is limited with the help of PUT option:

> assets.mat
     trans type   strike price amount
[1,] "buy" "base" "40"   "0"   "1"   
[2,] "buy" "put"  "35"   "2"   "1" 

A pure option strategy is Bull Call Spread, when one simultaneously buys and sells CALL options with different strike prices:

> assets.mat
     trans  type   strike price amount
[1,] "buy"  "call" "40"   "3"   "1"   
[2,] "sell" "call" "45"   "1"   "1" 

Option strategy can consist both long and short positions, and different amounts of options at opposing sides - like in the Call Backspread:

> assets.mat
     trans  type   strike price amount
[1,] "sell" "call" "40"   "4"   "1"   
[2,] "buy"  "call" "45"   "2"   "2" 

Option strategy can be composed with more than two legs - like in the Condor:

> assets.mat
     trans  type   strike price amount
[1,] "buy"  "call" "35"   "11"  "1"   
[2,] "buy"  "call" "55"   "1"   "1"   
[3,] "sell" "call" "40"   "7"   "1"   
[4,] "sell" "call" "50"   "2"   "1"  

Obviously there are many more different option strategies. You can learn about them at the following places:

And you can experiment with them and any other ideas connected with option strategies with the R code I have prepared. Enjoy!

[ R Source ]

Thursday, January 9, 2014

Basics of scorecard model validation

Source: DW

Some time ago I wrote about Somers' D measure of association.

Somers' D is one of the many tools that can be used for validating scorecard models.

The task of a scorecard model is to assign scores, such as ratings, to the clients (in case of corporations usually called "counterparties") of a financial institution.

The ratings assigned by a scorecard model should reflect the probability of the client not meeting its obligations towards a bank or other financial institution.

As I showed in my previous post about relation between probability of default and interest rates, the higher risk of default needs to be compensate by higher interest rate charged.

Two aspects of a scorecard model are usually examined to assess the correctness of the model:

  1. discriminatory power
  2. calibration

Discriminatory power is about the model's ability to rate clients/counterparties according to their credit quality, i.e. verify whether clients/counterparties of similar quality fall into similar ratings classes.

Meanwhile, calibration verifies whether ratings given are correct indicators of future defaults. In other worlds, we compare probability of default forecast by the model with actual ("true") defaults, here.

Tools commonly used for the assessment of the models discriminatory power are Receiver Operating Characteristic (ROC), above mentioned Somers' D and Gini coefficient.

There is a number of tests for verifying model calibration. Probably the most often cited in the literature are: 

  • binomial test
  • Hosmer-Leweshow test
  • Spiegelhalter test
  • normal test

In most of the cases, the scorecard validation tests require knowledge of the previous scores and actual past defaults. 

When previous scores are not available and cannot be retroactively calculated, some external ratings - such as issued by credit agencies - may be used. An additional condition should be met in such a situation - the scores generated by the internal model need to be aligned with the external ratings.

As I noted before, the actual default rates change over time. Meanwhile, most of the scorecard validation tools does not take this fluctuations into account. They assume that the future will be similar to the (averaged or recent) past.

In addition, the mentioned above validation tools do not take into consideration the differences in characteristics of the past and current assets being evaluated by the scorecard model. It is assumed the model will take care of the differences. However, the assets being rated may have pretty complex internal structures hidden from the model.

Lastly, scorecard models do not usually say anything about the possible recovery rates and resolution times.

If you would like to play a little with scorecard validation tests, you may take a look at:

[ Scorecard validation tests in R ]

[ Scorecard validation tests examples in R ]

[ Measures of association in R ]

Validation tests in R