In this script, we will create functions that will be helpful for training, via the following steps:
- Import the numpy and math modules, as follows:
import numpy as npimport math
- Next, define a function to format the price to two decimal places, to reduce the ambiguity of the data:
def formatPrice(n): if n>=0: curr = "$" else: curr = "-$" return (curr +"{0:.2f}".format(abs(n)))
- Return a vector of stock data from the CSV file. Convert the closing stock prices from the data to vectors, and return a vector of all stock prices, as follows:
def getStockData(key): datavec = [] lines = open("data/" + key + ".csv", "r").read().splitlines() for line in lines[1:]: datavec.append(float(line.split(",")[4])) return datavec
- Next, ...