In [32]:
% matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
import csv
import math

In [36]:
f = open('./data/AMZN.csv', 'r')

reader = csv.reader(f)
header = next(reader)

close = []
date = {}
i = 0
for row in reader:
    date[i] = row[0]
    close.append(float(row[4]))
    i = i + 1
f.close()

def approx(close, t_approx, t):
    np_close = np.array(close)
    close_1 = np.diff(np_close)
    close_2 = np.diff(close_1)
    return np_close[t_approx] + close_1[t_approx] * (t - t_approx) + (close_2[t_approx] / math.factorial(2)) * np.power(t - t_approx, 2)


[960.570007, 958.469971, 953.289978, 966.900024, 958.0, 952.450012, 945.26001, 946.02002, 954.059998, 967.590027, 980.599976, 978.25, 965.27002, 967.799988, 979.469971, 965.900024, 977.960022, 982.580017, 999.599976, 992.210022, 986.789978]
966.900024