.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fraud/manipulation/plot_01_willy_bot_price_manipulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_fraud_manipulation_plot_01_willy_bot_price_manipulation.py: Gandal et al.: price manipulation in the Bitcoin ecosystem, the Willy bot (2018) ================================================================================ Between February and November 2013, two accounts on Mt. Gox, later dubbed the Markus and Willy bots, bought about 600,000 bitcoins without paying for them: the exchange credited them with dollars it did not have. Over the same months the price of bitcoin rose from about 150 to over 1,000 dollars. Gandal, Hamrick, Moore and Oberman compared the price change on the days the bots traded with the other days and found it rose about 4% a day on the former and fell slightly on the latter. In a thin market, buying moves the price: with Kyle's linear impact :math:`\lambda`, .. math:: \log p_{t+1} = \log p_t + \lambda q_t + \sigma \varepsilon_t , so a buyer of :math:`q_t` who need not pay raises the price at will, and the rise appears only on the days it trades. .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk from blockchainkit.fraud.visualizers import plot_price_spikes .. GENERATED FROM PYTHON SOURCE LINES 29-31 A year of trading, with a bot on one day in four ------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 31-53 .. code-block:: Python days = 300 bot_days = set(range(40, 260, 4)) run = bk.fraud.simulate_bot_market(days, bot_days, bot_volume=1.0, impact=0.04, seed=2013) honest = bk.fraud.simulate_bot_market(days, (), seed=2013) flagged, other = bk.fraud.return_by_activity(run.prices, run.flagged) print(f"mean daily return with the bot {flagged:+.2%}, without {other:+.2%}") print( f"price: {run.prices[0]:.0f} -> {run.prices[-1]:.0f}, without the bot {honest.prices[-1]:.0f}" ) assert flagged > 0.02 > abs(other) assert run.prices[-1] > 5 * honest.prices[-1] fig, ax = plt.subplots(figsize=(9, 4)) plot_price_spikes(run.prices, sorted(bot_days), ax=ax) ax.plot(honest.prices, color="#94a3b8", label="same noise, no bot") ax.set(xlabel="day", yscale="log", title="The rise happens on the bot's days") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/fraud/manipulation/images/sphx_glr_plot_01_willy_bot_price_manipulation_001.png :alt: The rise happens on the bot's days :srcset: /api/gallery/fraud/manipulation/images/sphx_glr_plot_01_willy_bot_price_manipulation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none mean daily return with the bot +5.27%, without -0.34% price: 100 -> 780, without the bot 72 .. GENERATED FROM PYTHON SOURCE LINES 54-60 Exercise -------- The comparison of returns on flagged and other days needs to know which days the bot traded. Gandal et al. had the leaked Mt. Gox trade records. What could an outsider who sees only the daily price and volume test instead, and why is it weaker? .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.053 seconds) .. _sphx_glr_download_api_gallery_fraud_manipulation_plot_01_willy_bot_price_manipulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/fraud/manipulation/plot_01_willy_bot_price_manipulation.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_willy_bot_price_manipulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_willy_bot_price_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_willy_bot_price_manipulation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_