Anyone here able to help with some python error messages?
1. Traceback (most recent call last):
2. ValueError: time data '' does not match format '%Y%m%d'
The code seems to run & execute based on the conditions stated below, up till printing 'we are complete. here is total profit:'.
PLEASE HELP!
this is the code I'm using:
1. Traceback (most recent call last):
2. ValueError: time data '' does not match format '%Y%m%d'
The code seems to run & execute based on the conditions stated below, up till printing 'we are complete. here is total profit:'.
PLEASE HELP!
this is the code I'm using:
import time
from datetime import datetime
from time import mktime
def backTest():
stance = 'none'
buyPrice = 0
sellPrice = 0
previousPrice = 0
totalProfit = 0
bigDataFile = open('AAPL.txt','r')
readFile = bigDataFile.read()
lineSplit = readFile.split('\n')
for everyLine in lineSplit:
dividedLine = everyLine.split(',')
initialDate = dividedLine[0]
unixStamp = mktime(datetime.strptime(initialDate, '%Y%m%d').timetuple())
dateStamp = time.strftime('%d/%m/%Y',time.localtime(unixStamp))
stockPrice = float(dividedLine[4])
reformatted = unixStamp,dateStamp,stockPrice
if stance == 'none':
if stockPrice < previousPrice:
print 'buy triggered!'
buyPrice = stockPrice
print 'bought stock for',buyPrice
stance = 'holding'
elif stance == 'holding':
if stockPrice > buyPrice * .002 + buyPrice:
print 'sell triggered!'
sellPrice = stockPrice
print 'finished trade, sold for:',sellPrice
stance = 'none'
tradeProfit = sellPrice - buyPrice
totalProfit += tradeProfit
print totalProfit
previousPrice = stockPrice
print 'we are complete. here is total profit:'
print totalProfit
time.sleep(555)
backTest()
