# Excel (and French people) are such a pain in the…

A few days ago, I published a post entitled extracting datasets from excel files in a zipped folder, because I wanted to use datasets that were online, in some (zipped) excel format. The first difficult part was the folder with a non-standard character (the French é). Because next week I should be using those dataset in a crash course in Gabon (in Africa), I wanted to make sure that everthing will go fine when we will run the code. And discussing @3wen‘s trick on Day 1 was maybe not the best way to explain that R is a very simple tool that should be used for data analysis…

To make thing easier, I did upload the xlsx files on my webpage. I wanted to use the xlsx R package. Unfortunately, on my linux laptop, I have troubles installing that package.

# Financial model complexity

Today, Olivier Scaillet gave a great talk on fast recursive projections. The idea was great, and the talk was amazing. A great plenary session talk actually. And after lunch, while we were having a coffee, we started to discuss about financial model complexity, mentioning that sometimes, traders and quants are lost, and it might be good to spend more time on basics than on very advanced stuff (which was, in fact, the general idea of my own talk, yesterday). And Olivier recalled that story, on how a rookie excel error led JPMorgan to misreport its VaR for years, published on the blog http://zerohedge.com/…. The short story is that the JPM’s reported VaR did rise by some 93% year over a year, from 2011 to 2012 (while it was decreasing for all competitors). The reason is explained in the very last page of its JPM task force report

… a decision was made to stop using the Basel II.5 model and not to rely on it for purposes of reporting CIO VaR in the Firm’s first-quarter Form 10-Q. Following that decision, further errors were discovered in the Basel II.5 model, including, most significantly, an operational error in the calculation of the relative changes in hazard rates and correlation estimates. Specifically, after subtracting the old rate from the new rate, the spreadsheet divided by their sum instead of their average, as the modeler had intended. This error likely had the effect of muting volatility by a  factor of two and of lowering the VaR…. It also remains unclear when this error was introduced in the calculation.

(Tyler Durden did highlight some parts, and I keep it like that). Let’s admit it: we did have fun about practitioners (actually, there was also a quant sitting with the two of us). But on the other hand, it is a bit scary, to see that we spend so much time to implement complex algorithms, to faster computations, and finally, we end up with a mistake in a spreadsheet….

# Rationality, and MS Excel (and other calculators)

This morning, Mathieu had a nice experience in his course on computational method in actuarial science. But let us start with some mathematical formal definitions.

First, recall that $y^x$ is – somehow – a standard expression. No one should be surprised to see such an expression. Generally (as explained in http://en.wikipedia.org/… ), this function is defined only when $y\in\mathbb{R}_+$. The idea is that the definition of $y^x$ is that

$y^x = \exp\left(x\log[y]\right)$

And it is a definition. Such a function exists only if $y\in\mathbb{R}_+$ (maybe excluding $0$). This would be a standard definition in real-analysis.

Now, this ‘power’ function appears also in complex analysis, when dealing with unit roots. From instance, if  $z=y^{\frac{1}{k}}e^{i \frac{2n\pi}{k}}$, where $y\in\mathbb{R}_+$ and $k\in\mathbb{N}_\star$, for some $n\in\mathbb{N}$, then $z^k=y$. Thus, in complex-analysis it might be more complex to define properly $y^x$ since it might not be unique. But we can relate (sometimes, when $x$ is the inverse of an integer, or maybe a rational number ?) with roots of polynomial functions. So far, nothing new…

Let us get back to Mathieu’s problem. Actually, in his course, he wanted to compute $(-8)^{\frac{1}{3}}$. With a French version of Excel, entering

you do get $-2$. If you look at the ‘help’ window, you have some more details

It looks like this hat function can be used to define objects such as $y^x$. But with

you get

(meaning that this is a problem…). It is also possible to use the power (puissance in French) function of Excel,

Here, you also get

The weird part here is that, in the ‘help’ window, you can read that this power function can be used with any number in $\mathbb{R}$.

Another point… what about $(-8)^{\frac{2}{3}}$ ? Somehow, it is just the square of the previous one (with the fraction)… Here, typing

you get

(similarly with the power function). So clearly, it is not that simple to use this power function. Now, if you use Google (which is now my new online calculator when I am in class, when I cannot use R), if the power is a fraction (or to be more specific the inverse of an integer), then it works as Excel

you get

But if you type (which should be close, from a continuity property of the power function)

you get

and similarly

On Wolfram Mathworld, enter

Mathematica does recognize that we try to deal with unit roots: the result is here

with – as expected – a numerical approximation

With Matlab, Mathieu did obtain the same as Mathematica (its decimal approximation). And to conclude, with R, Mathieu did obtain

> (-8)^(1/3)
[1] NaN
> (-8)^(.333333333333333)
[1] NaN

So for R, you cannot use this hat function on negative numbers.

Now, how can we interpret those outputs ?

1) My understanding is that clearly, with MS Excel, $x^{ab}\neq \left(x^a\right)^b$since

$(-8)^{\frac{2}{3}}\neq \left((-8)^{\frac{1}{3}}\right)^2$

which is problematic. For instance, in insurance, with monthly discounts, we do have functions like $u^{\frac{k}{12}}$. What if

$u^{\frac{k}{12}}\neq \left(u^{\frac{1}{12}}\right)^k$

2) The problem comes – probably (MS Excel is not an open software, so it might be hard to check) –  from the fact that $y^{\frac{1}{n}}$ is interpreted as an inverse of a (possibly) bijective function. To be more specific, $x=y^{\frac{1}{n}}$ means that $x^n=y$. When $n$ is an odd integer, then (in real-analysis) there is a unique inverse, and thus, $y^{\frac{1}{n}}$ is uniquely defined, since $x\mapsto x^n$ is a bijective $\mathbb{R}\rightarrow\mathbb{R}$ function. This is what MS Excel (and Google) is doing: $x\mapsto x^3$ is a bijective $\mathbb{R}\rightarrow\mathbb{R}$ function, so $(-8)^{\frac{1}{3}}$ means that we need to find the unique (real) value $x$ such that $x^3=-8$. Thus, somehow, it makes sense to return $-2$.

3) There is still a problem with Google, and Mathematica. That is fine to return unit roots in $\mathbb{C}$. But how comes there is only one value ? I mean, yes $1+\sqrt{3} \ i$ is a possible answer, since

$(1+\sqrt{3} \ i)^3=-8$

but one can also observe that , and similarly, $(-2)^3=-8$ and

$(1-\sqrt{3} \ i)^3=-8$

One can check with

With R, since we do not deal with power function here, but with roots, if we want to find $x$ such that $x^3=-8$, the function is

> polyroot(c(8,0,0,1))
[1]  1+1.732051i -2+0.000000i  1-1.732051i

Which is different… Weird isn’t it ?