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:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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() |