chapter seven

7 Handling time series data and missing values

 

This chapter covers

  • Fetching data using HTTP queries
  • Parsing JSON data
  • Working with dates
  • Handling missing values
  • Plotting data with missing values
  • Interpolating missing values

This is the last chapter in the introduction to the Julia language part of this book. A motivating use case for the topics that we will cover is working with financial asset prices. Imagine you wanted to analyze how the price of some stock or the exchange rate between two currencies evolves over time. To be able to handle such questions in Julia, you need to know how you can work with time series data. One of the frequent features of real-life temporal data is that for some time stamps there is missing data in it. Therefore, the second major topic of this chapter is handling missing values in Julia.

The problem we tackle in this chapter is analyzing the PLN/USD exchange rate that is published by the National Bank of Poland (NBP). The data is made available via a Web API, which is described here https://api.nbp.pl/en.html.

We will perform our task in the following steps:

  1. understanding the format of the data that the Web API exposes;
  2. fetching the data using HTTP GET requests for a specified range of dates;
  3. handling errors when the requested data is not available;
  4. extracting the PLN/USD exchange rate from the obtained result of the query;
  5. doing simple statistical analysis of the fetched data;
  6. plotting the fetched data with a proper handling of missing values.

7.1 Understanding the NBP Web API

7.1.1  Getting the data via a web browser

7.1.2  Getting the data using Julia

7.1.3  Handling cases when NBP Web API query fails

7.2 Missing data in Julia

7.2.1  Definition of the missing value

7.2.2  Working with missing values

7.3 Getting the time series data from NBP Web API

7.3.1  Working with dates

7.3.2  Fetching data from NBP Web API for a range of dates

7.4 Analyzing the data fetched from NBP Web API

7.4.1  Computing summary statistics

7.4.2  Finding in which days of week we have the most missing values

7.4.3  Plotting the PLN/USD exchange rate