scml.scml2020.components.trading ================================ .. py:module:: scml.scml2020.components.trading Classes ------- .. autoapisummary:: scml.scml2020.components.trading.TradingStrategy scml.scml2020.components.trading.ReactiveTradingStrategy scml.scml2020.components.trading.PredictionBasedTradingStrategy scml.scml2020.components.trading.MarketAwarePredictionBasedTradingStrategy Module Contents --------------- .. py:class:: TradingStrategy(*args, **kwargs) Base class for all trading strategies. Provides: - `inputs_needed` (np.ndarray): How many items of the input product do I need to buy at every time step (n_steps vector). This should be read **but not updated** by the `NegotiationManager`. - `outputs_needed` (np.ndarray): How many items of the output product do I need to sell at every time step (n_steps vector). This should be read **but not updated** by the `NegotiationManager`. - `inputs_secured` (np.ndarray): How many items of the input product I already contracted to buy (n_steps vector) [out of `input_needed`]. This can be read **but not updated** by the `NegotiationManager`. - `outputs_secured` (np.ndarray): How many units of the output product I already contracted to sell (n_steps vector) [out of `outputs_secured`] This can be read **but not updated** by the `NegotiationManager`. Hooks Into: - `init` - `internal_state` Remarks: - `Attributes` section describes the attributes that can be used to construct the component (passed to its `__init__` method). - `Provides` section describes the attributes (methods, properties, data-members) made available by this component directly. Note that everything provided by the bases of this components are also available to the agent (Check the `Bases` section above for all the bases of this component). - `Requires` section describes any requirements from the agent using this component. It defines a set of methods or properties/data-members that must exist in the agent that uses this component. These requirement are usually implemented as abstract methods in the component - `Abstract` section describes abstract methods that MUST be implemented by any descendant of this component. - `Hooks Into` section describes the methods this component overrides calling `super` () which allows other components to hook into the same method (by overriding it). Usually callbacks starting with `on_` are hooked into this way. - `Overrides` section describes the methods this component overrides without calling `super` effectively disallowing any other components after it in the MRO to call this method. Usually methods that do some action (i.e. not starting with `on_`) are overridden this way. .. py:attribute:: inputs_needed :type: numpy.ndarray :value: None How many items of the input product do I need at every time step .. py:attribute:: outputs_needed :type: numpy.ndarray :value: None How many items of the output product do I need at every time step .. py:attribute:: inputs_secured :type: numpy.ndarray :value: None How many units of the input product I have already secured per step .. py:attribute:: outputs_secured :type: numpy.ndarray :value: None How many units of the output product I have already secured per step .. py:method:: init() .. py:method:: step() .. py:property:: internal_state .. py:class:: ReactiveTradingStrategy(*args, **kwargs) Bases: :py:obj:`scml.scml2020.components.SignAllPossible`, :py:obj:`TradingStrategy` The agent reactively responds to contracts for selling by buying and vice versa. Hooks Into: - `on_contracts_finalized` Remarks: - `Attributes` section describes the attributes that can be used to construct the component (passed to its `__init__` method). - `Provides` section describes the attributes (methods, properties, data-members) made available by this component directly. Note that everything provided by the bases of this components are also available to the agent (Check the `Bases` section above for all the bases of this component). - `Requires` section describes any requirements from the agent using this component. It defines a set of methods or properties/data-members that must exist in the agent that uses this component. These requirement are usually implemented as abstract methods in the component - `Abstract` section describes abstract methods that MUST be implemented by any descendant of this component. - `Hooks Into` section describes the methods this component overrides calling `super` () which allows other components to hook into the same method (by overriding it). Usually callbacks starting with `on_` are hooked into this way. - `Overrides` section describes the methods this component overrides without calling `super` effectively disallowing any other components after it in the MRO to call this method. Usually methods that do some action (i.e. not starting with `on_`) are overridden this way. .. py:method:: on_contracts_finalized(signed: List[negmas.Contract], cancelled: List[negmas.Contract], rejectors: List[List[str]]) -> None .. py:class:: PredictionBasedTradingStrategy(*args, add_trade=True, **kwargs) Bases: :py:obj:`scml.scml2020.components.prediction.FixedTradePredictionStrategy`, :py:obj:`scml.scml2020.components.prediction.MeanERPStrategy`, :py:obj:`TradingStrategy` A trading strategy that uses prediction strategies to manage inputs/outputs needed Hooks Into: - `init` - `before_step` - `step` - `on_contracts_finalized` - `sign_all_contracts` - `on_agent_bankrupt` Requires: - `expected_inputs` (np.ndarray): How many items of the input product do I expect to have every day. Should be adjusted by the `TradePredictionStrategy` . - `expected_outputs` (np.ndarray): How many items of the output product do I expect to have every day. Should be adjusted by the `TradePredictionStrategy` . Remarks: - `Attributes` section describes the attributes that can be used to construct the component (passed to its `__init__` method). - `Provides` section describes the attributes (methods, properties, data-members) made available by this component directly. Note that everything provided by the bases of this components are also available to the agent (Check the `Bases` section above for all the bases of this component). - `Requires` section describes any requirements from the agent using this component. It defines a set of methods or properties/data-members that must exist in the agent that uses this component. These requirement are usually implemented as abstract methods in the component - `Abstract` section describes abstract methods that MUST be implemented by any descendant of this component. - `Hooks Into` section describes the methods this component overrides calling `super` () which allows other components to hook into the same method (by overriding it). Usually callbacks starting with `on_` are hooked into this way. - `Overrides` section describes the methods this component overrides without calling `super` effectively disallowing any other components after it in the MRO to call this method. Usually methods that do some action (i.e. not starting with `on_`) are overridden this way. .. py:method:: init() .. py:method:: _update_needs() .. py:method:: before_step() .. py:method:: step() .. py:method:: on_contracts_finalized(signed: List[negmas.Contract], cancelled: List[negmas.Contract], rejectors: List[List[str]]) -> None .. py:method:: sign_all_contracts(contracts: List[negmas.Contract]) -> List[Optional[str]] .. py:method:: _format(c: negmas.Contract) .. py:method:: on_agent_bankrupt(agent: str, contracts: List[negmas.Contract], quantities: List[int], compensation_money: int) -> None .. py:class:: MarketAwarePredictionBasedTradingStrategy(*args, predicted_outputs: Union[int, numpy.ndarray] = None, predicted_inputs: Union[int, numpy.ndarray] = None, add_trade=False, **kwargs) Bases: :py:obj:`scml.scml2020.components.prediction.MarketAwareTradePredictionStrategy`, :py:obj:`PredictionBasedTradingStrategy` Predicts an amount based on publicly available market information. Falls back to fixed prediction if no information is available Hooks Into: - `internal_state` - `on_contracts_finalized` Remarks: - `Attributes` section describes the attributes that can be used to construct the component (passed to its `__init__` method). - `Provides` section describes the attributes (methods, properties, data-members) made available by this component directly. Note that everything provided by the bases of this components are also available to the agent (Check the `Bases` section above for all the bases of this component). - `Requires` section describes any requirements from the agent using this component. It defines a set of methods or properties/data-members that must exist in the agent that uses this component. These requirement are usually implemented as abstract methods in the component - `Abstract` section describes abstract methods that MUST be implemented by any descendant of this component. - `Hooks Into` section describes the methods this component overrides calling `super` () which allows other components to hook into the same method (by overriding it). Usually callbacks starting with `on_` are hooked into this way. - `Overrides` section describes the methods this component overrides without calling `super` effectively disallowing any other components after it in the MRO to call this method. Usually methods that do some action (i.e. not starting with `on_`) are overridden this way.