margot.signals

The margot.signals module contains classes to help you construct trading algorithms using the MargotDataFrame

class margot.signals.BaseAlgo(env: dict = {}, calendar='XNYS')

A base class to inherit when implementing your trading algorithm.

You should at least implement signal() which is the output of a trading algorithm.

Parameters

env (dict) – a dictionary of environment variables, e.g. API keys. Overrides anything provided in sys env.

Raises
  • ValueError – the attribute, ‘data’ must be a reference to a MargotDataFrame.

  • NotImplementedError – If your subclass does not implement signal(), you will receive a NotImplementedError.

signal() → list

Return a list of Position objects for a given datetime.

simulate(when: datetime.datetime)

Simulate a signal from a point in time.

Parameters

when (datetime) – when to go back to

Returns

time-series of Positions.

Return type

pd.DataFrame

run(when: datetime.datetime = None)

Call to run this algo at a point in time (when).

We store the results of fetch_data() so that we can backtest without hitting the data provider more than once.

Returns

a list of Position objects for a given datetime

class margot.signals.Position(symbol: str, weight: float)

Represents a Position with a symbol and a weight.

Parameters
  • symbol (str) – The identifier of the symbol. e.g. ‘SPY’.

  • weight (float) – A value between -1.0 and +1.0 representing the weight of this symbol in the position list.