Quantlib
samplers
It contains samplers. A sampler triggers an onSample() callback when a sampling event happens, such as a time duration passed. It also calculates a decay value for this event.
samplers instances:
"samplers": [
["ds_0", ["TimeSampler", {"halflife": 5, "msecs": 100}]],
["ds_1", ["TimeSampler", {"halflife": 25, "msecs": 100}]]
]
samplers Overview:
Class | Description |
---|---|
TimeSampler | Fire sampling event when the specified duration has passed. |
TradeSampler | The sampler is fired on an event of a trade. |
VolSampler | The sampler is fired when the trading volume exceeds above a threshold. |
NotionalSampler | For a given notional threshold, the sampler is fired whenever the notional trade value (trade_price*trade_qty) over a period is greater than the notional threshold. |
samplers Details:
TimeSampler
Fire sampling event when the specified duration has passed.
Field | Description | Mandatory |
---|---|---|
msecs | The time interval to trigger a sampling event (millisecond unit). | Yes |
halflife | The number of sampler points taken to decay a value by half. | No |
TradeSampler
The sampler is fired on an event of a trade.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
halflife | The number of sampler points taken to decay a value by half. | No |
VolSampler
The sampler is fired when the trading volume exceeds above a threshold.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
vol | The user defined volume threhsold | Yes |
halflife | The number of sampler points taken to decay a value by half. | No |
multi_events_per_trade | A boolean parameter indicates whether the sampler will be fired multiple times based on the volume of the trade. | No |
NotionalSampler
For a given notional threshold, the sampler is fired whenever the notional trade value (trade_price*trade_qty) over a period is greater than the notional threshold.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
notional | The user defined notional threshold. | Yes |
halflife | The number of sampler points taken to decay a value by half. | No |
multi_events_per_trade | A boolean parameter indicates whether the sampler will be fired multiple times based on the notional of the trade. | No |
pricing_models
It contains pricing models. A pricing model generates the fair value of an asset. It can be calculated from books, trades or portfolios.
pricing_models instances:
"pricing_models": [
["BTCUSDT.HUOBI_midpx", ["MidPx", {"port": ["BTCUSDT", "HUOBI"]}]]
]
pricing_models Overview:
Class | Description |
---|---|
MidPx | A pricing model calculating the mid price of the specified symbol. |
AskPx | A pricing model calculating the bestask price of the specified symbol. |
BidPx | A pricing model calculating the bestbid price of the specified symbol. |
TradePx | A pricing model calculating the traded price of the specified symbol. |
TbboMid | A pricing model calculating the mid price based on best bid and ask tbbo price of the specified symbol. |
XbboMid | A pricing model calculating the mid price based on best bid and ask xbbo price of the specified symbol. |
PrevClosePx | A pricing model calculating the previous close price of the specified symbol. |
MktWPx | A pricing model calculating the bid/ask size weighted mid price of the specified symbol. |
Vwap | A pricing model calculating the volume weighted trade price of the specified symbol. |
Twap | A pricing model calculating the time weighted trade price of the specified symbol using EMA (exponential moving average). |
More pricing models will be shipped in QuantLib soon. |
pricing_models Details:
MidPx
A pricing model calculating the mid price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
AskPx
A pricing model calculating the bestask price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
BidPx
A pricing model calculating the bestbid price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
TradePx
A pricing model calculating the traded price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
TbboMid
A pricing model calculating the mid price based on best bid and ask tbbo price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
XbboMid
A pricing model calculating the mid price based on best bid and ask xbbo price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
PrevClosePx
A pricing model calculating the previous close price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
MktWPx
A pricing model calculating the bid/ask size weighted mid price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
Vwap
A pricing model calculating the volume weighted trade price of the specified symbol.
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
Sampler | The type of data sampling method. | Yes |
Twap
A pricing model calculating the time weighted trade price of the specified symbol using EMA (exponential moving average).
Field | Description | Mandatory |
---|---|---|
port | The source of market data, the first parameter is symbol, the second parameter is the exchange. | Yes |
Sampler | The type of data sampling method. | Yes |
variables
It contains variables. A variable generates a single number at any moment. It can be used as a standalone feature or an intermediated value to calculate a feature.
Variables instances:
"variables": [
["Zero", ["Const", {"value": 0.0}]],
["VAR_A_bidpx", ["PriceVar", {"pm": "BSVUSDTSWAP.OKEX_SWAP_bidpx"}]],
["RGAP_SBBA", ["Ratio", {"v1": "VAR_B_askpx", "v2": "VAR_A_askpx"}]],
["EMA_BBSA", ["VarEma", {"variable": "RGAP_BBSA", "sampler": "std_sampler"}]],
["STD_SBBA", ["VarStd2", {"variable": "RGAP_SBBA", "init_var_value": 1,"init_std_value": 0.0006,"sampler": "std_sampler"}]],
["BTCUSDT.H_ret", ["Sub", {"v1": "BTCUSDT.H_ratio", "v2": "BTCUSDT.H_const"}]],
["BTCUSDT.H_high_signal", ["Max", {"variables": ["BTCOFQ0.K_BTCUSDT.H_bt0_basispts", "BTCOFQ0.K_BTCUSDT.H_bt1_basis"]}]],
["BTCUSDT.H_low_signal", ["Min", {"variables": ["BTCOFQ0.K_BTCUSDT.H_bt0_basispts", "BTCOFQ0.K_BTCUSDT.H_bt1_basis"]}]],
["SELL_UP", ["GreaterThan", {"v1": "RGAP_SBBA", "v2": "UP"}]],
["BUY_DOWN", ["LessThan", {"v1": "RGAP_BBSA", "v2": "DOWN"}]]
]
Variables Overview:
Class | Description |
---|---|
BookReturn | return between book-weighted price and a reference price (e.g. MidPx) |
PriceVar | Variable value comes from price. |
Ratio | Calculates the ratio of two variables. |
VarEma | Calculate the value of ema. |
VarStd2 | Calculate the value of the standard deviation. |
Sum | Takes multiple variables as an input, and sums up its values. |
And | Performs “AND” operation on multiple variable. |
Sub | Takes two variables as an input and subtracts them together. |
Add | Takes two variables as an input and adds them together. |
Div | Takes two variables as an input and divide them together. |
Mul | Takes two variables as an input and multiply them together. |
Scale | Takes an input coefficient and variable and scales the variable by the coefficient. |
Max | Get max value on multiple variable. |
Min | Get min value on multiple variable. |
Mean | Calculates the mean values of a host of variable values. |
GreaterThan | Compare the values of two parameters. |
LessThan | Compare the values of two parameters. |
Or | Performs “OR” operation on multiple variable. |
NotZero | Checks if the variable equals zero. |
Not | Performs “NOT” operation on multiple variable. |
NormGT | For any two variables, it checks if the absolute value of one variable is greater than than absolute value of the other variable. |
SameSign | checks if the sign of two variables are the same. |
Const | Takes in a constant as an input. |
TopN | Calculates the average top N variable values. |
Median | Calculates the median values of a host of variable values. |
MinC | Takes in a variable and a constant as an input, and calculates the minimum of the two. |
MaxC | Takes in a variable and a constant as an input, and calculates the maximum of the two. |
Bollinger | For a given trend alpha and a threshold value, this indicator checks if the ratio of(trend_value)/(stdev(trend_value)) is above or below the threshold, if above value = +1, if below value=-1, else value = value. |
LevelPrice | Takes in a referenced pricing model and side, calculates the price at the level that is level_cap levels below the best price. |
Trend | Takes in as an input the pricing model and the sampler parameters, and computes the exponential moving average for the pricing model. |
Volatility | Computes the Standard deviation of the EMA of the trend. |
HighLow | For a given pricing model and a sampler, computes the high, low, total returns, high-low range, and min(last - low,high- last) for a given number of bars. |
ReturnFromMid | Take a pricing model and a mid pricing model as inputs and computes the return between them. |
ReturnBetweenPrices | Take a pricing model and a base pricing model as inputs and computes the return between them. |
| | More variables will be shipped in QuantLib soon. |
Variables Details:
PriceVar
Variable value comes from price.
Field | Description | Mandatory |
---|---|---|
pm | A price variable derived from pricing_models. | Yes |
Ratio
Calculates the ratio of two variables.
Field | Description | Mandatory |
---|---|---|
v1 | The molecular part of the ratio. | Yes |
v2 | The denominator part of the ratio. | Yes |
VarEma
Calculate the value of ema.
Field | Description | Mandatory |
---|---|---|
variable | The variable used to calculate the exponential moving average. | Yes |
sampler | Decay parameters when calculating ema. | Yes |
VarStd2
Calculate the value of the standard deviation.
Field | Description | Mandatory |
---|---|---|
variable | variable used to calculate standard deviation. | Yes |
init_var_value | initial variable used to calculate standard deviation. | Yes |
init_std_value | initial std used to calculate standard deviation. | Yes |
Add
Takes two variables as an input and adds them together.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | Two parameters that need to be added. | Yes |
Sub
Takes two variables as an input and subtracts them together.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | Two parameters to be subtracted. | Yes |
Mul
Takes two variables as an input and multiplies them together.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | Two parameters to be multiplied. | Yes |
Div
Takes two variables as an input and divides them together.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | Two parameters to be divided. | Yes |
Scale
Takes an input coefficient and variable and scales the variable by the coefficient.
Field | Description | Mandatory |
---|---|---|
coef | Store a constant value. | Yes |
variable | User defined variable. | Yes |
Max
Get max value on multiple variable.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
Min
Get min value on multiple variable.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
Mean
Calculates the mean values of a host of variable values.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
GreaterThan
Compare the values of two parameters.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | is v1 greater than v2. | Yes |
LessThan
Compare the values of two parameters.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | is v1 less than v2. | Yes |
Or
Performs “OR” operation on multiple variable.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
Not
Performs “NOT” operation on multiple variable.
Field | Description | Mandatory |
---|---|---|
variable | User defined variable. | Yes |
NotZero
Checks if the variable equals zero.
Field | Description | Mandatory |
---|---|---|
variable | User defined variable. | Yes |
NormGT
For any two variables, it checks if the absolute value of one variable is greater than than absolute value of the other variable.
Field | Description | Mandatory |
---|---|---|
v1 & v2 | Two parameters that need to be added. | Yes |
Const
Takes in a constant as an input.
Field | Description | Mandatory |
---|---|---|
value | Store a constant value. | Yes |
TopN
Calculates the average top N variable values.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
Median
Calculates the median values of a host of variable values.
Field | Description | Mandatory |
---|---|---|
variables | Store the list of variables to be compared. | Yes |
MinC
Takes in a variable and a constant as an input, and calculates the minimum of the two.
Field | Description | Mandatory |
---|---|---|
variable | User define variable. | Yes |
Const | Store a constant value. | Yes |
MaxC
Takes in a variable and a constant as an input, and calculates the maximum of the two.
Field | Description | Mandatory |
---|---|---|
variable | User define variable. | Yes |
Const | Store a constant value. | Yes |
Bollinger
For a given trend alpha and a threshold value, this indicator checks if the ratio of(trend_value)/(stdev(trend_value)) is above or below the threshold, if above value = +1, if below value=-1, else value = value
Field | Description | Mandatory |
---|---|---|
trend | User defined trend method. | Yes |
stdev_sampler | The type of data sampling method. | Yes |
default_stdev | Initial standard deviation. | Yes |
cutoff | Threshold cutoff. Default is 1 | No |
LevelPrice
Takes in a referenced pricing model and side, calculates the price at the level that is level_cap levels below the best price.
Field | Description | Mandatory |
---|---|---|
ref_pm | User defined referenced pricing method. | Yes |
side | 1 for BUY and 2 for SELL side. Default is 1 | No |
level_cap | Level cap. Default is 5 | No |
Trend
Takes in as an input the pricing model and the sampler parameters, and computes the exponential moving average for the pricing model.
Field | Description | Mandatory |
---|---|---|
pm | User defined pricing method. | Yes |
base_pm | User defined pricing method to compute EMA. Default is pm | No |
sampler | The type of data sampling method. | Yes |
Volatility
Computes the Standard deviation of the EMA of the trend.
Field | Description | Mandatory |
---|---|---|
trend | User defined trend method. | Yes |
sampler | The type of data sampling method. | Yes |
HighLow
For a given pricing model and a sampler, computes the high, low, total returns, high-low range, and min(last - low,high- last) for a given number of bars.
Field | Description | Mandatory |
---|---|---|
pm | User defined pricing model. | Yes |
sampler | The type of data sampling method. | Yes |
num_bars | Number of bars | No |
output | Choose one of 5 output types: range, return, high, low, px_from where px_from is min(high-px, px-low). Default is range | No |
ReturnFromMid
Take a pricing model and a mid pricing model as inputs and computes the return between them.
Field | Description | Mandatory |
---|---|---|
pm | User defined pricing model. | Yes |
mid_pm | User defined mid pricing model. | Yes |
ReturnBetweenPrices
Take a pricing model and a base pricing model as inputs and computes the return between them.
Field | Description | Mandatory |
---|---|---|
pm | User defined pricing model. | Yes |
base_pm | User defined base pricing model. | Yes |
LinearSum
Multiplies the input variables by the weights; you can use this to store a linear model. Exactly one of the fields must be used.
Field | Description | Mandatory |
---|---|---|
variables | A list of dictionaries each containing the properties "weight" and "variable", where weight is a float and variable is the name of a variable. | No |
components | A list of tuples of the form (weight, variable) | No |
models
It contains models. A model is a value generated from one or more variables. Its value represents the predicted forward return and is used by ModelStrategy.
Models instances:
"models": [
["Zero_m", ["LinearModel", {"variable": "Zero"}]]
]
Models Overview:
Class | Description |
---|---|
LinearModel | It takes in a single variable as an argument, and assigns the signal to the strategy based on the value of the variable (additionally can also take trading_condition as an argument. |
More models will be shipped in QuantLib soon. |
Models Details:
LinearModel
It takes in a single variable as an argument, and assigns the signal to the strategy based on the value of the variable (additionally can also take trading_condition as an argument.
Field | Description | Mandatory |
---|---|---|
variable | The variable to pass through. | Yes |
trading_condition | A sampler. Trading only happens when there is a sample event. | No |
strategies
It contains strategies. A strategy implements the execution logic for trading a symbol. It is driven by time and market events, makes order placing/canceling decisions based on model value and other information.
Strategies common parameters:
Additional to the trading logic, the strategies component also provides a set of common parameters which help you better tune and manage your strategy such as order notional, order cooloff and etc. Below is a list with the explanation.
Field | Description | Mandatory |
---|---|---|
symbol | Symbol of strategies trading. | Yes |
trade_market | On which market the strategies trading. | Yes |
account | Which account does the strategy run in. | Yes |
risk_id | The strategy portfolio to which the strategy belongs, used to consolidate the calculated risk. Default is 0. | No |
order_notional | The max notional per order (post only). Default is max_notional/5. | No |
ioc_notional | The max notional per order (ioc). Default is max_notional/5. | No |
max_notional | The allowed max notional per symbol. Default is 1000000. | No |
max_portfolio_notional | The allowed max notional per account. Default is -1. | No |
max_risk | The maximum notional value at risk of strategic portfolio exposure. Default is 1000000. | No |
cooloff | Time invterval for placing order. Default is 0. | No |
use_margin | Whether it is margin trading. Default is False. | No |
margin_source | Margin mode, only works when use_margin is True. Default is isolated | No |
Strategies instances:
"strategies": [
["BTCUSDTSWAP.OKEX_SWAP", [
"SimpleTakerStrategy", {
"symbol": "BTCUSDTSWAP",
"trade_market": "OKEX_SWAP",
"order_size": 0.0001,
"signal": "BTCUSDTSWAP.OKEX_SWAP_trend30"
}]],
["BTCUSDT.BINANCE", [
"CCSimpleMakerStrategy", {
"symbol": "BTCUSDT",
"trade_market": "BINANCE",
"account": 10001,
"model": "BTCUSDT.BINANCE_m",
"make_mid_pm": "BTCUSDT.BINANCE_midpx",
"use_bps_thold": true,
"make_thold": 1,
"order_notional": 2000,
"max_notional": 2000
}]]
["Arb01", [
"Arb1Strategy", {
"symbol": "BSVUSDTSWAP",
"trade_market": "OKEX_SWAP",
"risk_id":0,
"use_margin": true,
"account": 10001,
"model": "model_a",
"rbda": "RM_BDA",
"sell_up": "SELL_UP",
"buy_down": "BUY_DOWN",
"order_notional": 100,
"max_notional": 1000,
"max_risk": 500
}]],
["Arb02", [
"Arb2Strategy", {
"symbol": "BSVUSDSWAP",
"trade_market": "OKEX_SWAP",
"risk_id":0,
"use_margin": true,
"account": 10001,
"model": "model_a",
"max_notional": 1000,
"max_risk": 500
}]]
]
strategies Overview:
Class | Description |
---|---|
CCEventMakerStrategy | A simple maker strategy placing making orders based on buy/sell commands. |
CCSimpleMakerStrategy | A simple maker strategy quoting making orders on both sides based on signal. |
Arb1Strategy | The front leg strategy part of the arbitrage strategy. |
Arb2Strategy | The Back Leg Strategy Part of the Arbitrage Strategy. |
Strategies will be shipped in QuantLib soon. |
strategies Details:
CCEventMakerStrategy:
A simple maker strategy placing making orders based on command from python script.
Field | Description | Mandatory |
---|---|---|
symbol | symbol of strategies trading. | Yes |
trade_market | on which market the strategies trading. | Yes |
order_size | the order size on each order. | Yes |
signal | the signal where the stratigies used. | Yes |
CCSimpleMakerStrategy:
A simple maker strategy quoting maker orders on both sides based on signal. Default signal is 0. This strategy allowes the user to specify a model, or combines the variable set to generate signal, such as LinearModel.
Field | Description | Mandatory |
---|---|---|
symbol | symbol of strategies trading. | Yes |
trade_market | on which market the strategies trading. | Yes |
max_notional | the max allowed position notional. Default is 1000000. | No |
order_notional | the order notional on each order. Default is max_notional/5. | No |
quote_spread_bps | quote based on spread. Default is 5. | No |
max_quote_error_bps | the allowed error between quote price and order price. Default is 1. | No |
max_quote_signal_diff_bps | the allowed error between signal price and order price. | No |
model | user defined model which generates signal. | No |
use_bps_thold | whether to use bps to express threshold, i.e. True: threshold = make_thold * 0.0001, False: threhsold = make_thold * tick_size / midpx. Default is False. | No |
make_thold | how far you place a maker order from fair value. Default is 100000. | No |
make_mid_pm | user defined mid pricing model which will be used as mid price for quoting. | Yes |
Arb1Strategy:
The front leg strategy part of the arbitrage strategy.
Field | Description | Mandatory |
---|---|---|
symbol | symbol of strategies trading. | Yes |
trade_market | on which market the strategies trading. | Yes |
risk_id | The strategy portfolio to which the strategy belongs, used to consolidate the calculated risk. | Yes |
use_margin | Whether it is margin trading. | Yes |
account | Which account does the strategy run in. | Yes |
rbda | Signal direction, current main direction is buy or sell. | Yes |
sell_up | sell signal. | Yes |
buy_down | buy signal. | Yes |
order_notional | the max notional per order. | Yes |
max_notional | Notional value of the largest held position. | Yes |
max_risk | The maximum notional value at risk of strategic portfolio exposure. | Yes |
Arb2Strategy:
The Back leg strategy part of the arbitrage strategy.
Field | Description | Mandatory |
---|---|---|
symbol | symbol of strategies trading. | Yes |
trade_market | on which market the strategies trading. | Yes |
risk_id | The strategy portfolio to which the strategy belongs, used to consolidate the calculated risk. | Yes |
use_margin | Whether it is margin trading. | Yes |
account | Which account does the strategy run in. | Yes |
max_notional | Notional value of the largest held position. | Yes |
max_risk | The maximum notional value at risk of strategic portfolio exposure. | Yes |