import scikits.timeseries.lib.tstables as tstab import scikits.timeseries.lib.reportlib as rl ## a test series data = np.arange(1, 366) startdate = ts.Date(freq='D', year=2009, month=1, day=1) test_series = ts.time_series(data, start_date=startdate, freq='D') output_dir = '../timeseries' try: os.mkdir(output_dir) except OSError: pass ## write to csv file csv_file = os.path.abspath(os.path.join(output_dir, 'test_series.csv')) mycsv = open(csv_file, 'w') csvReport = rl.Report(test_series, delim=';', fixed_width=True) csvReport(output=mycsv) mycsv.close() # Write to a PyTables file hdf5_name = 'scikits_test1.hdf5' filepath_hdf5 = os.path.join(output_dir, hdf5_name) h5file = tstab.open_file(filepath_hdf5, mode="w", title='Example table with csikits time series') group_doc = h5file.create_group("/", 'examples', 'Test Data') table = h5file.createTimeSeriesTable(group_doc, 'Example_1', test_series) h5file.close()
# Data format is [(d, open, close, high, low, volume), ...] where d is # a floating point representation of the number of days since 01-01-01 UTC quotes = quotes_historical_yahoo('INTC', startdate, enddate) # Create a DateArray of daily dates and convert it to business day frequency dates = ts.date_array([q[0] for q in quotes], freq='DAILY').asfreq('BUSINESS') opens = [q[1] for q in quotes] # opens: the data portion of the timeserie # dates: the date portion of the timeserie raw_series = ts.time_series(opens, dates) test_series = raw_series #test_series = ts.fill_missing_dates(raw_series, fill_value=-1) # Write to a PyTables file output_dir = '../timeseries' try: os.mkdir(output_dir) except OSError: pass hdf5_name = 'scikits_test2.hdf5' filepath_hdf5 = os.path.join(output_dir, hdf5_name) h5file = tstab.open_file(filepath_hdf5, mode="w", title='Example table with csikits time series') group_doc = h5file.create_group("/", 'examples', 'Test Data') table = h5file.createTimeSeriesTable(group_doc, 'Example_2', test_series) h5file.close()