Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

346 crypto mean reversion #347

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
In this strategy, we apply OLS and stationarity tests to construct a mean-reverting portfolio of Cryptocurrencies.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Mean Reversion Trading is the process of trading assets or relationships that deviate from the long-term mean in hopes that the prices revert to the long term mean. There are several methods and models to carry out mean reversion, including using Moving Average crossovers. Furthermore, <a href="https://www.investopedia.com/terms/p/pairstrade.asp">Pairs Trading</a> is simultaneously going long on one stock while shorting another, and it is a form of Mean Reversion as Pairs Trading is the process of going opposite of the direction of the spread in hopes that the spread will revert to the mean. In our <a href="https://www.quantconnect.com/tutorials/strategy-library/optimal-pairs-trading">Optimal Pairs Trading</a> strategy, we model the spread as an Ornstein-Uhlenbeck process to find the optimal levels to buy and sell the pair. However, Pairs Trading is a form of <a href="https://www.investopedia.com/terms/s/statisticalarbitrage.asp">Statistical Arbitrage</a>, so like all other forms of Arbitrage, the opportunity is whittled away as more participants employ the strategy. Thus, in this strategy, we extend the concept of Pairs Trading to more than two stocks; we construct a basket of several securities that we long and short in an attempt to create a mean-reverting portfolio. Specifically, we use Bitcoin (BTC), Bitcoin Cash (BCH), Ethereum (ETH), and Litecoin (LTC), four cryptocurrencies, for our portfolio.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>We first gather 100 points of historical closing prices for BTC, BCH, ETH, and LTC. Using OLS, we regress BTC prices (we label BTC as the <em>anchor</em> in the code) against BCH, ETH, and LTC prices to create the following regression equation:</p>

\[P_{BTC} = \alpha + \beta_{BCH}P_{BCH} + \beta_{ETH}P_{ETH} + \beta_{LTC}P_{LTC}\]

<p>Using this relationship, if we long 1 BTC, we take a position of -<em>&beta;</em>{BCH, ETH, LTC}. Let this scenario be called &ldquo;buying the portfolio&rdquo;. If we go short 1 BTC, we take a position of <em>&beta;</em>{BCH, ETH, LTC}. Let this scenario be called &ldquo;shorting the portfolio&rdquo;.</p>
<p>We then take the residuals of the OLS Regression and test them at the .05 significance level for both the augmented Dickey-Fuller and Phillips-Perron test. These are two different tests for stationarity, which helps us determine if the portfolio has mean-reverting qualities. If either test fails, we stop the trading.</p>
<p>To generate the rules of trading, we first compute the portfolio values of holding 1 BTC and -<em>&beta;</em>{BCH, ETH, LTC}, and from these portfolio values we compute the mean (&mu;) and the standard deviation (&sigma;). Then, if the value of the current portfolio trips below and then above &mu; - 1.5&sigma;, we buy the portfolio, and if the value of the current portfolio trips above and then below &mu; + 1.5&sigma;, we short the portfolio. Please note that the paper buys and sells the portfolio on the initial trips of the levels, however, we noticed that by waiting until the portfolio trips the levels the second time, we significantly reduce the drawdown and the losses.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="qc-embed-frame" style="display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;">
<div class="qc-embed-dummy" style="padding-top: 56.25%;"></div>
<div class="qc-embed-element" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;">
<iframe class="qc-embed-backtest" height="100%" width="100%" style="border: 1px solid #ccc; padding: 0; margin: 0;" src="https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_0718e73710b656d2ab33d0c46da5686b.html"></iframe>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>The algorithm achieved a Sharpe Ratio of 0.688 over approximately three years, while simply holding an equal weighting of BTC, BCH, ETH, and LTC would have achieved a Sharpe 0.12 over the same period.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ol>
<li>
Leung, T. and Nguyen, H. (2019), "Constructing cointegrated cryptocurrency portfolios for statistical arbitrage", Studies in Economics and Finance, Vol. 36 No. 3, pp. 581-599. <a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3235890">Online Copy</a>.
</li>
</ol>