Python charts tell a market story


“I revel in the beauty of numbers”. I wrote that line a few years ago, at the start of a novel I had begun to write. Whilst 20,000 words somehow made it from my mind to drift on to paper, the novel remains unfinished. Will I ever finish it, I have no idea? For the time being, it lays undisturbed on my computer’s hard drive. Unfinished it may be but the first line of my novel, is something I really do believe. There is beauty in numbers. The ability to describe the precisely, with numbers, rather than purely with words, which are at best approximations. However, even someone enamoured by numbers, like me, realises that the human brain can only digest so many numbers at one time. Faced with a full tables plastered with numbers in a table, the mind can be overwhelmed by information. We might gravitate towards the wrong figures and the wrong conclusions, simply because we cannot interpret such data as a whole. This is especially true of markets, where the sheer amount of data which are bombarded towards market participants is huge. Being able to summarise this effectively, is the greatest skills of a good trader.


Visualising data, rather than presenting a huge stream of numbers is an effective way to cut through the noise and see patterns in the data. Indeed, in any data science problem, whether it is related to markets or not, presenting the data in an effective manner is key to communicating the results. If you can’t communicate the results of the analysis to anyone (including yourself), then it is questionable what the point of the analysis was. However, when visualising data, we are faced with many choices, in precisely how we visualise the data. What type of chart could we use? Is a line chart appropriate, or would a bar chart be better? Are there more unusual visualisations which would make sense, for example a surface or bubble plot (or would they merely complicate matters)? Once we have chosen how to visualise the data, we also need to make sure that we have formatted the chart properly. Poor formatting, small text, clashing colours etc, all detract from the message contained inside the chart.


There are many tools to help us to visualise data in Python, such as Matplotlib, Bokeh and Plotly. Unfortunately, every one of them has a different API and in some instances, we might need to spend time fiddling with the API to get the final chart to look presentable (less so admittedly with Plotly). Hence, if you want to try a different Python visualisation tool, bad luck, you have learn how to code all the formating all over again! When I wrote PyThalesians, an open source Python financial library, I quickly found that many of the solutions for plotting in Python were great, but each had their own steep learning curve.


I didn’t want to spend ages fiddling with graphics packages APIs, every time I did my plotting. So instead, I spent quite a bit of time developing my own easy to use wrapper, so that you could do simple visualisations in many underlying different chart libraries, with just a few lines of code. So rather than reinventing the wheel, I simply, made it easy to place different tyres on that wheel! Hence, I can concentrate on doing the analysis in solving a financial problem, rather than ages trying to get charts right. Hence, it really is as easily as changing a single word ‘pythalesians’ to ‘plotly’ to change the plotting engine I use, as illustrated below.


pf.plot_generic_graph(df, type = ‘line’, adapter = ‘pythalesians’, gp = gp)
pf.plot_generic_graph(df, type = ‘line’, adapter = ‘plotly’, gp = gp)


I’m also thinking of spinning out the graphics capabilities of PyThalesians into a separate project if there’s sufficient interest. To give you an example of some of the plotting you can do, with only a few lines of codes, I’ve plotted a recent volatility surface for EUR/USD using my PyThalesians wrapper (using Plotly as a backend). An Python example I wrote on GitHub shows you how to plot such surface in some more detail. Underneath this plot, are many data points. Thankfully, the surface effectively captures all this data in one easy snapshot. The cliche says that a picture a thousand words. Don’t end up coding a thousand words to do every one of your plots in Python, and check out my PyThalesians Graphics wrapper on GitHub! If you’d like to know more about PyThalesians drop me a message.


The clich