Developer Interface¶
Main Interface¶
All of PySGS functionality can be accessed by these 4 methods.
-
sgs.
time_serie
(ts_code: int, start: str, end: str) → pandas.core.series.Series[source]¶ Request a time serie data.
Parameters: - ts_code – time serie code.
- start – start date (DD/MM/YYYY).
- end – end date (DD/MM/YYYY).
Returns: Time serie values as pandas Series indexed by date.
Return type: Usage:
>>> CDI = 12 >>> ts = sgs.time_serie(CDI_CODE, start='02/01/2018', end='31/12/2018') >>> ts.head() 2018-01-02 0.026444 2018-01-03 0.026444 2018-01-04 0.026444 2018-01-05 0.026444 2018-01-08 0.026444
-
sgs.
dataframe
(ts_codes: Union[int, List[T], Tuple], start: str, end: str) → pandas.core.frame.DataFrame[source]¶ Creates a dataframe from a list of time serie codes.
Parameters: - ts_codes – single code or list/tuple of time series codes.
- start – start date (DD/MM/YYYY).
- end – end date (DD/MM/YYYY).
Returns: Pandas dataframe.
Return type: Usage:
>>> CDI = 12 >>> INCC = 192 # National Index of Building Costs >>> df = sgs.dataframe([CDI, INCC], start='02/01/2018', end='31/12/2018') >>> df.head() 12 192 2018-01-01 NaN 0.31 2018-01-02 0.026444 NaN 2018-01-03 0.026444 NaN 2018-01-04 0.026444 NaN 2018-01-05 0.026444 NaN
-
sgs.
search_ts
(query: Union[int, str], language: str) → Optional[list][source]¶ Search for time series and return metadata about it.
Parameters: - query – code(int) or name(str) used to search for a time serie.
- language – string (en or pt) used in query and return results.
Returns: List of results matching the search query.
Return type: Usage:
>>> results = sgs.search_ts("gold", language="en") >>> len(results) 29 >>> results[0] {'code': 4, 'name': 'BM&F Gold - gramme', 'unit': 'c.m.u.', 'frequency': 'D', 'first_value': Timestamp('1989-12-29 00:00:00'), 'last_value': Timestamp('2019-06-27 00:00:00'), 'source': 'BM&FBOVESPA'}
-
sgs.
metadata
(ts_code: Union[int, pandas.core.frame.DataFrame], language: str = 'en') → Optional[List[T]][source]¶ Request metadata about a time serie or all time series in a pandas dataframe.
Parameters: - ts_code – time serie code or pandas dataframe with time series as columns.
- language – language of the returned metadata.
Returns: List of dicts containing time series metadata.
Return type: Usage:
>>> CDI = 12 >>> INCC = 192 # National Index of Building Costs >>> df = sgs.dataframe([CDI, INCC], start='02/01/2018', end='31/12/2018') >>> sgs.metadata(df) [{'code': 12, 'name': 'Interest rate - CDI', 'unit': '% p.d.', 'frequency': 'D', 'first_value': Timestamp('1986-03-06 00:00:00'), 'last_value': Timestamp('2019-06-27 00:00:00'), 'source': 'Cetip'}, {'code': 192, 'name': 'National Index of Building Costs (INCC)', 'unit': 'Monthly % var.', 'frequency': 'M', 'first_value': Timestamp('1944-02-29 00:00:00'), 'last_value': Timestamp('2019-05-01 00:00:00'), 'source': 'FGV'}]