def commit(self): self.Error.seasonal_decompose_fail.clear() data = self.data if not data or not self.selected: self.Outputs.time_series.send(data) return selected_subset = Timeseries.from_table( Domain(self.selected, source=data.domain), data) # FIXME: might not pass selected interpolation method with self.progressBar(len(self.selected)) as progress: try: adjusted_data = seasonal_decompose( selected_subset, self.DECOMPOSITION_MODELS[self.decomposition], self.n_periods, callback=lambda *_: progress.advance()) except ValueError as ex: self.Error.seasonal_decompose_fail(str(ex)) adjusted_data = None if adjusted_data is not None: new_domain = Domain( data.domain.attributes + adjusted_data.domain.attributes, data.domain.class_vars, data.domain.metas) ts = Timeseries.from_numpy(new_domain, X=hstack((data.X, adjusted_data.X)), Y=data.Y, metas=data.metas) ts.time_variable = data.time_variable else: ts = None self.Outputs.time_series.send(ts)
def finance_data(symbol, since=None, until=None, granularity='d'): """Fetch Yahoo Finance data for stock or index `symbol` within the period after `since` and before `until` (both inclusive). Parameters ---------- symbol: str A stock or index symbol, as supported by Yahoo Finance. since: date A start date (default: 1900-01-01). until: date An end date (default: today). granularity: 'd' or 'w' or 'm' or 'v' What data to get: daily, weekly, monthly, or dividends. Returns ------- data : Timeseries """ if since is None: since = date(1900, 1, 1) if until is None: until = date.today() f = web.DataReader(symbol, 'yahoo', since, until) data = Timeseries.from_data_table(table_from_frame(f)) # Make Adjusted Close a class variable attrs = [var.name for var in data.domain.attributes] attrs.remove('Adj Close') data = Timeseries.from_table( Domain(attrs, [data.domain['Adj Close']], None, source=data.domain), data) data.name = symbol data.time_variable = data.domain['Date'] return data
def on_changed(self): self.commit() def commit(self): self.Warning.no_transforms_added.clear() data = self.data if not data: self.Outputs.time_series.send(None) return if not len(self.table_model): self.Warning.no_transforms_added() self.Outputs.time_series.send(None) return ts = moving_transform(data, self.table_model, self.non_overlapping and self.fixed_wlen) self.Outputs.time_series.send(ts) if __name__ == "__main__": data = Timeseries.from_file('airpassengers') attrs = [var.name for var in data.domain.attributes] if 'Adj Close' in attrs: # Make Adjusted Close a class variable attrs.remove('Adj Close') data = Timeseries.from_table( Domain(attrs, [data.domain['Adj Close']], None, source=data.domain), data) WidgetPreview(OWMovingTransform).run(data)