Skip to content

RainBoltz/Series2GAF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

  • Series2GAF can be used to transform time series into Gramian Angular Field. GAF DEMO
  • There are many useful utility features for financial research in Series2GAF, and will be mentioned in the following sections.

Series2GAF

simple time series encoding package, focused on financial tasks.

this is an simple example:

import numpy as np
from series2gaf import GenerateGAF

# create a random sequence with 200 numbers
# all numbers are in the range of 50.0 to 150.0
random_series = np.random.uniform(low=50.0, high=150.0, size=(200,))

# set parameters
timeSeries = list(random_series)
windowSize = 50
rollingLength = 10
fileName = 'demo_%02d_%02d'%(windowSize, rollingLength)

# generate GAF pickle file (output by Numpy.dump)
GenerateGAF(all_ts = timeSeries,
            window_size = windowSize,
            rolling_length = rollingLength,
            fname = fileName)

now we get a file named demo_50_10_gaf.pkl in current directory. inside the pickle file, you got a grammian angular field with shape (15, 50, 50).

  • shape[0] refers to data amount : floor((len(timeSeries)-(normalize_window_scaling-1)*windowSize)/windowSize)
  • shape[1] refers to image width : windowSize
  • shape[2] refers to image height : windowSize

Thats It!

if we want to preview the image results, just add these to the code:

from series2gaf import PlotHeatmap

gaf = np.load('%s_gaf.pkl'%fileName)
PlotHeatmap(gaf)

we can now find GAF heapmap images in a new child directory /output_img!

Functions

def GenerateGAF(all_ts, window_size, rolling_length, fname,
                normalize_window_scaling=1.0, method='summation', scale='[0,1]'):
  ...

def PlotHeatmap(all_img, save_dir='output_img'):
  ...

Parameters

  • all_ts: list
        the time series we want to transform.

  • window_size: int
        the sliding window size for transforming sequences into GAF images

  • rolling_length: int
        also known as "stride value" for the sliding window

  • fname: str
        output file name, the output pickle file will be named as "[fname]_gaf.pkl"

  • normalize_window_scaling: float, optional
        default: 1.0
        normalize the values in the windows, but considering a ratio of previous values

  • method: str, optional
        default: 'summation'
        'summation' is for GASF ( calculate cos(x1+x2) )
        'difference' if for GADF ( calculate sin(x1-x2) )

  • scale: str, optoinal
        default: '[0,1]'
        '[0,1]' means normalize the sequence in the range of 0 and 1
        '[-1,1]' means normalize the sequence in the range of -1 and 1

  • all_img: numpy.array
        input GAF multi-dimension array

  • save_dir: str, optional
        default: 'output_img'
        directory for output images


development environment

  • macOS 13.5.1
  • python 3.9

About

simple time series encoding package

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages