Files
  • main.py
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/matplotlib/sample_data/master/aapl.csv')

# Sanitize Data
df = df.drop('Date', axis=1)
df = df.drop('Adj Close', axis=1)
df = df.fillna(value=0)

def difference(dataset, interval=1):
  diff = list()
  for i in range(interval, len(dataset)):
    value = dataset[i] - dataset[i - interval]
    diff.append(value)
  return Series(diff)

def inverse_difference(history, yhat, interval=1):
  return yhat + history[-interval]

# Series
print(df.head())

# transform to be stationary
differenced = difference(df, 1)
print(differenced.head())

# invert transform
#inverted = list()
#for i in range(len(differenced)):
#  value = inverse_difference(series, differenced[i], len(series)-i)
#  inverted.append(value)
#inverted = Series(inverted)
#print(inverted.head())