Data
Data Coordinates
DataCoordinate
is an object which uses a coordinate system for creating a reference to a data
series. The object is immutable and hashable, so they can be applied in caching, streaming, and
other applications where mapping the coordinates may be important. DataCoordinate
s can also be
utilized to fetch the series defined by the coordinate.
DataCoordinate Class
Below is an example of fetching implied volatility for AAPL UW using the Marquee assetId.
Note
Examples require an initialized GsSession and relevant identifier licenses. Please refer to Sessions for details.
import datetime as dt
from gs_quant.data import DataDimension, DataCoordinate, DataMeasure
dimensions = {
'assetId': 'MA4B66MW5E27U9VBB94', # AAPL UW
DataDimension.TENOR: '1m',
DataDimension.STRIKE_REFERENCE: 'spot',
DataDimension.RELATIVE_STRIKE: .8
}
coordinate = DataCoordinate(measure=DataMeasure.IMPLIED_VOLATILITY,
dataset_id='EDRVOL_PERCENT_STOCK_STANDARD',
dimensions=dimensions)
coordinate.get_series(start=dt.date(2020, 1, 2), end=dt.date(2020, 1, 8))
Output:
2020-01-02 0.399873
2020-01-03 0.402368
2020-01-06 0.394695
2020-01-07 0.392863
2020-01-08 0.372748
dtype: float64
Get a DataCoordinate from an Entity
Using an Entity
object, such as an Asset
object, you can get a DataCoordinate
using the
get_data_coordinate
method. With this DataCoordinate
, a series can be fetched without explicitly
specifying the dataset ID.
import datetime as dt
from gs_quant.data import DataDimension, DataCoordinate, DataMeasure
from gs_quant.markets.securities import SecurityMaster, AssetIdentifier
dimensions = {
DataDimension.TENOR: '1m',
DataDimension.STRIKE_REFERENCE: 'spot',
DataDimension.RELATIVE_STRIKE: .8
}
spx = SecurityMaster.get_asset('SPX', AssetIdentifier.BLOOMBERG_ID)
coordinate: DataCoordinate = spx.get_data_coordinate(measure=DataMeasure.IMPLIED_VOLATILITY,
dimensions=dimensions,
frequency=DataFrequency.DAILY)
coordinate.get_series(start=dt.date(2020, 1, 1), end=dt.date(2020, 1, 8))
Output:
2020-01-02 0.300644
2020-01-03 0.315498
2020-01-06 0.311003
2020-01-07 0.306926
2020-01-08 0.308256
dtype: float64
Comparable and Hashable
DataCoordinates
are comparable and hashable objects which allow them to be conveniently compared
for equality and mapped for caching and streaming purposes.
dimensions_a = {
DataDimension.TENOR: '1m',
DataDimension.STRIKE_REFERENCE: 'spot',
DataDimension.RELATIVE_STRIKE: .8
}
# Same dimensions but different order
dimensions_b = {
DataDimension.RELATIVE_STRIKE: .8,
DataDimension.STRIKE_REFERENCE: 'spot',
DataDimension.TENOR: '1m'
}
coord_a = DataCoordinate('EDRVOL_PERCENT_STOCK_STANDARD',
DataMeasure.IMPLIED_VOLATILITY,
dimensions_a)
coord_b = DataCoordinate('EDRVOL_PERCENT_STOCK_STANDARD',
DataMeasure.IMPLIED_VOLATILITY,
dimensions_b)
assert coord_a == coord_b # True
assert hash(coord_a) == hash(coord_b) # True