Top Mobile Framework for App Development

In this article we will talk about one of our favorite device the smart phone. The very device that we can’t like it up. For many including me our entire lives are summed up in to this little device…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A Quantamental Approach to Trading BTC

Using novel network data to understand changes in BTC fundamentals.

Value investing can often be cringy. While not normally the word associated with value investing, there has been a sullying of the term by self-appointed “investing gurus” offering hollow advice after reading a few articles about Warren Buffet’s knockout investments — bonus points for quoting Benjamin Graham and referring to “those quants” with disdain. Unfortunately, this has given the investment methodology an unfair image as primitive, unsophisticated, and outgunned by more modern trading methodologies.

This could not be further from the truth. Value investing requires deep domain specific knowledge of a company’s business and a clear understanding of the metrics required to track a company. Here I am specifically using words that are more normally associated with quantitative trading because, ultimately, I would like to show that it’s all the same under different jargon. Indeed, when we consider something like PE Ratio (price-to-earnings ratio), all that we are doing is feature engineering considering no company publishes their PE ratio in their balance sheet. This does, however, extend to metrics that companies do publish, such as EBITDA. Value investing can be and is as data intensive as any other form of quantitative investment.

Unfortunately, many value investors have rejected cryptocurrencies and Bitcoin in particular as fraudulent and the fabrication of Internet dorks. Further, some of these investors proudly remain ignorant to the underlying value of asset by quoting Buffet as the basis of a “never invest in what you don’t understand” — ignoring the better half of that proclamation where Buffet explained that “I had plenty of ways to ask questions or anything of the sort and educate myself, but I blew it” with regards to a missed opportunity to invest in Google. There are always fundamentals in a market, you just have to be creative when looking for them.

To fit Bitcoin into a framework for value investing we have to consider the type of data we can acquire on Bitcoin. With the right type of data, we can construct a model, which can help us understand if Bitcoin is trading rich or cheap — this type of assessment can be done with a relative value model.

Many of the BTC algos that I come across are focused on implementing traditional technical indicators with varying degrees of accuracy. One thing I have noticed amongst these algos is that they tend to focus on shorter trading horizons with the majority being intraday trading on hourly horizons. I wanted to generate signals using daily data for three main reasons:

1. For a relatively passive trading system, I did not want to focus on data quality and latency. Even getting a BTC price series to model against on an intraday basis can be tough as the prices can have impactful variations from exchange to exchange. This is not to say that data quality is not important — it very much is — but on slower trading horizons aberrations in data quality are not as ruinous.

2. I did not want to build new infrastructure and execution engines.

3. I wanted to use this as a way to hedge some volatility in my BTC holdings. The way I envisioned this working was I have some stack of BTC, which I am consistently adding to. The algorithm would allow me to pick decent entry points as well as some decent exit points where I could trim 25–50% of my holdings in order to “smooth” out my PnL. This also gives me the opportunity to consider additional signals — perhaps I hear some interesting news or decide to trim after a large rally in order to lock in gains. A good portfolio is rarely just one algo and these “other signals” are basically algos of sorts.

Earlier this year, I read another medium piece, which introduced me to a unique data set to work with: Coinmetrics. The piece itself (How I Predicted Bitcoin’s Biggest Breakout in 2019) was the inspiration behind building this model.

Coinmetrics provides network-level data on BTC and other cryptocurrencies. I have no affiliation with the product but I enjoyed working with their free data and after meeting the team and discussing their data in depth. In particular, I was motivated to build using their data after I found the following charts by playing around with the charting tool on their website:

BTC Price (USD) vs. Mean Network Transfer Value
BTC Price (USD) vs. Adjusted Mean Network Transfer Value

I put together the following script to pull down the free version of their data:

As I try to stay up to date on what little detailed Bitcoin analysis there is, I recognize some of these features but many of these are new to me. Given that, the way I wanted to proceed was to let my model determine the most important features for any rolling window of data. To keep things simple, I cleaned out the missing data points with some drop.na’s and set up a ridge regression.

Before we continue, let’s examine the use of ridge regression for this problem. In my experience, for forecasting financial data — specifically financial time series — regressions tend to have dependable accuracy and computational efficiency. As mentioned in previous posts, I have had much more success in increasing model performance by contextually cleansing data than tuning models. Also, regressions offer easily explainable solutions and allow us to consider which features are drivers of price/return. This further allows us to articulate our pre-trade thesis as something of the form: “I believe BTC is rich/cheap because X, Y, Z facets of network data suggest and decrease/increase in BTC value.” It is a way of judging the BTC economy by proxy.

With regressions, we have a number of options. Given the density of the data we have, I wanted to consider my options between a Lasso and ridge regression. In my experience, ridge regressions have tended to work better than Lasso regressions for this type of forecasting. In general, when running a regression we are applying weights to each of our features. In the case of ridge regressions, we minimize the coefficients of our features that are deemed irrelevant — we don’t drive the coefficients to 0 (that would be Lasso regression) but by lowering the coefficient we are limiting the impact of that feature on our prediction. For ridge regressions, we minimize the squares of the residuals — the error between predicted and actual — but in Lasso, we minimize their absolute value. In linear algebra terms, a ridge regression minimizes the l2 norm and a Lasso regression minimizes the l1 norm. Stepping away from the math and considering the motivation of these two methods, a ridge regression will tend to keep residuals tighter allowing for more consistent signals (and by definition, returns) where as a Lasso tends to give more 0-error terms but have more variability in signals. As a result, algorithm returns tend to be less stable for this kind of application and ultimately don’t have the consistent profitability of signals from a ridge regression. Because Lasso forces coefficients to 0, one would believe they would work better on a data set such as the CoinMetrics one given the breadth of features. Indeed, Lasso’s are a great first choice for modeling data sets with large number of features. However, we have enough contextual understanding of the data to know that most if not all these features represent something important in the BTC economy — as such we don’t want to remove them all together. A more thorough treatment of ridge vs. lasso is outside the scope of this post but if it is something of interest, I can dive deeper into the details in a future post.

In the code below, we split the data into a y vector with BTC price in USD and the remaining features into a data frame of x vectors. When I first wrote it, the ridge threw a few errors and after some time debugging I found that there were some weird values in features causing the code to fail. Surprisingly dropping infs and nans did not fix the problem so I removed those columns all together. This is why I have my x features explicitly labeled out. There are probably smarter ways of dealing with this issue than throwing away potentially useful data but that seemed like a boring undertaking at the time and is relatively easy to check.

We run our ridge on a rolling 250-day window (representing one trading year in traditional assets). This window along with the alpha term (set at 0.1 as default) are parameters that can be tuned using separate functions or can be tweaked manually to get a better understanding of the data. While it is interesting to mess around to find the number that leads to the highest return — remember that is introducing a potentially overfit parameter into a production model.

The following chart shows the coefficients of the features and gives us an idea of their importance:

After running a somewhat detailed backtest we can asses the following results”

The results of this model are modest but are promising enough to make this data set worth exploring further. In particular, we note that an average 40% annual return would be phenomenal for a portion of our BTC portfolio despite being small compared to potential BTC returns. We knew this and aimed for this going in. The drawdown is still higher than we would like but our Sharpe's are generally interesting. Looking at average return by year, we note that in down years such as 2018 our model is insulated from the more dramatic drawdowns the market took as a whole.

Tuning and optimizing machine learning models requires work, patience, and tying it back to our opening comments: domain specific knowledge. Yes, I’m aware that the dream ML system would not need the last one but until then it makes everything a lot easier.

This post was tough to put together. It took me a while because for the most part the end never seemed in sight. As I built more and dove into the data more I just felt that there was more and more to explain as I learned so much trying to detail the data acquisition, model building, and model tweaking process.

Disclaimer:

None of the above is investment advice. Should you choose to build models to trade BTC or other digital assets, know that they are high-risk assets and can lead to negative effects including but not limited to sleep loss, financial ruin, and turning into John Macafee on full moons.

Add a comment

Related posts:

Mining More Detailed. 3. Mining Reward Race

We have already explained the process of crypto mining and described what tasks full nodes perform. Now it’s time to talk about a mining reward. The mining process happens all the time. Many full…

Branding Your Data Visualizations Using Matplotlib

Just as companies will only use certain shades of colors and types of shapes in their images to create a unique brand image. You too can create your own personalized brand of data visualizations…