Signal
The output of a Strategy is a list of Signal objects. Each signal contains three pieces of
information:
asset— the asset the signal applies to.rating— a float, normally between -1.0 (strong sell) and 1.0 (strong buy). This range is however not enforced.type— aSignalTypeflag indicating how the signal may be used:ENTRY(open or increase a position),EXIT(close or reduce a position), orENTRY_EXIT(both, the default).
There are several ways to create a signal:
| Constructor | rating | type | Use |
|---|---|---|---|
Signal.buy(asset) | 1.0 | ENTRY_EXIT | Strong buy |
Signal.sell(asset) | -1.0 | ENTRY_EXIT | Strong sell |
Signal.buy(asset, SignalType.ENTRY) | 1.0 | ENTRY | Only open/increase a position |
Signal.sell(asset, SignalType.EXIT) | -1.0 | EXIT | Only close/reduce a position |
Signal(asset, rating, type) | custom | custom | Full control |
from roboquant import Stock, Signal, SignalType
apple = Stock("AAPL")
buy = Signal.buy(apple)
print(buy)
sell = Signal.sell(apple, SignalType.EXIT)
print(sell)
custom = Signal(apple, 0.5, SignalType.ENTRY)
print(custom)Signal(asset=Stock(symbol='AAPL', currency='USD'), rating=1.0, type=ENTRY_EXIT)
Signal(asset=Stock(symbol='AAPL', currency='USD'), rating=-1.0, type=EXIT)
Signal(asset=Stock(symbol='AAPL', currency='USD'), rating=0.5, type=ENTRY)
Some of the convenience properties on a signal: is_buy, is_sell, is_entry, and is_exit.