5 Analyzing time series data with arrays

 

This chapter covers:

  • Analyzing stock prices with Fortran arrays
  • Declaring, allocating, and initializing arrays
  • Using whole-array arithmetic to quantify stock performance and risk

An array is a sequence of data elements that are of same type and contiguous in memory. While this may seem restrictive, it comes with its advantages. First, it allows you to write simpler code using expressive one-liners that work on many elements at once. While arrays have been part of Fortran since its birth, whole-array operators and arithmetic have been introduced in Fortran 90, allowing programmers to write cleaner, shorter, and less error-prone code. In a nutshell, arrays allow you to easily work on large datasets and apply functions and arithmetic operators on whole arrays without resorting to loops or other verbose syntax.

5.1  Analyzing stock prices with Fortran arrays

5.1.1  Objectives for this exercise

5.1.2  About the data

5.1.3  Getting the data and code

5.2  Finding the best and worst performing stocks

5.2.1  Declaring arrays

5.2.2  Array constructors

5.2.3  Reading stock data from files

5.2.4  Allocating arrays of certain size or range

5.2.5  Allocating an array from another array

5.2.6  Cleaning up after use

5.2.7  Checking for allocation status

5.2.8  Catching allocation and deallocation errors

5.2.9  Implementing the CSV reader subroutine

5.2.10  Indexing and slicing arrays

5.3  Identifying risky stocks

5.4  Finding good times to buy and sell

5.5  Answer Key

5.5.1  Exercise 1: Convenience (de)allocator subroutines

5.5.2  Exercise 2: Reversing an array

5.5.3  Exercise 3: Computing the moving average over custom time period.