## Wednesday, December 18, 2013

### Statistical arbitrage with Python

UPDATE: The current Github version of the backtest is a bit broken: there was a stupid bug that caused the algo to "see" 1 min into the future. Also, the overnight effects/ jumps in the morning kinda ruin the intraday trades, so I'm currently rewriting the code for 1 sec bar bid/ask data to be used intraday only... ETA unknown, since I'm not sure how much I can spend time on this, but stay tuned for more!

Finally managed to complete an early version of my PyArb statistical arbitrage project... Can I call myself a quant now? ;) I published it in GitHub as a Python module here, although the best way to view it right away would be to check out the IPython Notebook here at nbviewer.ipython.org. It is a model dependent equity statistical arbitrage backtest module for Python. Roughly speaking, the input is a universe of N stock prices over a selected time period, and the output is a mean reverting portfolio which can be used for trading. The idea is to model "interacting" (correlated, anticorrelated or cointegrated) stock prices as a system of stochastic differential equations, roughly as

$$dX_t^i = A^i_j X_t^j dt + X_t^i dW_t^i,$$

where $X_t$ are the prices and $dW_t$ are white noises.

The stochastic part doesn't yet play any important role, but that will soon change as I'm planning to implement a Box-Tiao style predictability measure for determining the portfolios (see e.g. the paper by de Prado)... not sure if it will improve the performance though.

This is just a backtest for a strategy, so there's no saying it will actually work in a live situation (but I'm planning to try paper trading next). Specifically, there's no slippage and impact modelling, short sell contract and borrow costs etc. I just assumed a flat rate \$.005 per share cost from Interactive Brokers' website as a sort of ballpark figure. It gives a roughly 12% annualized returns with a Sharpe ratio of about 5 and a maximum drawdown of 0.6%. Maybe that sounds a bit too good to be true? Well maybe I made a mistake, go ahead and check the code! :) (I need to check it again myself anyway or give it a go in e.g. Quantopian). Here's a plot of the cumulative returns for a period of about 300 days. The "mode=0" is the best portfolio and corresponds to the lowest eigenvalue of the evolution matrix$A$in the equation above. Hey, I have a great idea!! How about you give me a zillion$€£ to manage and I use this strategy for trading?!?! ;)

## Saturday, September 14, 2013

### Funny statistics in stock market data

Funny statistics in stock market data

# Market data structure functions

I recently got some minute level stock market data from The Bonnot Gang for some data analytic (and stat arb design) purposes, when I noticed some funny behavior in the data structure function. Now the concept of a structure function may not be very widely known with quants/ data analysts/ economists, so here's a definition:

Suppose there's a time series Xt$X_t$. The structure function of Xt$X_t$ is defined as

Sn(τ)E(|Xt+τXt|n)

where for a given sample of data you just replace the ensemble expectation E()$\mathbb E()$ by the sample mean, 1Nt=0N()$\frac{1}{N} \sum\limits_{t=0}^N()$.

These types of structure functions have been studied for some time now in finance in the context of similarities between financial markets and hydrodynamic turbulence. I think it all started in 1996 with the paper Turbulent cascades in foreign exchange markets by Ghashghaie et al. They computed the structure functions for some FX market data, and found a scaling relation Sn(τ)ξn$S_n(\tau) \propto \xi_n$, where ξn$\xi_n$ is a concave function of n$n$, implying multiscaling in FX markets, similarly to hydrodynamic turbulence (BTW their conclusions about the result were a bit out there, but I guess the data analysis is still good).

So I did some of my own data analysis with the Bonnot Gang data (I hope it's not bad data!). Here's a few plots of the structure functions, first for n=1$n=1$:

Then n=3$n=3$:

This is close to linear, i.e. ξ31$\xi_3 \approx 1$, as in turbulence. Then n=10$n=10$:

Clearly you can't fit a power law in all of this, but there seems to be clear power law regimes divided by about 6, 18, 60 and 180 minutes! I don't know the reason for this, but if I had to guess, I'd say it's because of traders/ algorithms operating w.r.t different data timeframes... or maybe it's because of the finite tick size...

Anyway, I don't have time to get to the bottom of this, but maybe someone else will... so if you see this stuff on a paper someday, you saw it first here!! ;)

Written with StackEdit. Try it out, it's awesome!! You can do MathJax and sync everything in Google Drive or Dropbox and publish directli in Blogger, Wordpress, Tumblr etc.!

## Tuesday, April 30, 2013

### Goodbye to Academia

Damn I'm tired of applying for puny research grants (and not getting one most of the time)... Time to move on and implement plan B that I've been preparing for some time: I've decided to squeeze myself into quantitative finance! It's actually really interesting. I was greatly inspider by Emanuel Derman's "My life as a Quant", where he describes pretty similar circumstances to my own with his postdoc aspirations. I recommend the book to anyone considering leaving Academia.

From a mathematical point of view, I was a bit awe-struck by Pierre Henry-Labordere's "Analysis, Geometry and Modeling in Finance". Apparently there's a close connection between the geometry of black holes (well, at least the hyperbolic types) and stochastic volatility models! It would be extremely cool to be able to actually research and design models like that which would actually work and be useful! Anyway, I doubt real quant life is that fancy, but I'll be happy if the job involves PhD level math of some kind.

I'd love to hear other people's stories about switching from academia to industry or finance. Anyone here with similar experiences?

## Friday, November 2, 2012

### Workshop: LIE THEORY AND ITS APPLICATIONS IN PHYSICS

I received an invitation to the conference "LIE THEORY AND ITS APPLICATIONS IN PHYSICS", which will be held in Varna, Bulgaria next june. That would be my first hep-th/gravity related conference... exciting! Some interesting names in the advisory board and previous years' visitors. Now if only I could get some funding, I could actually go (a hint for possible reviewers reading this).

## Sunday, September 30, 2012

### An idea for gauge/gravity dualities

Change of plans. Converting TeX to HTML and the post editing involved is a drag, so I'm not going to finish the series about asymptotic geometry etc. Instead I wrote a new paper on the subject! The preprint is posted on arXiv here, but I haven't submitted it yet(I will probably revise a bit). Here's a short summary.

In the paper I try to generalize the successful results of gauge gravity duality for $AdS_3$ gravity to higher dimensions (or at least motivate the attempt). This was the big idea by Brown and Henneaux (link to paper at inSPIRE.net) which was later refined in here (and in other people's works, but I don't want to cite a lot of sources). The idea is that a three dimensional gravity theory that approaches an anti-de Sitter space at a spherical boundary at infinity is equivalent (or dual) to a two dimensional conformal field theory on the boundary, which turns out to be a 2D Liouville theory. Brown and Henneaux discovered this by studying the asymptotic symmetries of $AdS_3$ gravity, which they discovered to actually tend to conformal transformations at the boundary. The asymptotic symmetries are here diffeomorphisms which preserve the asymptotically $AdS_3$ conditions. Moreover, they discovered that the algebra of canonical generators of these asymptotic symmetries is the Virasoro algebra with a classical, nonvanishing central charge!

What's perhaps even more interesting is that this kind of approach does not work in higher dimensions. The reason is that the boundary of $AdS_{d+1}$ is a $d$ dimensional flat space (Minkowskian or Euclidean, depending on if you're talking about real $AdS$ spaces or the Euclidean versions, i.e. hyperbolic spaces) and because the conformal transformations in dimensions $d>2$ forms a finite dimensional group. The infinite dimensionality of the asymptotic symmetries will be the key!

As I explain in the paper, the key to understanding how to generalize the extremely successful 3D case to higher dimensions is the observation that (loosely speaking) the 3D $AdS$ space is in fact the Lie group $SL(2)$. Indeed, my hypothesis was that instead of studying higher dimensional $AdS$ spaces, one should study the geometry of the Lie groups $SL(N)$ (and their homogeneous spaces). In the first article of the subject, (published in JMP),I discovered that the asymptotic symmetries on the boundary of the five dimensional homogeneous space $SL(3)/SO(3)$ form an infinite dimensional Lie algebra, which implies the generalization of the duality (the paper was a bit of a "tour de force" and not very elegant...). This is completely different to the higher dimensional $AdS$ spaces, where the asymptotic symmetries form a finite dimensional Lie algebra. It will then be possible to extend the $SL(3)/SO(3)$ asymptotic symmetries to near boundary symmetries to obtain a similar dual theory as the Liouville theory in the 3D AdS gravity case.

Anyway, I hope the stuff makes sense... I wrote this piece quite quickly. The intro in the paper is probably better!

## Thursday, April 26, 2012

### Asymptotic geometry of symmetric spaces II: $\mathbb H^2$ from $sl(2;\mathbb R)$

This is a sequel to the first part in the "Asymptotic geometry" series, found below. The goal here is to obtain the metric of the space of unit area ellipses starting from the Lie algebra $sl(2; \mathbb R)$. Instead of thinking about a space on which a Lie groups acts, we can start from "the opposite end", from Lie algebras. I will work explicitly with the defining and adjoint representations, although much could be done without any reference to a representation. I'll start with some generalities.

## Symmetric spaces

This subsection will be a bit technical, but will hopefully become clearer in the next subsection. Consider a (semi-simple) Lie algebra $\mathfrak g$ associated to a Lie group $G$. The Lie bracket $\left[X,Y\right]$ can be used to define the adjoint representation $\ad X : Y \to \left[X,Y\right]$, which are formed of square matrices of size $dim(\mathfrak g)\times dim(\mathfrak g)$. The symmetric bilinear form $$\kappa \left( X, Y \right) \doteq \tr \left( \ad X \ad Y \right)$$ is known as the Killing form, which can be used as an inner product on the Lie algebra by setting $\langle X, Y\rangle \doteq \kappa \left( X, Y \right)$. Now try to find involutive automorphisms $\sigma$ of the Lie algebra, i.e. $\sigma^2 =1$. Then the Lie algebra decomposes according to the eigenvalues $\pm 1$ as $\mathfrak g = \mathfrak p + \mathfrak k$ with $\sigma (\mathfrak p) = - \mathfrak p$ and $\sigma (\mathfrak k) = \mathfrak k$. It's easy to show that the subsets are orthogonal, i.e. $\langle \mathfrak p, \mathfrak k\rangle=0$, and that they satisfy the commutation rules \left\{ \begin{aligned} \left[\mathfrak p,\mathfrak p \right] &\subseteq \mathfrak k \\ \left[\mathfrak p,\mathfrak k \right] &\subseteq \mathfrak p\\ \left[\mathfrak k,\mathfrak k \right] &\subseteq \mathfrak k. \end{aligned} \right. This procedure is known as the Cartan decomposition. Note that $\mathfrak k$ is a subalgebra, but $\mathfrak p$ is not. If $K$ is the Lie group corresponding to $\mathfrak k$, then the homogeneous space $G/K$ is a symmetric space. We can denote elements in the symmetric space as a left coset $p K$, where $p$ is the exponential map of an element in the subset $\mathfrak p$. Then left actions on the symmetric space are well defined, $L_g :p K \to g p K = p' k K = p' K$ ($L_g$ is just the left multiplication) for some $p'$ and $k$. There's an elegant formula for the Maurer-Cartan form (the expression for the differential is originally due to Helgason, I think). Suppose that the elements in the Lie algebra are sorted as $X_i, X_j, \ldots \in \mathfrak g$, $Y_\mu, Y_\nu, \ldots \in \mathfrak p$ and $Z_a, Z_b, \ldots \in \mathfrak k$. Then an element in the symmetric space can be written as $p = \mbox{EXP}\left( Y (\omega)\right) \doteq \mbox{EXP}\left( \omega_\mu Y_\mu\right)$, and the Maurer-Cartan form can be written in the form of the nontrivial formula (in a slightly less obscure notation than Helgason's, I hope; note that everything can of course also be done in the right invariant formalism) $$p^{-1} dp = \left( \frac{1-e^{-\ad Y (\omega)}}{\ad Y (\omega)} \right) \left( Y(d\omega) \right).$$ In components, $$p^{-1} \partial_\mu p = \left( \frac{1-e^{-\ad Y (\omega)}}{\ad Y (\omega)} \right) \left( Y_\mu \right) = X_k \left( \frac{1-e^{-\ad Y (\omega)}}{\ad Y (\omega)} \right)_{k \mu} .$$ It's also common to write $p^{-1} dp = X_i \otimes \Omega_i$, and call the one forms $$\Omega_i = \left( \frac{1-e^{-\ad Y (\omega)}}{\ad Y (\omega)} \right)_{k \mu} d\omega^\mu \doteq \mathcal A_{k \mu} d\omega^\mu \label{matrix.gauge}$$ the (left invariant) Maurer-Cartan forms. The left invariant metric is then $$ds^2 \doteq \langle p^{-1} dp, p^{-1} dp \rangle = \Omega_i \kappa_{ij} \Omega_j, = d\omega^\mu \left( \mathcal A^T \kappa \mathcal A \right)_{\mu\nu} d\omega^\nu \label{metric.explicit}$$ where $\kappa_{i j} = \langle X_i, X_j\rangle$. The above formula may however not be very useful in practice, since it involves exponentiations of the adjoint representation. The point here is that the metric can be defined and calculated by purely algebraic operations.

## $\mathbb H^2 \simeq P_2$ from $sl(2;\mathbb R)$

The Lie algebra $\mathfrak g \doteq sl(2;\mathbb R)$ can be defined as the set of traceless two by two matrices with elements $$X(\omega) \doteq \left( \begin{array}{cc} -\omega_2 & \omega_1 + \omega_3 \\ \omega_1-\omega_3 & \omega_2 \end{array} \right) \doteq \sum\limits_{i=1}^{3} \omega_i X_i. \label{definingrep}$$ In this particular basis the matrices $X_i$ in fact satisfy the Lie algebra $so(1,2;\mathbb R)$, \left\{ \begin{aligned} \left[X_1,X_2 \right]&= 2 X_3 \\ \left[X_2,X_3 \right]&= -2 X_1\\ \left[X_3,X_1 \right]&= -2 X_2, \end{aligned}\label{comms.so21} \right. which is just a realization of the well known isomorphism $sl(2;\mathbb R) \simeq so(1,2;\mathbb R)$ (note how flipping the sign in e.g. the first commutator brings the algebra to the familiar $so(3;\mathbb R)$ Lie algebra). Now try to find all involutive automorphisms $\sigma$ of the Lie algebra. It can be shown that in this case there is only one such mapping, $$\sigma : X \to -X^T.$$ It is then straightforward to see that $\mathfrak p = \left\{ X_1, X_2 \right\}$ and $\mathfrak k = \left\{ X_3 \right\}$. Note that $K=\exp (\mathfrak k) = SO(2;\mathbb R)$. Using radial coordinates $\left(\omega_1, \omega_2 \right) = \left( r \sin \phi, r \cos \phi \right)$, we have $$\small{p \doteq \exp \left(\omega_1 X_1 + \omega_2 X_2 \right) = \left( \begin{array}{cc} \cosh r -\cos \phi \sinh r & \sin \phi \sinh r \\ \sin \phi \sinh r & \cosh r +\cos \phi \sinh r \end{array} \right)},$$ which is identical to the matrix in eq. (10) in part I. The matrix $\mathcal A$ in eq. \eqref{matrix.gauge} can be computed explicitly as follows. The $\ad$ basis can be written as in the defining representation in eq. \eqref{definingrep}, $$\ad X(\omega) \doteq 2\left( \begin{array}{ccc} 0 & \omega _3 & -\omega _2 \\ -\omega _3 & 0 & \omega _1 \\ -\omega _2 & \omega _1 & 0 \end{array} \right) = \sum\limits_{i=1}^{3} \omega_i \ad X_i.$$ It is straightforward to verify that e.g. $\ad X_1 (X_2) = 2 X_3$, where now $X_2 = \left(0,1,0\right)^T$, $X_3 = \left(0,0,1\right)^T$ and the $\ad$ representation acts in the usual way. The matrix $\mathcal A$ can be expanded in power series (in fact the power series is the definition), $$\mathcal A = \left( \frac{1-e^{-\ad Y (\omega)}}{\ad Y (\omega)} \right) = \sum\limits_{n=0}^{\infty} \frac{1}{(n+1)!}\left(-\ad Y(\omega) \right)^n ,$$ remembering that $Y(\omega) \in \mathfrak p$. By using the Cayley-Hamilton theorem, the right hand sum can be written in finitely many powers of the matrix as $$c_0 (\omega) +c_1 (\omega) \ad Y(\omega) + c_2 (\omega) \ad Y(\omega)^2.$$ The task of finding the coefficients $c_n (\omega)$ is straightforward, although slightly tedious (NOTE TO SELF: I once wrote a Mathematica function, similar to the MatrixExp function, that does the trick automatically... must remember to post it somewhere and insert a link here). Anyway, the result is $$\scriptsize{ \mathcal A = \left( \begin{array}{ccc} \frac{\sinh (2 r) \cos ^2(\phi )}{2 r}+\sin ^2(\phi ) & \frac{\left(r-\frac{1}{2} \sinh (2 r)\right) \sin (\phi ) \cos (\phi )}{r} & \frac{\sinh ^2(r) \cos (\phi )}{r} \\ \frac{\left(r-\frac{1}{2} \sinh (2 r)\right) \sin (\phi ) \cos (\phi )}{r} & \frac{\sinh (2 r) \sin ^2(\phi )}{2 r}+\cos ^2(\phi ) & -\frac{\sinh ^2(r) \sin (\phi )}{r} \\ \frac{\sinh ^2(r) \cos (\phi )}{r} & -\frac{\sinh ^2(r) \sin (\phi )}{r} & \frac{\sinh (2 r)}{2 r} \end{array} \right)}.$$ Using the definition in eq. \eqref{metric.explicit} will then yield the same metric as in part I (up to a factor of 2): $$ds^2 = dr^2 + \sinh^2 (r) d\phi^2.\label{metricP2}$$

## Monday, April 16, 2012

### Asymptotic geometry of symmetric spaces I: The space of unit area ellipses is the hyperbolic space $\mathbb H^2$

This blog article was supposed to be a transcript of sorts of a seminar talk I gave about my work at Aalto university math department's differential geometry seminar, but I noticed that I was actually rewriting the whole thing from start to finish. This version is primarily aimed at physicists or people who think mathematics in the traditional proof/theorem sense is not a very good method for an introductory exposition (such as myself). I decided to post the whole thing in four separate parts, since it's not very easy to manage big HTML+LaTeX posts... Hopefully I will get some feedback which I may use in the later parts!

The purpose of this first part (out of four) is to give a very easy going description of the geometry of the space of unit area ellipses (with center of mass at the origin), also known as $P_2 = SL(2;\mathbb R)/SO(2; \mathbb R)$, which is isomorphic to the hyperbolic space $\mathbb H^2$. Much of the material may seem to have been pulled out of a magicians hat, but will hopefully become clearer in part II, where I will present the problem a bit more traditionally and carefully by starting from the Lie algebra $sl(2; \mathbb R)$. In part III I will talk about the asymptotic geometry of $P_2$, and the conformal structure on its boundary á la Fefferman and Graham (see e.g. Graham & Zworski). I will also try to point how and why these "asymptotic conformal symmetries" play an important role in the so-called gauge/gravity dualities. In part IV I will discuss my own work on the asymptotic geometry, conformal structures and the infinite dimensional Lie algebra of asymptotic symmetries on the boundary of $P_3$ (see here for the arXiv version; I must note that I was a bit hasty with the publication and I will try to elaborate the results a bit further in the blog version), which can be understood as a space of unit volume ellipsoids in $\mathbb R^3$. This is a five dimensional noncompact symmetric space of constant negative Ricci scalar curvature, which however is not isomorphic to $\mathbb H^5$.

Figure 1: Some ellipses. Black is the circle, Red is $\mathcal E (1/2,5)$ and green is $\mathcal E (1,3/2)$ (see below for the definition of $\mathcal E$).

### Symmetries of the space of unit area ellipses (UAE)

What exactly is a symmetry? We could describe a ball being symmetric under rotations about it's center. Here's an equation for a (unit) ball in $\mathbb R^2$, i.e. a circle: $$x^2 + y^2 = 1.\label{circleeq}$$ The equation \eqref{circleeq} is invariant under a rotation by an angle $\phi$, $$\left( \begin{array}{c} x' \\ y' \end{array} \right) = \left( \begin{array}{c} x \cos\phi + y \sin\phi \\ -x \sin\phi +y \cos\phi\end{array} \right) \label{rotation}.$$ I will define the matrix that does the rotation as (the symbol $\doteq$ is here used to define a notation) $$k(\phi) \doteq \left( \begin{array}{cc} \cos \phi & \sin\phi \\ -\sin\phi & \cos\phi \end{array} \right) \in SO(2;\mathbb R).$$ (I apologize for not making a distinction between a representation and a Lie group element... hopefully that will not cause confusion) I'll just denote the circle as $$S^1 =\left\{ (x,y) \in \mathbb{R}^2 \left| x^2+y^2=1 \right. \right\}. \label{circle}$$ The invariance under rotations \eqref{rotation} can then be expressed as $$k(\phi)\cdot S^1 = \left\{ (x,y)\in \mathbb{R}^2 \left| {x'}^2+{y'}^2=1 \right. \right\} = S^1 .$$ We could say that the rotation maps the circle into another circle, which is another solution to the equation, albeit identical. Symmetries may in fact be defined as transformations that map the solution space to itself. Here the solution space is zero dimensional, since there is only one solution, which admittedly makes the example rather boring... We could instead consider the space of all UAEs (never mind about what the equation would be, we just need the space). An UAE can be obtained by acting on the unit area circle by a linear transformation which preserves the area, like this: $$\left( \begin{array}{c} x' \\ y' \end{array} \right) \doteq \left( \begin{array}{cc} a & b \\ c & d \end{array} \right) \left( \begin{array}{c} x \\ y \end{array} \right) \ \ , \ \ a d-b c =1 .\label{speciallinear}$$ We can call the matrix $g$, after which the right hand side area preserving condition can be expressed simply as $\det g = 1$. Invariance of the area is a simple consequence of invariance of the volume form, $dx' \wedge dy' = dx \wedge dy$ (the volume form is just the integration measure in e.g. $\int\! f(x,y)dx dy$). Two by two matrices with unit determinant form the Lie group of type $SL(2; \mathbb R)$. Let's consider a particular matrix in $SL(2; \mathbb R)$ of the following type: $$h(r) \doteq \left( \begin{array}{cc} e^{-r} & 0 \\ 0 & e^{r} \end{array} \right) .$$ The exponential notation is simply a matter of convenience and will be useful below. Its effect is to shrink the $x$ coordinate by a factor $e^{-r}$ and to stretch the y coordinate by $e^{r}$ (for positive $r$), therefore it deforms the circle into a unit area ellipse, explicitly $$h(r)\cdot S^1 = \left\{ (x,y) \in \mathbb{R}^2 \left| e^{-2r} x^2+ e^{2r} y^2=1 \right. \right\} .$$ On the other hand, we also have the rotation matrix $k(\phi)$. Clearly we can get any ellipse by acting on $S^1$ with $k(\phi) h(r)$. It is in fact possible and convenient to express any matrix $g$ with $\det g = 1$ in a combination of these kinds of two matrices by using a polar decomposition, $$g = k(\phi/2)h(r)k(-\phi/2) k(\phi') \doteq p(r,\phi) k(\phi'),$$ with $$p(r,\phi) = \left( \begin{array}{cc} \cosh r -\cos \phi \sinh r & \sin \phi \sinh r \\ \sin \phi \sinh r & \cosh r +\cos \phi \sinh r \end{array} \right).\label{symmspace}$$ Now we can define any ellipse as $$\mathcal E (r,\phi) \doteq p(r,\phi) \cdot S^1,$$ since $k(\phi') \cdot S^1 = S^1$. In fact, we wouldn't need the circle at all: for $r>0$, there's a one to one correspondence between all ellipses and the elements $p(r,\phi)$. The origin in the space of ellipses is the circle $S^1$, which corresponds to $p(0,\phi)$. It is indeed perhaps more intuitive to consider the origin as a point rather than a circle... Now $g$ acts on the space of ellipses by multiplication from the left: $\mathcal E \to g \mathcal E = g p \cdot S^1$. But note that we can always rearrange $g p(r,\phi) = p(r',\phi') k(\phi'')$, and since $k \cdot S^1 = S^1$, the transformation preserves the form $p\cdot S^1$ of the space of ellipses. This is of course just a realization of a homogeneous space: $SO(2)$ is the isotropy group of the circle, and the space of ellipses can be identified with $SL(2)/SO(2)$ (I will always assume the field to be $\mathbb R$ and will therefore often drop it).

### Geometry

What is the distance between two ellipses $p(r,\phi)$ and $p(r',\phi')$, or rather, the metric tensor in the space of ellipses? Clearly the metric would need to be invariant under the Lie group $SL(2)$, so we might try to apply the transformations on an arbitrary two dimensional metric and demand invariance. This would lead to a system of PDEs to be solved, which is never fun. It's in fact possible to find the (unique) metric in a more elegant way. For this we need the left invariant Maurer-Cartan form $p^{-1} dp$, i.e. take the differential of $p$ and multiply by the inverse of $p$ from the left. Explicitly, $$p^{-1} dp = \left( \begin{array}{cc} -\cos \phi & \sin \phi \\ \sin \phi & \cos \phi \end{array} \right) dr \\ - \sinh r \left( \begin{array}{cc} \sin \phi \cosh r& \cos \phi \cosh r - \sinh r \\ \cos \phi \cosh r + \sinh r & -\sin \phi \cosh r \end{array} \right) d\phi$$ Then, as if by a miracle, we can define the metric as $$ds^2 \doteq \frac{1}{2} \tr \left( p^{-1} dp \cdot p^{-1} dp \right) = dr^2 + \sinh^2 (r) d\phi^2.\label{metricP2}$$ Compare this to the Euclidean metric on $\mathbb R^2$ in radial coordinates: $$ds^2 = dr^2 + r^2 d\phi^2.$$ The metrics are asymptotically equivalent as $r$ approaches zero, but the metric of eq. \eqref{metricP2} grows exponentially for large $r$. Then the distance between ellipses with same angle is $\mbox{dist}\! \left( p(r_1,\phi), p(r_2,\phi)\right) = |r_1-r_2|$ and the distance between ellipses with same "radius" is $\mbox{dist} \left( p(r,\phi_1), p(r,\phi_2)\right) = |\phi_1-\phi_2| \sinh r$. We can express the metric in possibly slightly more familiar coordinates by \left\{ \begin{aligned} \xi &= \frac{\sin \phi \sinh r}{\cosh r + \cos \phi \sinh r}\\ \eta &=\frac{1}{\cosh r + \cos \phi \sinh r} \end{aligned}\label{coords.poincare} \right. which results in the metric $$ds^2 = \frac{1}{\eta^2} \left(d\xi^2 + d \eta^2 \right),$$ which is the familiar Poincare upper half place metric of the hyperbolic space $\mathbb H^2$.

That's all for now. In the next part I'll discuss symmetric spaces via a Cartan decomposition of the Lie algebra $sl(2; \mathbb R)$.