I am having an issue and seem to not understand the concept on looping thru an array. My goal is divide each value in my array by the preceding value. Sort of like an i / i-1
I am dividing closing price stock data. My goal is to then store that value into a new array.
An example of stock data could be [1000, 1002, 1008, 999] Output should look like [1, 1.002, 1.005988, 0.99107]
Here is my code
date, closep, highp, lowp, openp, volume = np.loadtxt(stockFile, delimiter=',', unpack=True,
converters={ 0: mdates.strpdate2num('%Y%m%d')})
normalizedData = []
for i in closep:
na_normalized_price = closep/closep[i-1]
print na_normalized_price
normalizedData.append(na_normalized_price)
my two issues are as follows:
It doesn't stop dividing - so I'm guessing I will need a count of some sort to end the loop
error: Traceback (most recent call last): File "C:\Users\antoniozeus\Desktop\BuyAndHold.py", line 31, in na_normalized_price = closep/closep[i-1] IndexError: index out of bounds
I dont believe I am understanding how to append in numpy