예제 #1
0
    def build_graph(self, entity: Entity, cell,
                    queries: List[Union[DataQueryInfo, MeasureQueryInfo]],
                    rdate_entity_map: Dict[str, Set[Tuple]],
                    overrides: Optional[List]):
        """ Generates the nested cell graph and keeps a map of leaf data queries to processors"""
        self.data_cell = cell
        self.__add_required_rdates(entity, rdate_entity_map)

        attributes = self.__dict__

        if self.measure_processor:
            queries.append(
                MeasureQueryInfo(attr='a', processor=self, entity=entity))

        for attr_name, child in self.children.items():
            if isinstance(child, DataCoordinate):
                # Override coordinate dimensions
                if overrides:
                    override_dimensions = list(
                        filter(lambda x: x.coordinate == child, overrides))
                    if len(override_dimensions):
                        use_default = True
                        for override in overrides:
                            if override.coordinate_id == child.id:
                                child.set_dimensions(override.dimensions)
                                use_default = False
                                break
                        if use_default and overrides[0].coordinate_id is None:
                            child.set_dimensions(overrides[0].dimensions)

                if child.frequency == DataFrequency.DAILY:
                    query = DataQuery(coordinate=child,
                                      start=attributes.get('start'),
                                      end=attributes.get('end'))
                else:
                    query = DataQuery(coordinate=child,
                                      query_type=DataQueryType.LAST)

                # track the leaf data query
                queries.append(
                    DataQueryInfo(attr=attr_name,
                                  processor=self,
                                  query=query,
                                  entity=entity))

            elif isinstance(child, BaseProcessor):
                # Set the children's parent fields
                child.parent = self
                child.parent_attr = attr_name
                child.build_graph(entity, cell, queries, rdate_entity_map,
                                  overrides)

            elif isinstance(child, DataQueryInfo):
                child.parent = self
                child.parent_attr = attr_name
                child.processor = self
                queries.append(child)
예제 #2
0
 def get_benchmark_coordinate(self) -> DataQueryInfo:
     coordinate = DataCoordinate(measure=DataMeasure.CLOSE_PRICE,
                                 frequency=DataFrequency.DAILY)
     data_query = DataQuery(coordinate=coordinate,
                            start=self.start,
                            end=self.end)
     return DataQueryInfo('benchmark', None, data_query, self.benchmark)
예제 #3
0
    def build_graph(self, entity: Entity, cell, queries: List[DataQueryInfo],
                    overrides: Optional[List]):
        """ Generates the nested cell graph and keeps a map of leaf data queries to processors"""
        self.data_cell = cell

        attributes = self.__dict__

        for attr_name, child in self.children.items():
            if isinstance(child, DataCoordinate):
                # Override coordinate dimensions
                if overrides:
                    override_dimensions = list(
                        filter(lambda x: x.coordinate == child, overrides))
                    if len(override_dimensions):
                        child.set_dimensions(overrides[0].dimensions)

                if child.frequency == DataFrequency.DAILY:
                    query = DataQuery(coordinate=child,
                                      start=attributes.get('start'),
                                      end=attributes.get('end'))
                else:
                    query = DataQuery(coordinate=child,
                                      query_type=DataQueryType.LAST)

                # track the leaf data query
                queries.append(
                    DataQueryInfo(attr=attr_name,
                                  processor=self,
                                  query=query,
                                  entity=entity))

            elif isinstance(child, BaseProcessor):
                # Set the children's parent fields
                child.parent = self
                child.parent_attr = attr_name
                child.build_graph(entity, cell, queries, overrides)

            elif isinstance(child, DataQueryInfo):
                child.parent = self
                child.parent_attr = attr_name
                child.processor = self
                queries.append(child)
    def get_excess_returns_query(self) -> DataQueryInfo:
        marquee_id = SharpeAssets[self.currency.value].value
        entity = Stock(marquee_id, "", "")

        coordinate: DataCoordinate = DataCoordinate(
            measure=DataMeasure.CLOSE_PRICE,
            frequency=DataFrequency.DAILY
        )

        data_query: DataQuery = DataQuery(coordinate=coordinate, start=self.start, end=self.end)

        return DataQueryInfo('excess_returns', None, data_query, entity)