Python Algorithmic Trading Cookbook
上QQ阅读APP看书,第一时间看更新

Handling and Manipulating Date, Time, and Time Series Data

Time series data is ubiquitous when it comes to algorithmic trading. So, handling, managing, and manipulating time series data is essential to performing algorithmic trading successfully. This chapter has various recipes that demonstrate how algorithmic trading can be done using the Python standard library and pandas, which is a Python data analysis library.

For our context, time series data is a series of data consisting of equally spaced timestamps and multiple data points describing trading data in that particular time frame. 

When handling time series data, the first thing you should know is how to read, modify, and create Python objects that understand date and time. The Python standard library includes the datetime module, which provides the datetime and timedelta objects, which can handle everything about the date and time. The first seven recipes in this chapter talk about this module. The remainder of this chapter talks about handling time series data using the pandas library, which is a very efficient library for data analysis. The pandas.DataFrame class will be used in our recipes.

The following is a list of the recipes in this chapter: 

  • Creating datetime objects
  • Creating timedelta objects
  • Operations on datetime objects
  • Modifying datetime objects
  • Converting a datetime to a string
  • Creating a datetime object from a string
  • The datetime object and time zones
  • Creating a pandas.DataFrame object
  • DataFrame manipulation—renaming, rearranging, reversing, and slicing
  • DataFrame manipulation—applying, sorting, iterating, and concatenating
  • Converting a DataFrame into other formats
  • Creating a DataFrame from other formats