The search for relationships on the example of the Oil-Ruble

    One of the basic tasks of data analysis is to find the relationship between the two quantities. Here I want to show an example of finding a connection between the price of oil and the ruble.

    image

    First, you need to determine whether the task makes sense at all. Why should oil and ruble be / can be interconnected? In short, the model is this: exporters sell oil for dollars, and then sell dollars to get rubles for domestic payments. The mechanism is extremely simplified, it is necessary to take into account the volumes of production and sales that not only oil is exported, exporters do not always sell dollars, the Central Bank is affected by the intervention rate, etc. Nevertheless, we assume that the model is more or less working, that is, that there are fundamental reasons for the relationship between oil prices and the ruble exchange rate.

    What do we need. Data - take the daily measured oil price (Brent grade) in dollars and the ruble to dollar exchange rate, data can be freely obtained on the site finam.ru , the sampling period is from the beginning of last year. Toolkit - we will need to build a lot of graphs to visually evaluate how the model generally works and a fairly simple apparatus for constructing regressions. Gnuplot has all these features, looking ahead - the script for drawing graphs and counting regressions takes no more than 40 lines of code. A link to all working scripts will be given below.

    Let's look at the joint dynamics over time of the price of oil and the ruble:

    image

    Oil down, ruble up. There is some kind of relationship, but the impression is that something is missing ... Aha! We compare the values ​​“Oil for dollars” and “dollar for rubles”, that is, the dimensions do not coincide with the commonplace dimension. We take the ruble exchange rate in the form of “Ruble / Dollar” and redraw the picture:

    image

    Here the correlation is already obvious. We are on the right track, continue.

    We will construct many points (Oil / Usd, Ruble / Usd) and draw two regression lines, Y1 - linear, Y2 - quadratic, the determination coefficient is high for both lines, that is, the relationship between the price of oil and the ruble is quite close.

    image

    The regression lines almost coincide. We choose a linear one, firstly it is simpler and has fewer parameters, which is very important, including from the point of view of the Occam principle, and secondly, it has a slightly larger coefficient R2, that is, formally it is better, a little, but better.

    We will rebuild the chart of the ruble exchange rate versus oil price in the usual format, that is, as we see these figures in the news, on websites, on signs near banks. At the same time, for clarity, let us leave all our constructions on the chart, only make their color paler.

    image
    Summary. The ruble exchange rate is quite closely related to the price of oil, the dependence is linear (for the Rub / Usd rate), the coefficient of determination is ~ 0.97.

    PS. All data, scripts and files for building pictures in Gnuplot can be downloaded here:drive.google.com/file/d/0BwHQSqFOG-7ldjk0SHZ4M1RxRGc/view?usp=sharing

    PPS
    Update. A typo has been fixed in the formula (this did not affect the graphs themselves). Thanks to Alexei Kuzmin (@ alexeykuzmin0) for the comment.

    Also popular now: