Pricers

Structure

Cosine’s pricers all inherit from the CosinePricer class and are responsible for providing auxiliary pricing generation which maybe useful or required depending on the strategy implementation at play. Pricers are more of an optional component within the algo framework, as not every strategy will need one. Pricers are designed to be pipelined, such that algos can leverage a chain of them to generate supplementary pricing based on the base pricing retrieved from the feeds. Pricer may also be used to source external pricing information which can be pulled into the algo to generate pricing related information (e.g. generated information which takes the feed pricing + externally sourced data as inputs and outputs information used by the strategy to generate quotes or order working) required for the specific strategy.

An Example Use Case

A typical example use-case could be as follows:

An algo strategy implementation wishes to quote orders in relation to two specific sources of generated pricing information:

The strategy implementation aims to construct a dynamic quoting behaviour by performing the following actions on each tick:

  • Source aggregate market pricing for each instrument from the relevant feed source
  • Update the VWAP, feeding the latest feed pricing snapshot as input
  • Source the latest Volatility metrics to generate a dynamic quote width (i.e. widen quotes as the volatility increases, within a specified ratio)
  • Construct a set of quotes centered around the VWAP
  • Apply the generated leans to dynamically widen/narrow the quotes in-response to current volatility
  • Apply the new quotes via the order workers

This strategy can be achieved by leveraging a set of pricers to define the structural building blocks for managing the pricing info generation for use within the strategy.

An implementation here may consist of two pricers:

  • VWAPPricer where it’s generate_theo_prices() method override takes the feed snapshot prices as input and calculates the VWAP, setting it into the snapshot and returning it
  • VolPricer which takes the feed snapshot prices as input, makes a synchronous internal call to a volatility data source (REST/gRPC/etc), calculates the dynamic quote width info and writes that into the snapshot before returning it

With strategy logic to drive their use similar to the following example code:

# in the class CustomStrategy(CosineBaseStrategy)
def update(self):
    self.logger.debug("CustomStrategy - ** update **")

    ...

    # pull prices for instruments...
    self.logger.debug("CustomStrategy - source instrument prices from feed cache...")
    feed = self._cxt.feeds['pricing.mycustomfeed']
    prices = feed.capture_latest_prices(instruments=instruments)

    # massage pricing...
    for p in self._cxt.pricer_seq:
        self.logger.debug(f"CustomStrategy - calc pricing: [{p}]")
        prices = self._cxt.pricers[p].generate_theo_prices(instrument_prices=prices)

    ...

The pricer configuration in this example would be setup as follows:

...

pricers:
    Default: pricing.pricers.vwappricer,pricing.pricers.volpricer # the pipeline  ordering of pricers...
    settings:
        pricing.pricers.vwappricer:
            ... <pricer-specific config> ...
        pricing.pricers.volpricer:
            ... <pricer-specific config> ...
...

Pricers are setup via the configuration file (See the Configuration Management section for more details) with all of their custom pricer-specific attributes defined. These config attributes will be automatically set as member attributes on the class instance on construction via the CosineAlgo. Once a pricer instance has been created, the CosineAlgo calls the pricer’s setup() method, which is expected to initialise any external data sourcing or internal setup requirements. The CosinePricer base class provides access to the CosineProcWorkers worker pool instance, that can be using during setup to instantiate a worker for any asynchronous data source connectivity required (if applicable).

The NullPricer has been provided as an initial pricer skeleton, mainly to demonstrate how it fits into the wider framework and how it can be used via pipelining within strategy implementations. Feel free to check out the code for this pricer implementation to familiarise yourself with the structure.