Skip to content

Commit

Permalink
xldb
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Mosley authored and Bart Mosley committed Sep 28, 2011
1 parent 480703c commit f6522d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion studies/spreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def spread_timeseries(series1, series2):
if value2:
value1 = series1.get(dt, None)
spread = value1 - value2
ratio = value2/value1
ratio = value1/value2
spread_series[dt] = (value1, value2, spread, ratio)

return spread_series
Expand Down
7 changes: 5 additions & 2 deletions tools/htmldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def quotes_yahoo(ticker, begin, end=None, mode='d'):

# call matplotlib function, asobject=True
# for structured numpy array
quotes = quotes_historical_yahoo('INTC', date1, date2, asobject=True)

try:
quotes = quotes_historical_yahoo(ticker, date1, date2, asobject=True)
except:
return None

if mode == 'd':
vTuple = lambda x: (x['date'],
tuple([x[h] for h in quote_header[1:]]))
Expand Down
15 changes: 10 additions & 5 deletions xldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,24 @@ def timeseries(self, xdata, sheet=0, hdr=None):
date_keys = xdata.keys()
date_keys.sort()

# how will we access data?
testdata = xdata[date_keys[0]]
if hasattr(testdata, "__iter__"):
get_column_value = lambda colnum: value[colnum-1]

else:
get_column_value = lambda n: value

# create header if not provided
if not hdr:
testdata = xdata[date_keys[0]]

hdr = ['date']

if hasattr(testdata, "__iter__"):
hdr.extend(['value%s'%str(n) for n in range(1, len(testdata)+1)])
get_column_value = lambda colnum: value[colnum-1]

else:
hdr.append('value1')
get_column_value = lambda n: value


# write header row
for ncol in range(len(hdr)):
rc = self.write(hdr[ncol], 0, ncol, sheet)
Expand Down

0 comments on commit f6522d9

Please sign in to comment.