Hello,
For the attached algorithm, it will run with a batch transform window length (global W_L) of 30, but if I try 90, I get a general runtime error, with no indication of the source of the error.
Any idea what's going on?
Thanks,
Grant
Hello,
For the attached algorithm, it will run with a batch transform window length (global W_L) of 30, but if I try 90, I get a general runtime error, with no indication of the source of the error.
Any idea what's going on?
Thanks,
Grant
Here's the code (it is not available under "Source Code" above:
# References:
# 1. Ming Li; Xin Chen; Xin Li; Bin Ma; Vitanyi, P.M.B.; , "The similarity metric,"
# Information Theory, IEEE Transactions on , vol.50, no.12, pp. 3250- 3264, Dec. 2004
# http://homepages.cwi.nl/~paulv/papers/similarity.pdf
#
# 2. Lin, Jessica, et al. "A symbolic representation of time series, with implications for
# streaming algorithms." Proceedings of the 8th ACM SIGMOD workshop on Research issues
# in data mining and knowledge discovery. ACM, 2003.
# www.cs.ucr.edu/~stelo/papers/DMKD03.pdf
import numpy as np
import zlib
from scipy import stats
import random
import itertools
import datetime
# globals for get_data batch transform decorator
R_P = 1 # refresh period in days
W_L = 90 # window length in days
def initialize(context):
context.stocks = []
# bottom = random.randint(0,98)
bottom = 98
range = 2
log.info("universe is {b} to {t}".format(b=bottom, t=bottom+range))
set_universe(universe.DollarVolumeUniverse(bottom, bottom+range))
# context.day = 0
def handle_data(context, data):
context.stocks = [sid for sid in data]
# get data (select prices, volume, etc. in batch transform get_data)
d = get_data(data, context.stocks)
if d is None:
return
# # update plot daily
# trade_day = data[context.stocks[0]].datetime.day
#
# if trade_day == context.day:
# return
#
# context.day = trade_day
# code data & convert to strings
coded_d = code_data(d)
# remove columns with NaNs
# http://stackoverflow.com/questions/1642730/how-to-delete-columns-in-numpy-array
coded_d=np.ma.compress_cols(np.ma.masked_invalid(coded_d))
m =coded_d.shape[1]
n = coded_d.shape[0]
X = [i for i in range(m)]
for j in range(m):
X[j] = ''
for i in range(n):
X[j] = X[j] + str(int(coded_d[i,j]))
s = sim_pairs(X)
# compute & plot coefficien of variation
# http://en.wikipedia.org/wiki/Coefficient_of_variation
mean_s = np.mean(s)
std_s = np.std(s,ddof=1)
CV = std_s/mean_s
record(CV = CV)
@batch_transform(refresh_period=R_P, window_length=W_L, clean_nans=False) # set globals R_P & W_L above
def get_data(datapanel,sids):
return datapanel['price'].as_matrix(sids)
def code_data(uncoded_data):
# code data according to Ref. 2
coded_d = stats.zscore(uncoded_data, axis=0, ddof=1)
coded_d[coded_d >= 0.67] = 4
coded_d[(coded_d >= 0.0) & (coded_d < 0.67)] = 3
coded_d[(coded_d >= -0.67) & (coded_d < 0.0)] = 2
coded_d[coded_d < -0.67] = 1
return coded_d
def NCD(X,Y):
CX = len(zlib.compress(X,9))
CY = len(zlib.compress(Y,9))
return (len(zlib.compress(X+Y,9)) - min(CX,CY)) / float(max(CX,CY))
def sim_pairs(string_data):
pairs = list((itertools.combinations(string_data,2)))
n = len(pairs)
result = np.zeros(n)
for j in range(n):
result[j] = NCD(pairs[j][0],pairs[j][1])
return result
Hi Grant,
I'm baffled myself. I was able to get a more articulate error from the server logs, but I haven't solved it yet.
Exception: columns overlap: <class 'pandas.tseries.index.DatetimeIndex'>
Obviously, we need to give a better error to you. And we need to make it easier to debug!
Dan
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.
Thanks Dan,
No rush...sounds like it might be in the batch transform, since that is the only place that I know of where pandas is being used. I stripped everything down and still get the error:
# globals for get_data batch transform decorator
R_P = 1 # refresh period in days
W_L = 90 # window length in days
def initialize(context):
context.stocks = []
bottom = 98
range = 2
log.info("universe is {b} to {t}".format(b=bottom, t=bottom+range))
set_universe(universe.DollarVolumeUniverse(bottom, bottom+range))
def handle_data(context, data):
context.stocks = [sid for sid in data]
# get data (select prices, volume, etc. in batch transform get_data)
d = get_data(data, context.stocks)
if d is None:
return
@batch_transform(refresh_period=R_P, window_length=W_L, clean_nans=False) # set globals R_P & W_L above
def get_data(datapanel,sids):
return datapanel['price'].as_matrix(sids)
Grant