Stability and Beer

Today's post is certainly one of the most important applications of mathematics, so read it carefully and do practical experiments.

I recently came across this nice video by Matthias Kreck from the University of Bonn.




Watch and enjoy!

Sports Noise Amplification

Last week, I gave a talk at the Wolfram Data Summit. Since I am a physicist without any formal education in the way of data science, it has been exciting two days with lots of new input and food for thought. Having heard so much about the "internet of things" and geospatial data gave my motivation the final push to start a little private "data science project" that has been lurking in the back of my mind for quite a while...

If you have, up to now, pictured MathConsult'ers as nerds spending their days (and nights) in front of computers, with pizza boxes stacked to both sides, you couldn't be more wrong. OK - you might have been right about the nerd part, but there are actually lots of good sportsmen among my colleagues; in particular, many of us enjoy running. Of course, most of us own a few of those internet-of-things gadgets that record your running tracks, heart rate, and other running-related data.

What has always irked me about the software behind those gadgets is that I'd really like to know the velocity I have been running at a certain point of the track. Most applications, however, just show wild noise, some show an over-smoothed curve that doesn't seem to have much to do with reality, but none seem to really get it right. The underlying problem actually has already been outlined by Andreas in his post on identifying implied volatility: While GPS-enabled watches can measure time very accurately, GPS coordinates are much, much less accurate (up to 7 meters off in the worst case). That means there is a lot of noise in the positions recorded alongside the running track, and the velocity is the time derivative of the distances between those track points. And taking the derivative of noise yields a hell of a lot of more noise.

Before we can do savvy maths on the recorded data, we of course need to get the stuff into the computer and most of the time clean it a bit - in this respect, data from a running watch is no different to financial data. In this post, I'd like to concentrate on that data science aspect, and show you how easy it is to read, interpret and clean the data with Mathematica. While I'm using the data from my running watch as an example, the general problems encountered here apply to other data as well.

Most devices can export their data als so-called GPX files, which are simple XML file containing, among other data, the information on the GPS locations recorded alongside the running track. Importing the XML is trivial:

xml = Import[dir <> "activity_579570063.gpx", "XML"];

In the next step, we need to extract the relevant data: we want to have the time at which each track point was recorded, the geographic location (latitude and longitude) and also the elevation (I'll take care of the heart rate at a later time). Furthermore, we want to convert the timestamps (they are ISO date strings of the form "2014-08-31T16:14:45.000Z") to seconds elapsed since the start. We also need to clean the data a bit, since for some unknown reason, some track points are contained multiple times, and we need to eliminate the duplicates. All that can be done with this little piece of Wolfram language code:

TrackpointData[xml_] := Module[{trkpts, lats, longs, elevs, times},
  trkpts = Cases[xml, XMLElement["trkpt", _, _], \[Infinity]];
  lats = ToExpression["lat" /. #[[2]]] & /@ trkpts;
  longs = ToExpression["lon" /. #[[2]]] & /@ trkpts;
  elevs = Cases[trkpts, XMLElement["ele", _, {e_String}]
          :> ToExpression[e], \[Infinity]];
  times = ToSecondsElapsed[ Cases[trkpts, XMLElement["time", _,
          {t_String}] :> DateList[t], \[Infinity]]];
  DeleteDuplicates[Transpose[{times, lats, longs, elevs}]]]

Now, let's plot our track:

ToGeoPath[trkdata_] := GeoPath[trkdata[[All, {2, 3}]]]
GeoGraphics[{Thick, Red, ToGeoPath[trkdata]}, ImageSize -> Medium]


Ah, right. I have been running alongside the Danube. Now, a naive way of directly calculating the velocity is to calculate the time elapsed between two track points, as well as the distance between them, and take that as the velocity. Here's the Mathematica code (luckily, the built-in function GeoDistance takes care of calculating the distance between two points on the earth's surface for us):

ToDistancesMeters[trkdata_] := 
 With[{latlongpts = trkdata[[All, {2, 3}]]}, 
  Table[QuantityMagnitude[
    GeoDistance[latlongpts[[k]], latlongpts[[k + 1]], 
     UnitSystem -> "Metric"]], {k, 1, Length[latlongpts] - 1}]]

Velocities[trkpoints_] := Module[{times, delSs, delTs, vs},
  times = trkpoints[[All, 1]];
  delTs = Differences[times];
  delSs = ToDistancesMeters[trkpoints];
  vs = delSs/delTs;
  Transpose[{times[[2 ;; -1]], vs}]
  ]

Let's plot the velocity:



Good god. Seems I have not been running, but rather "oscillating". If you'd plot the Fourier spectrum, you'd notice a distinct peak at a frequency of about 0.33 Hz - this is the frequency the GPS watch takes measurements (every three seconds). A naive way to get a smoother velocity would be to kill off the high frequencies by a kind of low-Pass filter. That's simple to do in Mathematica:

SmoothVelocities[vels_, omega_, kl_] := Module[{times, vslp},
  times = vels[[All, 1]];
  vslp = LowpassFilter[vels[[All, 2]], omega, kl, BlackmanWindow];
  Transpose[{times, vslp}]
  ]


The orange curve is the smoothed velocity. It is much smoother, but I'm not really satisfied with it: it shows a slowly oscillating velocity (because the high-frequency oscillations have been killed), which does not really match reality. In reality, runners move at almost constant speed for some time, then probably switch to higher speed for a few kilometers, ... and so on.

To do better, we need a kind of model for how the runner moves, and fit the model to the available data. I'll probably show this in another blog post some time, but would like to end this one on a more philosophical note:

More often than not, the problem is not being able to store or otherwise handle huge amounts of data -  the evolution of computer hardware has already taken care of a wide range of such problems. The real problem often is to make sense of the data, to extract the relevant information. In the case of the data from the running watch, the situation seems to be simple enough at first sight: the watch actually records the data we want right away. Still, inevitable noise in the data forces us to make assumptions about the behavior of the runner (e.g., how fast, and how often does he change his velocity), and these assumptions of course will influence the conclusions we make from the data. Financial data, for instance, is incredibly noisy, too. In addition: what actually is the information we want to extract from that data?



What I Am Worried About - Anti-Scientism

About 20 years ago, I read Shadows of the Pomegranate Tree, Tariq Ali.

A family sage telling us the story about the aftermath of the fall of Granada (the demolish of the Moorish culture). In short it's about the reverse of tolerance and intolerance. The Muslim community has been shaken by the burning of their books including the great Muslim writings on science, mathematics, optics, medicine, … It's end of 15th Century, final stages of the Reconquista.  The start of a dark age of Christianity (Inquisition …).

Dark ages - War on Science

Ironically enough, the fall of Granada was centuries after the Islamic golden age (that lasted from approx. 800 to 1200). In Lost Enlightenment, Frederick Starr chronicles the long tradition of scientists, mathematicians, engineers, .. in Central Asia (Iranian- and Turkish speaking regions). BTW, at that time the essentials of applied mathematics were invented.

But after this 4 centuries all went wrong. The region went into a downturn and the Islamic science with it. Maybe the conquest of the Mongols? Not really.

Starr argues that there were anti-science movements much earlier.  Part of the Muslim rulers told the rest: we see more and know it better - only faith, not rationalism and science, can  offer insight into the truths of the world.

(read more in Noah Smith's great post at BloombergView).

It's only one example of the war for Tribal Reality (putting positions of rulers, preachers, culture leaders, .. in concrete), and a "War on Science" in the large. There is more, also in the Western cultures - I am really worried about that.

War on science in the small?

Scientific Method? There is a better way?

About 25 years ago, I conducted a project for a renowned Austrian ski maker. The objective: create models that describe the dependencies of ski test scores on ski properties. Tests that are made on icy or powder snow piste, … for ladies, men, .... We took in particular geometric and related physical properties.

We applied multi-method machine learning, including the decision tree method ID3. From the set up it is a simple supervised learning scheme. We achieved some good results, but our methods at that time did not extract that a parabolic sidecut is essential for turns. Why? The system dis not "see" any ski samples that had significantly curved edges - they had only some slight sidecuts.

3 years later we had methods (like fuzzy ID3) that may have extracted the relation: precise in turns - significant sidecuts. A carving ski invented? How? Fuzzy decision trees are computational and you can calibrate fuzzy sets and membership functions ....

But to introduce fuzzy machine learning methods, you need fuzzy ordering and order relations. And finding a general framework for it you need to apply scientific method: have a hypothesis and test it.

The dark of the data salt mines

There are many contributions suggesting that scientific method is outdated - in the exabyte age data contain every information required?

But even with the best machine learning methods, can we really transform them into knowledge? With my over 25 years experience, no. Theories need models that ride the data waves.

Big data are (too) often dumb data.

The Big Joke of Big Data - I am also worried about.

Driver of modernity

The worrying possibility of all is that the public forgets about the central importance of science in golden ages and how quick the fall into dark ages may happen.

I am not a scientist, but I know that science and rationalism are driving modernity.

A Simple CVA Example

In my blog post two weeks ago I posted some figures with paths and exposures. Today I want to give a short example how Monte Carlo simulation can be used for the calculation of the CVA of an option. To keep things simple we will assume that only the counterparty can default (we will calculate the unilateral CVA).

The formula for unilateral CVA is given by


where LGD is the loss given default, i.e. one minus the recovery rate, DF is the discount factor (we assume a deterministic yield) and PD is the default probability of our counterparty. The term EE(t) stands for the expected exposure at time t. Exposure describes the amount of money that the counterparty owes us if it defaults at time t. As we only want to calculate a single instrument CVA we do not need to take into account netting. Furthermore we assume that o collateral agreements are in place. We can then calculate the positive exposure


where V(t) is the mark to market value of the

instrument a time t. As we model the underlying risk factor of the instrument by a stochastic process, V(t) and therefore also E(t) are random variables.

Equity paths: Black Scholes model with constant volatility.


We can calculate the expected exposure EE(t) by calculating the expectation value over all realisations of our random variable E(t). For an option the value of a trade at time t is simply given by


where K is the strike price. 

E(t) for the call option with strike K=100


EE(t)


Having calculated the exposure we put everything together with a discretised version of formula one

.





How Long Can Faster, Thinner, Smaller, Bigger than Bigger, … Be Innovative?

Yesterday, I experienced the Apple keynote 2014 on my iMac. It is amazing, how perfect its was staged again.

Apple wants to make things for those, who see things differently. Again and again and again …

In search of perfection?

And this made me brooding. Industrial work does what it did yesterday tomorrow, but faster, preciser, thinner, smaller, bigger, ... cheaper. Only at the lab we are striving to find a breakthrough, new ways to solve new problems, and do new things.

The "iPhone 6" is bigger and thinner? Is this important for those who see things differently? To be honest, although expecting it, I was bit disappointed (at the beginning).

A Watch is not a tool

"Apple Watch". I don't wear a watch, because there are watches all around.

I own the WATCH by Femming Bo Hansen. It's minimalist. It's represented at the Museum of Modern Art, NY. And, what a shame, I have put it into a drawer (and nearly forgot it).

A watch is not a tool - it clocks our life.

A computer is not a tool either

Hold on, Apple Watch is a computer on a wrist, and a computer is not a tool either - it is a universal machine to build tools for many usages.

I started my professional work at the stone age of IT. Since then people said subsequently:

"Only a mainframe is a computer" - and then the mini computers entered the market
"Only a mini computer is a computer" - and then the micro computers entered the market
"Only a micro computer is a computer" - and then the workstations entered the market
"Only a workstation is a computer" - and then the PC entered the market
"Only a PC is a computer" - and then the tablet computers entered the market
"Only a tablet computer  is a computer - and then ….?

My first professional work challenge was the migration of an mainframe based system for offline CNC machine programming ("APT") to the first mini computer ("General Automation"). But I quickly realized: this is crazy - and I built a completely new system instead. Exploiting the capabilities of a mini computer. Like the first computer graphics tools … I built a new CNC programming language and all the algorithms to implement it.

And this kind of reinvention's happened again and again and again.

When things became smaller, connectivity became more important. "Sun" said: the network is the computer. And now we have entered the "cloudy" days.

But still front-end devices become smaller and more intelligent. In a not so far future we may have beer glasses, ... that are computers?

However, one of the challenges for a "wrist computer" is the interaction paradigm … that at the other hand - if solved adequately - enable

New uses

It seams Apple wants to take the watch to occupy new market segments, like Health and Fitness. By making things computational - transforming information into knowledge - they can provide better real time advice. If you are running, bicycling, climbing, … you don't want to wear a tablet computer (a bigger than bigger  smartphone), in a race you want to optimize your risk: go to the limit but not across.

Summarizing, I think, this Apple announcement has been underestimated. It may be the begin of making massive information computational - first on a smaller scale.

Maybe, it was not a keynote that shook the tech industry, like those with the announcements of  iMac, iPod, iPhone, iPad, …

What has this all to do with quant finance?

IMO, the quant finance platform and system providers have developed powerful technologies that all are tied together to more or less comprehensive valuation-, portfolio- and risk management solutions or development systems. From professionals for professionals. Following the regulatory framework that reduces the optionality and introduces immense complexity to the valuation and data management  space.

Less effort is applied to explain, say, complex financial concepts to non experts. Using new description and visualization techniques explaining when (and why) an investment will become unhealthy. In an offline (or semi-online) simulator to get more insight into the possible optimization of risk and in the real investment and capital management cycles.

It's not so much about the innovativeness of the smart devices, but their paradigms of interaction …

I confess, this is also challenge for us UnRiskers. Health and Fitness of the financial system … Nothing for the wrist, but for a tablet compute and a bigger than bigger smart phone. We have implemented quite complex mathematical schemes on them … and we have clients and partner who use them for tailored solutions, but ….

p.s. I did not take in account the marketing here: is Apple Watch placed as a form of identity? I would not do it that way. It was producing too less volume and no change. However, the reaction on the announcement was quite surprising ….

Some heavy math in local vol calibratrion

Last week, I plotted the results we obtained for local vol by UnRisk's calibration engine.

To obtain such results, you need some serious mathematics. And this is exactly what we did.

In an abstract setting, we want to solve a nonlinear equation F (x) = y between Hilbert spaces X and Y. (Here: x is the parameter function of local volatility acting on two-dimenstional space (S,t). F is the operator that maps any local volatility function to the two-dimensional surface of call prices (K,T). The right hand side y itself (the call price function for the true local vol) cannot be measured but it is noisy (with noise level delta), and available only for certain points.

Instead of solving F(x) = y_delta, Tikhonov regularization solves

  
In the 1990's Engl, Kunisch, and Neubauer proved that, in this abstract setting, nonlinear Tikhonov regularization converges if
(a) the operator F is continuous,
(b) the operator F is weakly sequentially closed, and
(c) alpha > 0 and delta^2 / alpha -> 0.

Condition (b) might look unfamiliar. The reason for which we have to use the weak topology is that in infinite-dimensional settings, bounded sets in the strong topology need not have convergent subsequences.

For any parameter identification problem, where the solution is theoretically inifinite-dimensional, we have to analyse if the above conditions on the operator are satisfied. For local volaitility, this was carried out by Egger and Engl (Tikhonov Regularization Applied to the Inverse Problem of Option Pricing: Convergence Analysis and Rates, Inverse Problems, 2005).

At UnRisk, we do the math and the numerical implementation. This makes us deliver robust solutions. Can you say this for your system as well?

Pygmalion At Work

The myth of Pygmalion  is about the Greek sculptor who fell in love with a statue he has carved.

The Pygmalion Effect

is about expectations that drive performance. In a workplace it should lead to a kind of co-evolution: leader expectations of team members may alter leader behavior. Like, the more a team member is engaged in learning the more the leader expects. In turn, the team member participates in more learning activities … and leader set learning goals and allow for more learning opportunities.

Placebo?

This effect may help leaders leading, teachers teaching, learners learning … But it's difficult to measure.

However, I am interested in the original myth:

Flip motivation

Instead of doing-what-we-love, we-love-what-we-do. Yes, we want to do things we are good at, but this is not enough. It's all about the results. Create values, solve problems, leverage skills, … do things that matter for and with those who care.

(In the ancient Greek mythology the sculpture came to life - Aphrodite had granted Pygmalion's wish)

What drives us

Years ago, we have unleashed the programming power of UnRisk enabling quants to love what they do, without needing to do all the plumbing. With UnRisk, quants can programmatically manipulate deal types with hybrid contract features, models and data and intelligently aggregate the massive risk data the UnRisk FACTORY calculates.

In 2001, when we looked at the available quant finance technologies, we found products that were too black-box, too rigid to introduce new features, too service dependent to build our ideas atop.

Because we saw a need for a more flexible technology, we developed UnRisk. We wanted to provide solutions that are development systems in one. To make them bank-proof, we provided solutions first and then offered the technology behind.

We've much more ideas than we can build

This is one reason why we love partnering. We believe in quant-powered innovation on a higher level. An we offer all type of programs that make partnerships profitable to our partners - and us.

How good is the description of term structure movements using PCA?

The movements of the term structure of interest rates can be explained quite well using only a few basic factors, like a parallel movement of the curve (shift), a flattening or steepening or of the curve (twist) and a reshaping of the curve (butterfly). The factors, which can be calculated as the eigenvectors of the Gramian matrix of interest rate movements, provide a very powerful framework, since they accelerate the calculation of the historical VaR for interest rate derivatives (which is a very time consuming task, if a full valuation approach is used) significantly.
The following questions occur:

  • How good is the explaination of interest rate movements using only a few factors?
  • How many factors do we have to use to get a good approximation?
  • How stable are the principal components over time?
  • Does the shape of the principal components depend on the currency?
  • How large is the approximation error of a historical VaR calculation using PCA compared to a full valuation approach?
Performing a principal component analysis (PCA) on the weekly changes of historical EUR yield curve data (between 2000 and 2007) given on 16 curve points (1W,3M,6M,9M,1Y,2Y,3Y,4Y, 5Y,7Y,10Y,15Y, 20Y,25Y, 30Y,50Y), the principal components have the following form
 

As expected, the first three factors describe a shift, twist and butterfly movement of the curve. 
In my next blog(s), I will try to find the answers to the questions above....

Do I Need A Cloud To Let My Business Shine?

In the current technology climate computer infrastructure is cloudy and lightning-fast. Ideal to mine big data and transform them into big insight ….?

Recently, I found this article in RBS Insight hub: How the cloud will reshape transaction banking. I have no doubt, this makes perfect sense for many transaction-oriented systems.

Then I read

What is cloud computing?

Cloud computing lets people use the internet to tap into hardware, software and a range of
related services on demand from powerful computers usually based in remote locations. 
 
Successfully enabling the widespread adoption of cloud computing could add EUR 250 billion to European GDP by 2020, thanks to greater innovation and productivity, according to research conducted by International Data Corporation on behalf of the EC. Nearly four million new jobs could be created as a result.
This would amount to more than 3.8 million new jobs, although this number does not include jobs lost to cloud-related business reorganisations and productivity gains.
How can one make such a forecast?

Is the cloud what risk managers should be thankful for?

Over the years regulatory and business requirements have driven financial institutions to take leading positions in technology, implementing new sophisticated features and automated analytics solutions that are widely accessible.

UnRisk has all technologies to run at a cloud - for development we offer webUnRisk, and the UnRisk FACTORY has a web front-end. Both can be seamlessly combined. But, which clouds run our advanced technologies to make our business shining?

But also due to the data and security issues, I rather believe advanced risk management systems will run on "on-site of financial institutions clouds", providing access via the intranet and selected clients, business partners, … There we take care that our technologies run.

However, Quant jobs will not end in a cloud. Nor will ours.

Local Volatility by Regularization

Two weaks ago, I applied some data smoothing techniques to improve the results of Dupire's formula when the data are noisy. The quality of the results improved slightly, but not completely satisfying.

What would we like to obtain?
On the one hand, the model prices for the forward local volatility problem (e.g. by finite elements) should fit the (noisy) market prices reasonably, on the other hand, the local volatility surface should not exhibit severe oscilations. It should be as smooth as possible and as unsmooth as necessary to fit the data.

Identifying local volatility is, at least in infinite dimensional setting (you would know the call price for any (K, T)-combination (K is strike, T is expiry)) an ill-posed problem. This means that arbitrarily small noise (remark; if of sufficient high frequency) can lead to arbitrarily large errors in the solution.  And it is a nonliner problem, which makes it more complicated than, e.g. curvefitting in a Hull-White-setting.

The technique to overcome these stability prblems (or: one of the techniques) is Tikhonov regularisation. The following plot shows the result we obtain by regularization on the same data as we used in the presmoothing example.
 
 
Next week, I will have a closer look on the theory behind this improvement.