16 Nov 2024

Arbitrage In DEFI (p2)

As mentioned in my prior post Arbitrage in DEFI (p1), have been building and improving a MEV strategy in DEFI to perform both atomic and non-atomic arbitrage, backrunning, liquidations, etc. In this article we continue to focus on algorithms to detect and optimise arbitrage paths through the pool graph.

Let us consider a simple graph of possible flows between 6 pools:

Bute-force approach (for small graphs)

For smaller graphs, we can avoid evaluating a complex...

11 Nov 2024

Arbitrage In DEFI (p1)

I have been building and improving a MEV strategy in DEFI to perform both atomic and non-atomic arbitrage, backrunning, liquidations, etc. In this post will focus on one of the hard algorithmic problems, namely, determining the optimal size and path of arbitrage through swap pools and other protocols.

On Ethereum, for example, there are ~700K ERC20 tokens and a few hundred thousand AMM pools (fortunately only a fraction of these pools and tokens are active). We can consider the possible...

01 Sep 2021

New Crypto Strategy

I have a new stat/arb strategy in crypto that uses an adaptive state based system to identify MR opportunities on small portfolios of coins. I have identified ~1600 such portfolios across 200 coins, each of which is traded as a strategy. In practice I trade a portfolio of these strategies (which I term, “stratlets”), where the strategy is defined as a dynamically weighted portfolio of these stratlets.

Setup

While each stratlet is adaptive, adjusting internal parameters over time, there...

20 Aug 2021

Crypto Trading Depth

I have a collection of crypto stat/arb strategies I plan to trade as a portfolio of strategies. Each strategy trades a small mean-reversion portfolio of loosely cointegrated coins, based on a bayesian state-based model. The returns in cryptos for this sort of strategy are phenomenal, however, finding enough size can be difficult for some coin portfolios.

In my universe of roughly 220 coins, there is significant variation in liquidity, requiring that I size these strategy portfolios very differently depending on...

28 Jul 2021

Pricing Deribit Options

We have been working on some option strategies and wanted to get a sense of how well BTC and ETH options are priced on Deribit, i.e. is there a substantial IV premium over realized volatility or are options fairly priced. At first glance, based on the documentation, it seemed that Deribit options were Europeans on spot or spot equivalent. On closer inspection, however, and with some follow-ups with deribit, determined that this is actually a much more complex product (to...

12 May 2021

Learning Candlestick Patterns

In the previous posts I described an Reinforcement Learning approach to “Learning the Exit” part 1, part 2. My initial conclusions there have been:

  • reward smoothing (with the labeler) leads to more robust results than a reward on position exit
    • without smoothing the learning process struggled and had more volatility from epoch to epoch
    • obtained the best results with smoothed reward
  • obtained better results with discrete actions (such as enter, hold, exit) rather than...
26 Apr 2021

Learning the Exit (part 2)

As described in my prior post Learning the Exit (part 1), I have a model that indicates mean reversion entries with ~81% accuracy, however I did not have a good approach in handling the exit. While 81% of MR signals had a minimum profit of 25% (of prior amplitude), the mean profit available was 150%, pointing to a larger profit opportunity to be had if can better handle the exit.

I have found it very difficult to predict the...

26 Apr 2021

Learning the Exit (part 1)

I have a model that indicates mean reversion with ~81% accuracy. Here is an example of a MR scenario the model identified:

The strategy is very good at detecting entry points (usually very close to optimal), however is fairly crude in terms of how it determines the exit. Given that 81% of MR (with this model) experiences a profit of at least 25% of the prior amplitude, one could take the approach of waiting for...

12 Apr 2021

Uniswap v3 & Liquidity Provision

I had a look at Uniswap’s upcoming V3 protocol overview and white paper. There are some substantial improvements above the current V2, such as:

  • ability to offer “concentrated” liquidity (we’ll discuss this below)
  • ability to introduce pools with varying fee structure
  • advances in oracle efficiency and new oracle types
  • ..

For a market maker, the most important of these is the ability to “concentrate” liquidity. What does this mean? As of V2, one’s liquidity was uniformly...

09 Jan 2021

Stable Coin Minting & Momentum

A friend of mine (thanks Adal) suggested that I look at other stable coins, again observing the relationship between coin issuance and momentum. Given that Circle (USDC) and Binance coin (BUSD) are widely traded, focused on these two coins.

Binance coin is newer than Circle, so I only have history for BUSD from late 2019. However, will compare the signal from these coins for events in 2020.

2020 Covid Bounce

Here is the combined signal for USDC and BUSD...

08 Jan 2021

Tether Minting & Momentum

Tether started as a stable coin with a purported 1:1 backing of USD initially (though at this point we know that Tether is only fractionally backed). It is a defacto fiat currency, with fractional reserves. For better or worse Tether (the company) acts as a central bank of sorts, as appears to have intervened in the market numerous times: for example evidence points to Tether propping up momentum during the 2017 bubble.

Since Tether (USDT) is effectively fiat, new USDT...

24 Dec 2020

New Equities Strategy (p2)

In the prior post I showed results for a new equities strategy which uses a combination of signals to create and risk manage a high-momentum portfolio. Further investigation revealed that I had neglected on a couple of fronts:

  • failed to account for dividends (which are substantial)
  • some data issues
  • improper sharpe calculation

The good news is that solving these issues substantially improved the profitability of the strategy (which was already high return for a low-freq strategy).

20 Dec 2020

New Equities Strategy

Given that I am busy with higher-frequency strategies generally, thought should find a longer-term portfolio strategy that could apply systematically at low-frequency for my passive funds. Momentum seems to have been a dominant force in the equities market for the last 20 years or so, with relatively short bear or drawdown interludes. I have no illusions that market behavior will remain the same, however the following continue to weigh in favor of momentum strategies in equities, IMO:

  • money searching...
19 Dec 2020

Bitcoin Mempool & Momentum

I have been thinking about the recent institutional buying that has propelled the price of bitcoin to stratospheric levels; in particular considering how one might detect some of this interest early. Bitcoin and crypto, in general, is quite interesting in that due to the decentralized ledger, there is more transparency in this market than any other financial market.

The majority of transactions, at this point, occur off chain on exchanges. However, if one wanted to buy into a large position,...

28 Nov 2020

Analyst Ratings → Return Prediction

I have a couple of equities strategies that I will start trading shortly, and I want to understand the risk from all angles. Towards this end I try to utilize both market signals and exogenous unstructured data to minimize surprise and maximize selection or prediction efficiency. In thinking about single name risks (i.e. the risk associated with selecting and trading a particular stock), I wanted to examine is if there is any signal or risk measure I could derive from...

25 Nov 2020

Thoughts on Crypto Market Making

In the past have been a HFT market maker for FX and other traditional instruments, however have not investigated exchange-based market making in Crypto. As I have proprietary signals applicable for Crypto, thought it would be worthwhile to investigate the difficulty of market making on crypto exchanges.

The crypto ecosystem and microstructure is quite different from FX and equities in the following ways:

  • extremely high transaction costs on many exchanges
    • for example the US spot exchanges charge out...
01 Sep 2020

Denoising a signal with HMM

Most signals I deal with are noisy, reflecting noise of underlying prices, volume, vol of vol, etc. Many traditional strategies built on such indicators might either:

  • use signal to scale into position
    • such approaches have to deal with noise to avoid thrashing, adjusting position up and down with noise
  • consider specific levels of the signal to signify a state
    • for example: long {+1}, short {-1}, neutral {0}

Pictured below is an example...

15 Aug 2020

Feature Selection (3 / 3)

In the prior two posts, investigated:

In this post will evaluate feature importance as implemented by Random Forest and compare to Information Geometric approaches. Here is an outline of what would like to discuss:

  • similarities between Decision Trees and Information Geometric approaches for feature selection
  • some of the deficiencies of Decision Trees
  • some areas for improvements

As we will see, Random Forest’s approach to...

14 Aug 2020

Feature Selection (2 / 3)

As mentioned in the prior discussion feature selection (1/3), of primary interest is understanding the contribution of each feature in \(\vec{x}\) to the outcome or class labeling function \(f(\vec{x})\). One way to examine this is to understand how the distributions:

  • \(p(x_f)\), the probability distribution of feature f (without regard to label)
  • \(p(x_f\, \vert\, f(x) = y)\), the feature distribution conditional on class label

differ from each other. For a feature with no relationship to the outcome \(p(x_f)\)...

13 Aug 2020

Feature Selection (1 / 3)

I am often confronted with the problem of trying to reduce a high dimensional feature set to a, smaller, more effective one. Reducing dimension is important for machine learning models as:

  • the volume of the “search space” grows exponentially
    • at a minimum rate of \(2^{d}\) for binary categorical variables to a much higher exponential for continuous or n-ary categoricals.
  • the joint-distribution of high dimensional empirical spaces tends to be sparse and ill-defined
    • empirical distributions require...
03 Aug 2020

Buy / Sell Imbalance

Problem

It is fairly easy to recognize price momentum with price-based indicators ex-post or with lag. Price based momentum signals tend to have lag issues in recognizing the start and end of a price move as there is a tradeoff between noise and lag [1] that can’t be defeated without future information (due to principles from signal processing).

[1] For those interested see impulse-response and the relationship between response delay and degree of smoothing by a filter. Zero lag...

30 Jul 2020

Why ML → Finance is Hard (3 / 4)

Following on from the prior post, want to discuss the problem of sample independence. Many machine learning models in finance deal with timeseries data, where samples used in training may be close together in time and not be independent of one another. There are very few features in finance that do not make use of lookback periods. Most features do evaluate prior windows:

  • almost all technical indicators (SMA being the most basic example)
  • distribution based signals
  • decomposition based...
27 Jul 2020

Why ML → Finance is Hard (2 / 4)

Following on from the prior post, want to discuss the repercussions of the low signal / noise ratio and how it effects:

  • labeling / mis-labeling
  • patterns unsupported by features

How does this manifest and what might we do to ameliorate the issues it poses.

Introduction

Financial timeseries appear to have a very low signal to noise ratio, where the variance (the power of the noise frequency) can be higher than the power of the overall signal....

27 Jul 2020

Why ML → Finance is Hard (1/4)

I have used machine learning in trading strategies over the past 10 years or so. However my use of ML has often played a relatively small role in the overall design and success of the strategies due to issues particular to financial data sets. I tend to use ML in specific signals or strategy sub-problems where the data / problem setup have attributes that lead to a robust statistical solution. This is as opposed to the “Nirvana” scenario where fundamental...

11 Jul 2020

Labeling Momentum & Trends

There are times when need to label a time series, identifying periods of momentum, trend, mean-reversion, etc. Directionaly labeling timeseries has a wide variety of applications:

  • labels can be used for supervised learning
  • analysis of microstructure around larger price moves
  • conditional analysis using label (pattern) sequences
  • testing online signals versus idealized ex-post labeled trend / momentum or MR targets

The Problem

The naive approach to labeling might just note the sign of individual returns in a series....

09 Dec 2017

Bitcoin Valuation Fundamentals

Bitcoin has entered the mainstream, though not in a way that is particularly useful. Many, including myself, are calling a bubble in Bitcoin. As with many bubbles when the “mom and pops” and non-professional investors get into a buying frenzy, historically this has been associated with the last stages of a bubble. Momentum from individual buying may persist for some time, potentially in cycles of buying dips, so would not want to get short, without a strong view on sentiment...

29 Oct 2017

Information In Volatility Structure [2]

In the prior post Information In Volatility Structure [1] applied the SABR model to fit noisy raw option price data of approximatelty 700 million prices across a 10 year history of 2700 stocks. The point was to examine a hypothesis:

  • does supply / demand imbalance in the options market express in terms of abnormal vol skew?
  • can abnormal vol skew point to forward market behavior?

First Application

I started by observing both put/call skew and skew...

02 Oct 2017

Roll Your Own RoboAdvisor [1]

I have two pools of capital, one for active trading and another for long-term investment / lower-risk capital preservation. I go through phases of actively managing investment capital and then phases where become too busy to do so properly. It would be convenient to hand off the management to one or more funds, invest and forget, but given the market uncertainties and what I know about wall street, trust is hard to come by. Indeed since the financial crisis, Hedge...

24 Sep 2017

Information In Volatility Structure [1]

I’ve developed signals based on the “spot” market, but had not really explored the options market as a source of information. In particular want to look at discrepancies in option demand / pricing that may relate to future returns or risk. In scenarios where there is an expected dislocation in price, there may be more demand for calls vs puts or vice-versa. Buying pressure on puts or calls will tend to impact the option price (and therefore implied vol), much...

02 May 2015

Market-Making Portfolio & Hedging

With market making we can try to be neutral by skewing prices in such a way as to maintain a neutral position.   To the extent that the market can become 1-sided (in momentum) or may have large sized requests (if offering at different sizes), one’s portfolio may require explicit hedging.

In a live market-making scenario we can determine how we want to hedge on a case-by-case basis and with a view on where it is cheapest to achieve the...

29 Mar 2015

Bitcoin, In its own Universe?

Investors are often looking for uncorrelated returns so as to better diversify.   If one looks at world indices &  equities, there is much less diversity between assets than there was a decade ago, indeed the cross-market correlations are remarkably high.

On the other hand, from a trading perspective, generally want to be able to reduce the risk by hedging or spreading against related assets.   For example in FX, when market making the G10 currencies, one typically offsets inventory risk with...

14 Mar 2015

Musings on HFT in Bitcoin

I have 4 Bitcoin L3 exchange feeds running smoothly out of a data center in California (which is slightly closer to Asian exchanges and Coinbase than the east coast).  It took a bit of error handling and exponential back-off, to handle the unreliability of connectivity with these exchanges, where connections can intermittently be overwhelmed (returning 502 / 503 errors due to the poor choice of a REST-based API).

I am thinking to add Bitstamp and Kraken to the mix, even though they are...

11 Feb 2015

Bitcoin: Needs Cross-Exchange "Prime Brokerage"

Ok, what I am going to say here is probably Bitcoin heresy, in that I am going to advocate more centralized clearing and management of assets wrt exchange trading.

I want to be able to scale trading in bitcoin and execute across multiple exchanges.  However have the following problems

  • lack of trust in (most) of the bitcoin exchanges
    • security of the exchange against attackers
    • degree of trust in the ownership re: my assets on deposit
  • inability to...
10 Feb 2015

Bitcoin L3 Feeds: Status

I have implemented 4 bitcoin exchange interfaces now that produce a live L3 stream of orderbook updates + trades of the form:

Messages

Given the above, can reconstitute the orderbook as it moves through time, and can likewise be used to create BBO quotes and bars of different granularities.   The status of the exchange implementations is:

Status

I am looking to run this on a remote machine (preferably linux) and write to an efficient...

08 Feb 2015

Bitcoin Exchanges: State of the Market

In the previous post outlined intention to put together high quality L2/L3 feeds for the top 4-5 bitcoin exchanges, collect L3 data, and provide a consolidated live orderbook for trading.   So far have implemented OKCoin and been experimenting with the others to determine their API capabilities.

With the exception of OKCoin, what I’ve found so far is not good.  Here is a summary of the top-4 exchanges w/ respect to market data APIs (I also included Coinbase with the notion will...

28 Jan 2015

Consolidated Source of Data for Bitcoin

It seems like every other month there is a new bitcoin exchange.  For the purposes of trading research & backtesting it is important to have historical data across the most liquid exchanges.  My minimal list is:

  1. BTC/USD
    1. bitfinex (15%)
    2. bitstamp (5%)
    3. coinbase (new, but likely to garner market share)
  2. BTC/CNY
    1. okcoin (28%)
    2. btcn (44%)

(percentage volume sourced from http://bitcoincharts.com/charts/volumepie/).   Each of these exchanges not only has a unique protocol but also unique...

13 Dec 2014

Thompson Sampling

I recently attended a talk by David Simchi-Levi of MIT, where he discussed an approach to online price discovery for inventory, to maximize some objective, such as profit.   The scenario was where one could observe whether inventory was sold or not-sold to for each potential buyer in the marketplace, giving an empirical view of demand-behavior as a function of price.   The optimal setting in selling the inventory is one that  maximizes price x liquidation probability.

When we have no knowledge about the...

29 Sep 2012

Money Management

It has been almost a year since my last post.  I have been far too busy getting a new trading desk up and running.   I  thought to discuss money management, since am revisiting right now.

Overview

It is easy to think that trading signal is the most important aspect of a trading strategy, but money management (and execution) can be even more important.   Loosely defined, money management is a mechanism for position-level risk management.  The mechanism attempts...