def __init__(self, past, future, features = None):
"""Create a training pattern.
Parameters:
past -- past feature vectors as a tensor of shape [P, V]
where P is past days and V is the vectors/day
future -- future feature vectors as a tensor of [F, V]
where F is future days and V is the vectors/day
features -- a sequence of feature names to use
where None means use all features
"""
# calculate training input from past features
past_subfeatures = [[self._subfeatures(vector, features)
for vector in vectors]
for vectors in past]
self._input = numpy.array(
[list(util.flatten(vectors)) for vectors in past_subfeatures])
# calculate training output from future volatility
future_returns = numpy.log1p(
[[vector.ret for vector in vectors] for vectors in future])
self._output = numpy.std(future_returns, axis = 0, ddof = 1)\
* numpy.sqrt(252)
# calculate past returns for forecasts
self._past_returns = numpy.log1p(
[[vector.ret for vector in vectors] for vectors in past])
评论列表
文章目录