<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maximilian Wimmer on Medium]]></title>
        <description><![CDATA[Stories by Maximilian Wimmer on Medium]]></description>
        <link>https://medium.com/@mw96?source=rss-6066c4ec5d4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*swnGwO7WwPv1c9tKzwXBzw.png</url>
            <title>Stories by Maximilian Wimmer on Medium</title>
            <link>https://medium.com/@mw96?source=rss-6066c4ec5d4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 22:17:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mw96/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Free Data-Pipeline for Quantitative Finance]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://mw96.medium.com/building-a-free-data-pipeline-for-quantitative-finance-973c28c78ff4?source=rss-6066c4ec5d4f------2"><img src="https://cdn-images-1.medium.com/max/2180/1*F5ViKp49Q-Ta1Q9HqPlAzQ.jpeg" width="2180"></a></p><p class="medium-feed-snippet">The Complete Workflow: Fetching, Processing, and Bundling Stooq Data for Zipline-Reloaded</p><p class="medium-feed-link"><a href="https://mw96.medium.com/building-a-free-data-pipeline-for-quantitative-finance-973c28c78ff4?source=rss-6066c4ec5d4f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://mw96.medium.com/building-a-free-data-pipeline-for-quantitative-finance-973c28c78ff4?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/973c28c78ff4</guid>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[quantitative-finance]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Thu, 02 Apr 2026 22:07:33 GMT</pubDate>
            <atom:updated>2026-04-17T16:16:42.991Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Level Up Your Zipline Backtests: Introducing the Sharadar DB Bundle]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://mw96.medium.com/supercharge-zipline-with-full-sharadar-data-introducing-the-sharadar-db-bundle-c8d3dd101730?source=rss-6066c4ec5d4f------2"><img src="https://cdn-images-1.medium.com/max/2600/1*4fm_1Ugp765xVRkrOg-QOA.png" width="3024"></a></p><p class="medium-feed-snippet">A guide to SQLite-based bundles, incremental updates, and point-in-time fundamentals.</p><p class="medium-feed-link"><a href="https://mw96.medium.com/supercharge-zipline-with-full-sharadar-data-introducing-the-sharadar-db-bundle-c8d3dd101730?source=rss-6066c4ec5d4f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://mw96.medium.com/supercharge-zipline-with-full-sharadar-data-introducing-the-sharadar-db-bundle-c8d3dd101730?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8d3dd101730</guid>
            <category><![CDATA[ziplines]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quantitative-finance]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Fri, 13 Mar 2026 16:52:24 GMT</pubDate>
            <atom:updated>2026-03-21T20:51:49.142Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Zipline Pipeline Workflow]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://mw96.medium.com/zipline-pipeline-6723632824?source=rss-6066c4ec5d4f------2"><img src="https://cdn-images-1.medium.com/max/612/1*UcdIlz-FZtow2ITOok84VQ.png" width="612"></a></p><p class="medium-feed-snippet">Learn how to work with the Zipline-Reloaded Pipeline to filter stock data according to factors.</p><p class="medium-feed-link"><a href="https://mw96.medium.com/zipline-pipeline-6723632824?source=rss-6066c4ec5d4f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://mw96.medium.com/zipline-pipeline-6723632824?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6723632824</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[zipline-reloaded]]></category>
            <category><![CDATA[trading-system]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sat, 04 Mar 2023 20:42:14 GMT</pubDate>
            <atom:updated>2023-03-04T20:48:59.652Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Cloud Driven Snakes]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://mw96.medium.com/cloud-driven-snakes-be036e28d84f?source=rss-6066c4ec5d4f------2"><img src="https://cdn-images-1.medium.com/max/1440/1*mycIYgP51NJtEiAmhYPSsg.png" width="1440"></a></p><p class="medium-feed-snippet">Get Started with PythonAnywhere to run a Trading Algorithm in the Cloud</p><p class="medium-feed-link"><a href="https://mw96.medium.com/cloud-driven-snakes-be036e28d84f?source=rss-6066c4ec5d4f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://mw96.medium.com/cloud-driven-snakes-be036e28d84f?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/be036e28d84f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 10:00:08 GMT</pubDate>
            <atom:updated>2022-10-24T10:29:52.967Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Standing on the Shoulder of Giants]]></title>
            <link>https://mw96.medium.com/standing-on-the-shoulder-of-giants-72f90ee2a959?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/72f90ee2a959</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[live-trading]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sat, 14 May 2022 17:29:37 GMT</pubDate>
            <atom:updated>2022-06-07T09:18:04.498Z</atom:updated>
            <content:encoded><![CDATA[<p>Using a Simple Python Live Trading Framework with Zipline Interface</p><p>In the last articels we looked at how to backtest with the Z<a href="https://pypi.org/project/zipline-reloaded/">ipline-Reloaded </a>and then introduced Z<a href="https://github.com/shlomikushchi/zipline-trader">ipline-Trader</a> as an alternative for backtesting and live-trading service provided by the <a href="https://www.bizjournals.com/boston/news/2020/11/10/quantopian-shuts-down-cofounders-head-elsewhere.html">crowd-sourced investment fund Quantopian</a>. Now tighten your seatbelts and get ready to test your algorithm live in the cloud with pylivetrader a simple python live trading framework with zipline interface provided by <a href="https://alpaca.markets/">Alpaca</a>.</p><h3>1. Create New Environment</h3><p>Download and install <a href="https://www.anaconda.com/products/individual">Anaconda</a>. I recommend using <a href="https://code.visualstudio.com/">Visual Studio Code</a> as an IDE. Create a new environment in your conda navigator or terminal and use Python version 3.6 given dependencies. I recommend that you setup a new environment to use pylivetrader. Some packages create a conflict with pylivetrade and that will cause errors while running the algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/230cafb483a90a697a98b34dd195ddb2/href">https://medium.com/media/230cafb483a90a697a98b34dd195ddb2/href</a></iframe><h3>2. Install Packages</h3><p>So now we install pylivetrader together with other useful packages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7af4e6174510c1f48c8de24de7b47aa/href">https://medium.com/media/d7af4e6174510c1f48c8de24de7b47aa/href</a></iframe><h3>3. Configuration for API Access</h3><p>Before running any algorithm with pylivetrader or pipeline-live, you need to set up your environment for API access. To do so you can either store your connection information in environment variables or in a yaml config file. All relevant information can be obtained via your Alpaca dashboard.</p><h4><strong>3.1. Environment Variables</strong></h4><ul><li>APCA_API_KEY_ID</li><li>APCA_API_SECRET_KEY</li><li>APCA_API_BASE_URL</li></ul><p>The environment needs to be activated via terminal. Then use the following code to export the variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f15c12be911708ff50ee640086bae0e8/href">https://medium.com/media/f15c12be911708ff50ee640086bae0e8/href</a></iframe><h4><strong>3.2. Config File Parameters</strong></h4><ul><li>key_id</li><li>secret</li><li>base_url</li><li>feed</li></ul><p>Create a yaml file named and name it “config.yaml”. Then add these configuration parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5b16ab08cc8495103da4d34e71f9f18/href">https://medium.com/media/e5b16ab08cc8495103da4d34e71f9f18/href</a></iframe><h3>4. The Trading Algorithm</h3><p>To make the process a little more visual we are going to use a Jupyter-Notebook to build our first algorithm. Then we create a python file so we can run the algorithm from the CLI tool named <em>pylivetrader.</em></p><h4>4.1. Algorithm &amp; Pipeline Walkthrough</h4><p>We are going to build the algorithm together with the pipeline step by step. For a better undestanding we are going to go step by step through the notebook. You can finde the <a href="https://github.com/Moccazio/Medium/blob/main/Standing_on_the_Shoulder_of_Giants/notebook.ipynb">complete notebook on GitHub</a>. We start with importing all the modules we need to connect to the API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/723985ba76cbcb9f8ef0bde5aa025670/href">https://medium.com/media/723985ba76cbcb9f8ef0bde5aa025670/href</a></iframe><p>And now we import pylivetrader and the pipeline-live packages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3890c40391c8dd8e703d4d21318bb1ae/href">https://medium.com/media/3890c40391c8dd8e703d4d21318bb1ae/href</a></iframe><p>If you need any help understanding the pylivetrader package better you can run this code in the notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee25889fe8c657547f30c47f1932ea93/href">https://medium.com/media/ee25889fe8c657547f30c47f1932ea93/href</a></iframe><p>The next step is all about setting up the pipeline in order to get the securities we want for trading. Groups of tradeable stocks are refered to as “universes”, because all your trades will use these stocks as their “universe” of available stock, they won’t be trading with anything outside these groups.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd554afd86f23e9b767e941f992ac9bb/href">https://medium.com/media/dd554afd86f23e9b767e941f992ac9bb/href</a></iframe><p>Let’s apply our own filters following along with some of the examples above. Let’s select the following securities:</p><ul><li>US Stocks</li><li>They must be relatively highly traded stocks in the market (by dollar volume traded, need to be in the top 5% traded)</li></ul><p>Then we’ll calculate the percent difference as we’ve done previously. Using this percent difference we’ll create an unsophisticated strategy that shorts anything with negative percent difference (the difference between the 10 day mean and the 30 day mean).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caa9cccc190edfa71100fa433d301180/href">https://medium.com/media/caa9cccc190edfa71100fa433d301180/href</a></iframe><p>Now we are going to graph the pipeline we designed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d472655b01c458b9c916b9e395b5e5/href">https://medium.com/media/15d472655b01c458b9c916b9e395b5e5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wtJIeQlD5sOkuBY2yxABQ.png" /></figure><p>Lets run the pipeline.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6e2dd01b35ad6eca6b4a1d27c48503e/href">https://medium.com/media/e6e2dd01b35ad6eca6b4a1d27c48503e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_y9hdQOw2KaGxBJKTmmHbA.png" /></figure><p>Lets inspect the pipeline results a little.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf7108afdacbb69ca7d148666c93d453/href">https://medium.com/media/cf7108afdacbb69ca7d148666c93d453/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2CW3UeEdtTtetfAQw24k6A.png" /></figure><h3><strong>5. Executing the Strategy</strong></h3><p>To launche the algorithm with pylivetrader we create a python file and copy the following code into the file. If you take a closer look you see that pylivetrader follows the same logic as zipline. If you have no experience with zipline yet I recommend you have a look at the <a href="https://mw96.medium.com/algorithmic-trading-simulations-a211b5b6aa40">previous articels</a> and the documentation for the <a href="https://zipline.ml4trading.io/">zipline-reloaded</a> package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d23871c43c5b10f32064ab8daab73b82/href">https://medium.com/media/d23871c43c5b10f32064ab8daab73b82/href</a></iframe><h4>5.1 Terminal Commands to run the Strategy</h4><p>Open your terminal and activate the ziplive environment. Then export the config data and run pylivetrader with reference to the local path where the long_short_pipeline_algo.py file is saved. Use the following code to run the algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2567ccea68014ae2c00ee21bbc70dbe/href">https://medium.com/media/c2567ccea68014ae2c00ee21bbc70dbe/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIOAQ-HHVDwNQ6ZMI7T8cw.png" /></figure><p>After you enter the last command to run the long_short_pipeline_algo.py you should see the pipeline fetching data and 20 min before market close the rebalance will start and trade according to the pipeline results.</p><h3>Appendix</h3><p><a href="https://github.com/Moccazio/Medium/tree/main/Standing_on_the_Shoulder_of_Giants">Medium/Standing_on_the_Shoulder_of_Giants at main · Moccazio/Medium</a></p><p><strong>Sources:</strong></p><ul><li><a href="https://zipline.ml4trading.io/">https://pypi.org/project/zipline-reloaded/</a></li><li><a href="https://github.com/alpacahq/pylivetrader">https://github.com/alpacahq/pylivetrader</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72f90ee2a959" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Algorithmic Trading Simulations To Live Trading]]></title>
            <link>https://python.plainenglish.io/from-algorithmic-trading-simulations-to-live-trading-a2decd7a1847?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2decd7a1847</guid>
            <category><![CDATA[backtesting]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 10:31:44 GMT</pubDate>
            <atom:updated>2021-12-29T10:24:44.333Z</atom:updated>
            <content:encoded><![CDATA[<h4>Live Trading with Zipline-Trader &amp; Alpaca-API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oRD_xaqCf8Luc0dC" /><figcaption>Photo by <a href="https://unsplash.com/@heylagostechie?utm_source=medium&amp;utm_medium=referral">Lagos Techie</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So in the last articles, we looked at how to set up <a href="https://zipline.ml4trading.io/api-reference.html">Zipline-Reloaded</a> for algorithmic trading simulations. In this article, we will dive a little deeper into the zipline coding community. We will set up <a href="https://zipline-trader.readthedocs.io/en/latest/">Zipline-Trader</a> so we can first run a backtest and then go live with the algorithm. Yes with Zipline-Trader we can go live and trade with the Alpaca-API. The Quantopian website shut down its service in 2020 the backtesting engine Zipline is still being developed by the coding community. Some websites offer a similar service to Quantopian with having a full backtesting engine that you can easily run over their website like <a href="https://github.com/QuantConnect/Lean">LEAN</a> from <a href="https://www.quantconnect.com/">Quantconnect</a>. LEAN is a C# based engine and it works a bit different than Zipline. If you want to try it out you can run the engine directly on their website. Well, we are going to have a more detailed look now on how to set up Zipline-Trader and connect to the Alpaca-Api so we can ingest data and go live with our strategy.</p><h3>1. Install Zipline-Trader</h3><p>The first challenge here is to download and install Zipline-Trader so it runs stable. We will have a look at how to download and install Zipline-Trader on mac. So if you have windows you should check the <a href="https://zipline-trader.readthedocs.io/en/latest/install.html">documentation </a>for more details.</p><h4>1.1. Create Python 3.6 Environment</h4><p>Launch the Terminal and create a python3.6 environment. We need to git clone Zipline-Trader and install some specific modules to avoid errors when we run our algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a69c1a3cdfbb9dff4068b9a2a4d40c7/href">https://medium.com/media/4a69c1a3cdfbb9dff4068b9a2a4d40c7/href</a></iframe><h4>1.2. Modify The Code</h4><p>We need to change some of the Zipline-Trader code. Otherwise, we will not be able to ingest data from the alpaca-api correctly. So if you want to manage the whole process a little bit better I recommend you install <a href="https://code.visualstudio.com/">Visual Studio Code</a>.</p><p>Open the Zipline-Trader folder that we installed before. Navigate to data, bundles and open the alpaca_api.py file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LmvfZZbSG1T1NFsDYEBHg.png" /></figure><p>Replace the code in the alpaca_api.py file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c265d4768778511aed36977f519c0b/href">https://medium.com/media/69c265d4768778511aed36977f519c0b/href</a></iframe><h3>2.0. The Config File</h3><p>In the main folder, we need to create a YAML file that holds our alpaca-api keys and information about the stock universe that we want to ingest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c95f48c412a192ff18e3cf8bc8fa5924/href">https://medium.com/media/c95f48c412a192ff18e3cf8bc8fa5924/href</a></iframe><p>You need to have an alpaca account to download and ingest data. So if you don’t have an account yet sign up for free.</p><p><a href="https://alpaca.markets/">Alpaca - Developer-First API for Trading</a></p><h3>3.0. Load Data Bundle</h3><p>Now we are going to ingest data into Zipline-Trader. Activate the <em>ziptrader36 </em>environment we installed before and launch a Jupyter notebook. Then run the following code to load and ingest the bundle with the SP500 universe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca384f526ecf54dbca62e5f1fd8874d1/href">https://medium.com/media/ca384f526ecf54dbca62e5f1fd8874d1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YM2_8nVmBMEPvlHBiguG0w.png" /></figure><p>So the key is that you ingest the bundle with the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ef2c226ec9881ad014d49f7c1b855ee/href">https://medium.com/media/4ef2c226ec9881ad014d49f7c1b855ee/href</a></iframe><p>If you want to change the stock universe you need to change it in the <em>alpaca.yaml</em> file.</p><h4>2.1. Create Data Portal</h4><p>Let&#39;s check if we can load some of the data we ingested. Again we will use a notebook to create a data portal to get some historical data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ed4e91c7bed6bf54269028ef54aa71c/href">https://medium.com/media/8ed4e91c7bed6bf54269028ef54aa71c/href</a></iframe><p>Now we can get some historical data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/501b5ed7e830082d5ff20cc33687eb56/href">https://medium.com/media/501b5ed7e830082d5ff20cc33687eb56/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94OdXcgBy-bbb1Eeia1oQQ.png" /></figure><h3>3.0. Simple Factor Pipeline</h3><p>Okay, now we create a factor pipeline and analyze all the factors with alphalens. The factor analysis will give us a nice overview of the data.</p><p>We start with a factor pipeline so we can create a dataframe with all the factor data ready for analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9289fca137f5db20c5de7141e8468e0d/href">https://medium.com/media/9289fca137f5db20c5de7141e8468e0d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ma8VxS3n0gw4hbRWeoAfXg.png" /></figure><p>Now we create a full tear sheet with alphalens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bacb7f8045ad978a3fd36e714b69fbf8/href">https://medium.com/media/bacb7f8045ad978a3fd36e714b69fbf8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*4crmC1wff3XG3O2HSr_4Gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*AtOgi1eBZvUhf46K4tbE2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*WijceWl61FFTUIZTp_zcpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*3-NMNoTCLPQ6cO_gMHiD-A.png" /></figure><h3>4.0. Live Trading</h3><p>Before we start we need to change the universe in the alpaca.yaml file and the start date in the alpaca_api.py file. Then we repeat the whole process from before and ingest some new data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90adc52056ec2f238418ab75da1a7e08/href">https://medium.com/media/90adc52056ec2f238418ab75da1a7e08/href</a></iframe><p>Change the date in the alpaca_api.py otherwise, you will be loading data the whole day. If you want to keep it easy you can adjust the date and change it to days.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d312fede6f3f5917da863495cfb2705b/href">https://medium.com/media/d312fede6f3f5917da863495cfb2705b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aR5ZcZTlvP7tJGA5M9BXcg.png" /></figure><p>As you can see this already took over an hour. If you want to launch your code on a daily base you may have to adjust the date to get the data a bit faster.</p><p>Let&#39;s go live with an example algorithm. You can adjust the code according to your strategy and then test it yourself. To run an algorithm live you have to simply run the algorithm file in the terminal. The following code is a simple buy and holds for the ASML stock. The order target is 10. So if you run the code you will buy 10 ASML stocks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f125fa783e238aabc4502d770c19843/href">https://medium.com/media/6f125fa783e238aabc4502d770c19843/href</a></iframe><p>In Visual Studio Code you can open the file and simply run the Python file in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-jooNcRGEcGAVHUwYbXng.png" /></figure><h3>Appendix</h3><p><a href="https://github.com/Moccazio/Medium/tree/main/From_Algorithmic_Trading_Simulations_To_Live_Trading">Medium/From_Algorithmic_Trading_Simulations_To_Live_Trading at main · Moccazio/Medium</a></p><h3>Sources</h3><ul><li><a href="https://zipline-trader.readthedocs.io/en/latest/">https://zipline-trader.readthedocs.io/en/latest/</a></li><li><a href="https://github.com/shlomikushchi/zipline-trader">https://github.com/shlomikushchi/zipline-trader</a></li><li><a href="https://github.com/aspromatis/zipline-trader-demo">https://github.com/aspromatis/zipline-trader-demo</a></li></ul><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2decd7a1847" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/from-algorithmic-trading-simulations-to-live-trading-a2decd7a1847">From Algorithmic Trading Simulations To Live Trading</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithmic Trading Simulations Part III]]></title>
            <link>https://mw96.medium.com/algorithmic-trading-simulations-part-iii-d8ff8572284e?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8ff8572284e</guid>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[backtesting]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sat, 20 Nov 2021 17:25:56 GMT</pubDate>
            <atom:updated>2021-11-20T17:37:52.169Z</atom:updated>
            <content:encoded><![CDATA[<p>Setup Exchange and Asset Metadata to run a Single Factor Pipeline with Zipline-Reloaded</p><p>This articel is based on the custom data we ingested in tbe priovious articel and the basics coding for backtesting in zipline. So if you didn’t read the last two articles about algorithmic trading simulations you should.</p><ul><li><a href="https://mocca96.medium.com/algorithmic-trading-simulations-a211b5b6aa40">Algorithmic Trading Simulations Part I</a></li><li><a href="https://mocca96.medium.com/algorithmic-trading-simulations-part-ii-6f138a146b93">Algorithmic Trading Simulations Part II</a></li></ul><h3>1. The Pipeline API</h3><p>A p<a href="https://zipline.ml4trading.io/api-reference.html#zipline.pipeline.Pipeline">ipeline</a> enables faster and more memory-efficient execution by optimizing the computation of factors during a backtest. To demonstrate the power of using a pipeline we going to develope and test a simple mean-reversion factor that measures how much recent performance has deviated from the historical average.</p><p>Run the jupyter notebook extension.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bfc4c4c6e3b23db8ea3461490818ee1/href">https://medium.com/media/7bfc4c4c6e3b23db8ea3461490818ee1/href</a></iframe><p>The following code demonstrates a zipline backtest for a simple mean-reversion factor that measures how much recent performance has deviated from the historical average. We are not going to place any orders to simply illustrate the implementation of a custom factor pipeline. We are going to record the results during the simulation so we can inspect the results later on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8997438fd04e890ab9856ffab7d5b9e8/href">https://medium.com/media/8997438fd04e890ab9856ffab7d5b9e8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3kfs2QFwi7BNv4GNm50oIQ.png" /></figure><p>Well after you launch the algorithm you are going to see an error from zipline-reloaded that it faild to find any assets with the country_code ‘US’. Well thats because there is a bug that requires (manually) fixing the SQL database.</p><h3>2. Fixing the SQL Database</h3><p>The challenge that we face when we run a zipline backtest with custom data is the country code. Lets have a look on how we can set the country code to ‘US’.</p><h4>2.1. Edit Database Files with DB4S</h4><p>To open and edit the data that we ingested in <a href="https://mocca96.medium.com/algorithmic-trading-simulations-a211b5b6aa40">part 1</a> I recommend the DB Browser for SQLite Version.</p><p><a href="https://sqlitebrowser.org/">DB Browser for SQLite</a></p><p>Once you downloaded the DB Browser and you start it you should see a database overview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPjxnxtQX14n8J6PEqEDzA.png" /></figure><h4>2.2. Showing Hidden Files on Mac</h4><p>Where do we find the data we ingested into zipline? Well you can search for ever because the data is in a hidden folder named “.zipline”. Keyboard shortcuts are probably the easiest way to display hidden files and folders in the Finder on a Mac.</p><ol><li>Open Macintosh HD or the folder where you want to display the hidden files in the Finder.</li><li>Hold down the Command, Shift and Period keys: <strong>cmd + shift + [.]</strong></li><li>The hidden files and folders will then appear partially transparent.</li><li>You can hide the files again using the same keyboard shortcut.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tY71scv5WQ6PfP6WSEbE1g.png" /></figure><p>Now open the DB4S and click “Open Database” then we navigate to our user home directory and press <strong>cmd + shift + [.]</strong>. Select the ‘.zipline’ go to “data” and open the folder ‘yahoo_direct’. Then we open the “asset-7.sqlite” file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qor0_6JcEUzRz-QBmfPNCA.png" /></figure><p>We move from “Database Structure” to “Browse Data” and change the table from “asset_router” to “exchanges”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IRNWBDLfD3NfMvHxQ_5CwA.png" /></figure><p>Finally we see the column “country_code”. The current value is “??”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2HMKbM4_1G5OkvxzCxW3w.png" /></figure><p>Now we click on the “??” and type “US”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uxA6-CrPByk6YRTtqGA5Qg.png" /></figure><p>After doing so we can close the DB4S and click on “save”.</p><h3>3. Backtesting Single Factor Pipeline</h3><p>Go back into the jupyter notebook and run the code from <a href="https://gist.github.com/Moccazio/a09abd2cfe827f4b8206c1ae27064d59#file-single_factor_pipepline-py"><strong>Single_Factor_Pipepline.py</strong></a><strong> </strong>again. Now you should see the backtest results and not the country_code error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDbBJg2STElvCPDeBCA_rA.png" /></figure><h3>4. Inspect Results</h3><p>We can get the dataframe with the results by using _ which captures the last cell output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/640f13c5a797abf13b6859b0de5d5f54/href">https://medium.com/media/640f13c5a797abf13b6859b0de5d5f54/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZiZVBzFq14qZB0lqC5elYQ.png" /></figure><h4>4.1. Plot the Results</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84253752d2bc0df5e54bb7424503a7b2/href">https://medium.com/media/84253752d2bc0df5e54bb7424503a7b2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0ozj89nLBIAEBs4s8QQng.png" /></figure><h3>Appendix</h3><p><a href="https://github.com/Moccazio/Medium/tree/main/Algorithmic_Trading_Simulations">Medium/Algorithmic_Trading_Simulations at main · Moccazio/Medium</a></p><h4>Sources:</h4><ul><li><a href="https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/04_alpha_factor_research">https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/04_alpha_factor_research</a></li><li><a href="https://zipline.ml4trading.io/api-reference.html#zipline.pipeline.Pipeline">https://zipline.ml4trading.io/api-reference.html#zipline.pipeline.Pipeline</a></li><li><a href="https://github.com/quantopian/research_public">https://github.com/quantopian/research_public</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8ff8572284e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithmic Trading Simulations Part II]]></title>
            <link>https://mw96.medium.com/algorithmic-trading-simulations-part-ii-6f138a146b93?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f138a146b93</guid>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[backtesting]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sun, 14 Nov 2021 22:22:07 GMT</pubDate>
            <atom:updated>2021-11-21T14:39:26.303Z</atom:updated>
            <content:encoded><![CDATA[<p>Build and Backtest Trading Strategies using Zipline-Reloaded</p><p>In this articel we are going to look at how to run an algorithm on financial data. We are going to use the data that we ingested in the <a href="https://mocca96.medium.com/algorithmic-trading-simulations-a211b5b6aa40">previous articel</a>. Backtesting is basically evaluating the performance of a trading strategy on historical data.<em> </em>If we used a given strategy on a set of assets in the past, how well/bad would it have performed<em>. </em>Of course, there is no guarantee that past performance is indicative of the future one, but we can still investigate!</p><p>There are a few available frameworks for backtesting in Python. In this article we are going to use <a href="https://zipline.ml4trading.io/">zipline-reloaded</a>.</p><h3>Build Trading Strategies using Zipline</h3><p>Trading strategies can be defined as a method of buy and selling assets in markets that is based on predefined rules. These rules can be based on e.g. machine learning models. Backtesting is basically evaluating the performance of a trading strategy on historical data.</p><blockquote>If we used a given strategy on a set of assets in the past, how well/bad would it have performed?</blockquote><h4>How to construct an algorithm</h4><p>Every Zipline algorithm consists of two functions you have to define:</p><ul><li>initialize(context)</li><li>handle_data(context, data)</li></ul><p>Before the start of the algorithm, Zipline calls the initialize() function and passes in a context variable. context is a persistent namespace for you to store variables you need to access from one algorithm iteration to the next. After the algorithm has been initialized, Zipline calls the handle_data() function once for each event. At every call, it passes the same context variable and an event-frame called data containing the current trading bar with open, high, low, and close (OHLC) prices as well as volume for each stock in your universe.</p><h4>How to run the Algortihm</h4><p>Zipline provides three interfaces for running an algorithm on financial data:</p><ol><li><strong>Command Line via the zipline command</strong></li><li><strong>Jupyter Notebook via Zipline Magic</strong></li><li><strong>Zipline in your IDE via </strong><strong>run_algorithm()</strong></li></ol><p>We are going to use all the three zipline interfaces for running an buy and hold strategy with zipline.</p><h3>The Buy And Hold Strategy</h3><p>The idea is that we buy a certain asset and do not do anything for the entire duration of the investment horizon. The Buy and hold strategy is a simple trading strategy with a boring performance. This simple strategy can also be considered a benchmark for more advanced ones because there is no point in using a very complex strategy that generates less money (for example due to transaction costs) than buying and doing nothing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31c341f31d1759fe1dd6ca76abc33060/href">https://medium.com/media/31c341f31d1759fe1dd6ca76abc33060/href</a></iframe><h4>1. Command Line via Zipline Command</h4><p>After you installed zipline you should be able to execute the following from your command line (e.g. Terminal app on OSX):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e306c687d970c9d2ac59085ce9068088/href">https://medium.com/media/e306c687d970c9d2ac59085ce9068088/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZqqXVbMf7YSKs6RUxeJOg.png" /></figure><p>To execute an algorithm we call zipline run as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1a874f44030201a8479ee68dd84b95f/href">https://medium.com/media/e1a874f44030201a8479ee68dd84b95f/href</a></iframe><h4>2. Jupyter Notebook via Zipline Magic</h4><p>We write the algorithm within a Notebook cell and indicate that zipline is supposed to run it. This is done via the %%zipline IPython magic command. This magic takes the same arguments as the CLI mentioned above . Also one important thing, all imports required for the algorithm to run (such as numpy, sklearn, etc.) must be specified in the algorithm cell, even if they were previously imported elsewhere.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2aee500b9f5ec2d1bbf089db208cb00/href">https://medium.com/media/d2aee500b9f5ec2d1bbf089db208cb00/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGx8onxQab6jTcTF5OO1ew.png" /></figure><p>Final portfolio value (including cash): 523.92$</p><p>Well we had a capital-base of 300 $ and bought 2 shares of Apple on the 04–01-2019. Two years later the final portfolio value is 523,92$.</p><h4>3. Zipline in your IDE via run_algorithm()</h4><p>To execute an algorithm like a Python script in your favorite IDE, use the run_algorithm() function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9952c5385868b17be7870c2b0a8a4358/href">https://medium.com/media/9952c5385868b17be7870c2b0a8a4358/href</a></iframe><p>We can plot the results nicely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15eac06b112c8637ef887533cf37307f/href">https://medium.com/media/15eac06b112c8637ef887533cf37307f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcPIqyRx0TZkopFPEp_xZw.png" /></figure><p>If we bought two shares of Apple back in 2012 and just hold it until November 2021 we have a final portfolio value (including cash) of 528.41$.</p><p>To view the transactions we need to transform the transactions column from the performance DataFrame.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/490427cdaa2c1bc30ae5a6f43a102360/href">https://medium.com/media/490427cdaa2c1bc30ae5a6f43a102360/href</a></iframe><p>By inspecting the columns of the performance DataFrame we can see all the available metrics.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c8dd61dc4e6ddc68efccfd5c88e3063/href">https://medium.com/media/4c8dd61dc4e6ddc68efccfd5c88e3063/href</a></iframe><p>To get an overview and some info we use .info(null_counts=True).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cce7526ed989842382695e85c026c01f/href">https://medium.com/media/cce7526ed989842382695e85c026c01f/href</a></iframe><h3>Simple Moving Average Strategy</h3><p>A strategy that is also really common for trading equities is the simple moving average strategy (sma).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a7d8b443c1e0529ca53bed2e683f906/href">https://medium.com/media/0a7d8b443c1e0529ca53bed2e683f906/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIfj1rjzZI-HnYqdhsM1Aw.png" /></figure><h3>Appendix</h3><ul><li><a href="https://mocca96.medium.com/algorithmic-trading-simulations-a211b5b6aa40">Algorithmic Trading Simulations Part I</a></li><li><a href="https://github.com/Moccazio/Medium/tree/main/Algorithmic_Trading_Simulations">Medium/Algorithmic_Trading_Simulations at main · Moccazio/Medium</a></li></ul><h4>Sources:</h4><ul><li><a href="https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/08_ml4t_workflow">https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/08_ml4t_workflow</a></li><li><a href="https://github.com/shlomikushchi/research_public">https://github.com/shlomikushchi/research_public</a></li><li><a href="https://github.com/mrefermat/FinancePhD">https://github.com/mrefermat/FinancePhD</a></li><li><a href="https://zipline.ml4trading.io/">https://zipline.ml4trading.io/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f138a146b93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithmic Trading Simulations Part I]]></title>
            <link>https://mw96.medium.com/algorithmic-trading-simulations-a211b5b6aa40?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a211b5b6aa40</guid>
            <category><![CDATA[backtesting]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sat, 30 Oct 2021 15:54:11 GMT</pubDate>
            <atom:updated>2023-01-05T12:06:45.405Z</atom:updated>
            <content:encoded><![CDATA[<h4>Get Started with Zipline-Reloaded</h4><p>In this articel we will look at how to set up an environment so we can install the <a href="https://zipline.ml4trading.io/">Zipline-Reloaded</a> package and ingest data in order to run an algorithm trading simulation.</p><h3>Setup</h3><ol><li>Install Anaconda</li><li>Create an Environment with Mamba and Python 3.8.</li><li>Install Zipline-Reloaded and Libraries for Performance Analysis</li><li>Handling Zipline-Bundles</li><li>Add Custom Data to Zipline-Bundles</li><li>Ingest Custom Data</li><li>Data Access Using Zipline in a Jupyter Notebook</li></ol><h3>1. Install Anaconda</h3><h4>Windows:</h4><p><a href="https://docs.anaconda.com/anaconda/install/windows/">Installing Anaconda Distribution - Anaconda</a></p><h4>Mac:</h4><p><a href="https://docs.anaconda.com/anaconda/install/mac-os/">Installing on macOS - Anaconda documentation</a></p><h4>Linux:</h4><p><a href="https://docs.anaconda.com/anaconda/install/linux/">Installing on Linux - Anaconda documentation</a></p><h3>2. Create a Virtual Environment</h3><p>Launch the terminal and install mamba.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c33ce6733c0945aca9478bc1860360f/href">https://medium.com/media/7c33ce6733c0945aca9478bc1860360f/href</a></iframe><h3>3. Install Zipline-Reloaded and Libraries for Performance Analysis</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdb232825fd4a69fd071d1a14e169bda/href">https://medium.com/media/cdb232825fd4a69fd071d1a14e169bda/href</a></iframe><h3>4. Handling Zipline-Bundles</h3><p>The standard quandl libary installed with zipline is not recommended for proper backtestting because the data ends in 2018. Thats why we install <a href="https://github.com/hhatefi/zipline_bundles">zipline_bundles</a> as a helping tool from git so we can easly ingest our own data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17c123e7ffdfedd4d11319f3b6e29f04/href">https://medium.com/media/17c123e7ffdfedd4d11319f3b6e29f04/href</a></iframe><h4>4.1. Modify “extension.py”</h4><p>If you want to change parameters or add a new bundle you go into the folder of zipline_bundles and edit the extension.py. I will give you a quick example. I want to change the name of the exchange from the yahoo_dircet bundle so I change the name in the extension.py.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0369f383e3a93e011b808df0ca19bd3d/href">https://medium.com/media/0369f383e3a93e011b808df0ca19bd3d/href</a></iframe><h3>5. Add Custom Data to Zipline-Bundles</h3><p>Now we need to download and ingest the data into zipline. It seems to be a complicated process to ingest custom data into zipline. We are going to go throw the code for the hole process.</p><h4><strong>5.1. Jupyter Notebook</strong></h4><p>Run a Jupyter Notebook and import the following modules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03f087d5161e20a52aa1e56335e37d2d/href">https://medium.com/media/03f087d5161e20a52aa1e56335e37d2d/href</a></iframe><h4>5.2. <strong>IPython Magic Command</strong></h4><p>Zipline provides an easy way to run your algorithm inside the Notebook. To use it you have to write your algorithm in a cell and let Zipline know that it is supposed to run this algorithm. This is done via the IPython magic command that is available after you import zipline from within the IPython Notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da6399a2ab45a8f47ba3bf26e2f7794d/href">https://medium.com/media/da6399a2ab45a8f47ba3bf26e2f7794d/href</a></iframe><h3>6. Ingest Data</h3><p>Now we are able to call the yahoo_direct together with zipline ingest function. The tickers that you want to download and ingest are set at the beginning of the function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2952066ed6e553719bdec5e2ca8e7114/href">https://medium.com/media/2952066ed6e553719bdec5e2ca8e7114/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2k6NNwQ3GbS4wZUUZfM7Jw.png" /></figure><h3>7. Data Access Using Zipline in a Jupyter Notebook</h3><p>The following code illustrates how zipline permits us to access daily stock data for a range of companies. You can run zipline scripts in the Jupyter Notebook using the magic function of the same name. First, you need to initialize the context with the desired security symbols. We’ll also use a counter variable. Then zipline calls handle_data, where we use the `data.history()` method to look back a single period and append the data for the last day to a .csv file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b9d210ec8e355a75693bfd029afa388/href">https://medium.com/media/6b9d210ec8e355a75693bfd029afa388/href</a></iframe><h4>7.1. Plot the Data</h4><p>We can plot the data in the Jupyter Notebook easily.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e052584192b144d68349aa7db5b2f7f/href">https://medium.com/media/8e052584192b144d68349aa7db5b2f7f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yX9dQBza_QEUoFO5WeizVA.png" /></figure><h3>Appendix</h3><p><a href="https://github.com/Moccazio/Medium/tree/main/Algorithmic_Trading_Simulations">Medium/Algorithmic_Trading_Simulations at main · Moccazio/Medium</a></p><h4>Sources:</h4><ol><li><a href="https://zipline.ml4trading.io/">https://zipline.ml4trading.io/</a></li><li><a href="https://hhatefi.github.io/posts/zipline_bundles/">https://hhatefi.github.io/posts/zipline_bundles/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a211b5b6aa40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lemons Can Be Sweet]]></title>
            <link>https://mw96.medium.com/lemons-can-be-sweet-953ea87a561f?source=rss-6066c4ec5d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/953ea87a561f</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[jupyterlab]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Maximilian Wimmer]]></dc:creator>
            <pubDate>Sat, 17 Jul 2021 22:50:51 GMT</pubDate>
            <atom:updated>2021-08-07T22:45:02.716Z</atom:updated>
            <content:encoded><![CDATA[<p>Discovering Trading Liberty with lemon.markets</p><p>I started with learning python after I finished my studies in behavioral finance at uni. Coding my own equity trading strategy with the information available is always my first step before I actually decide to buy or sell a stock. Once the strategy is stable I apply it manually to my real portfolio. I wanted to optimize the process of trading so I was searching for an trading API. I discovered more then one solution and was starting to get excited. I signed up on the first website that was promoting an stable trading API. Unfortunately I live in Germany and I am not a US citizen so I am not able to create a account and trade equities in the US for now.</p><p>After days of searching for a possible trading platform I discovered a website named lemon.markets. The company is based in Germany and the lemon.markets API allows you to build your own trading strategies or application in a so called space. For now the lemon.markets API is in closed beta and you have to sign up for the waiting list to get early access. Once you are signed up for the closed beta the documentation leads the way to your first order that is placed on the Munich Stock Exchange (XMUN). I enjoy the design of the lemon.markets website and the sturcture of the documentation. The design is simple and effective. After the login you see the overview to watch all of your spaces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*veiK_Th-aQPMD_t_4Tql7Q.png" /><figcaption>Overview</figcaption></figure><p>We will quickly have a look at the structure of the API before we place an order and start with the portfolio management in python.</p><h3>API Structure</h3><blockquote>The lemon.markets API consists of a variety of different endpoints that together enable you to place orders at the stock market, manage your previous orders and portfolio, and retrieve market data conveniently. The Graph below shows how the different API services are structured and related with each other.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mSB741aP-Ec5eBAqPAoAw.png" /><figcaption><a href="https://docs.lemon.markets/api-structure">Source: https://docs.lemon.markets/api-structure</a></figcaption></figure><h3>Portfolio Management with lemon.markets API</h3><p>First of all we are going to code a class that helps us with our portfolio management with the API. The goal is that we can call a class that helps us placing an order quickly and shows the portfolio data nicely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac2b5a667b60320d20ffe75971dca7f5/href">https://medium.com/media/ac2b5a667b60320d20ffe75971dca7f5/href</a></iframe><h3>Placing an Order</h3><p>To place an order on lemon.markets API the order needs to be created and then activated. The lemon_markets class from lemon_markets.py allows us to quickly place and activate an order in one process.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c46e26ca9671a905a24ad8a6ef3ce8a0/href">https://medium.com/media/c46e26ca9671a905a24ad8a6ef3ce8a0/href</a></iframe><p>When you run the code you see if the status of the order is activated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*PuBm8CKXsdKBL9YyTDP1oQ.png" /></figure><h3>Get Portfolio DataFrame</h3><p>Since we want to have a nice overview of our portfolio we call the lemon_markets class and at get_portfolio_df.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57ddb56ecad8aa78bc0f739283bd094c/href">https://medium.com/media/57ddb56ecad8aa78bc0f739283bd094c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q36_fjtY99Gke6SUDtw2yA.png" /></figure><p>The dataframe shows the data from the lemon.markets API and the international ticker. In case you want to get more information about a stock in your portfolio the international ticker can be useful. In the next article we are going to look at how we get more information about the stocks in the lemon.markets portfolio.</p><h3>Stocks and Warrants DataFrame</h3><p>If we want to get the stocks and the warrants in a separate dataframe we can call get_stocks_and_warrants_df().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f847ceddcceef0c1f462c3e5b993b8c/href">https://medium.com/media/7f847ceddcceef0c1f462c3e5b993b8c/href</a></iframe><p>To see the only stocks dataframe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d648896423b684fac2fb546396164ca2/href">https://medium.com/media/d648896423b684fac2fb546396164ca2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-g_qkaX-Gj1yyILVWe3Hxg.png" /></figure><p>For the only warrants dataframe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c69ec73a30bcc4f912312f2f4a6e672/href">https://medium.com/media/4c69ec73a30bcc4f912312f2f4a6e672/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_1R_9cSMxLu-z82iT1rqg.png" /></figure><h3>Get OHLC DataFrame</h3><p>Now we want to get a quick overview of all stocks OHLC data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8e51b5d88508af20e30b5ac748a0976/href">https://medium.com/media/b8e51b5d88508af20e30b5ac748a0976/href</a></iframe><p>Running the code will give you a single plot for each stock. Next we are going to a get the portfolio_close_df that will give us a more quick and clean overview with the stocks close and the ISIN.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32898956427d343a920bbe65fb97f325/href">https://medium.com/media/32898956427d343a920bbe65fb97f325/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBcOhtTHn3YUile0GAF-rA.png" /></figure><h3>Get Portfolio Return DataFrame</h3><p>The portfolio return can be called as simple return and log return.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a24388f7d7505d24dddf1a057603c6e1/href">https://medium.com/media/a24388f7d7505d24dddf1a057603c6e1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fKbV9sR8M0KePsMOEXUcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8qtzJ4vlGW6mNy_xyZ6_A.png" /></figure><h3>Get Weighted Portfolio Return DataFrame</h3><p>The weighted portfolio return can be called with the same method as portfolio return. To see the overall performance of our portfolio we plot the cumulative return.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/390011409e8ae7011e08f70ca5bedee3/href">https://medium.com/media/390011409e8ae7011e08f70ca5bedee3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lL5bZ8-hXMnV9i5mFM9h9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVE0uURbZb_cfZSTfAajiA.png" /></figure><h3>Sign up for lemon.markets</h3><ul><li><a href="https://dashboard.lemon.markets/signup">https://dashboard.lemon.markets/signup</a></li></ul><h3>Sources:</h3><ul><li><a href="https://docs.lemon.markets/api-endpoints">https://docs.lemon.markets/api-endpoints</a></li><li><a href="https://docs.lemon.markets/api-structure">https://docs.lemon.markets/api-structure</a></li></ul><h3>Github:</h3><ul><li><a href="https://github.com/Moccazio/lemon_markets">https://github.com/Moccazio/lemon_markets</a></li></ul><p><a href="https://www.buymeacoffee.com/moccazio">Maximilian Wimmer is writing about quantitative finance, trading and machine learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=953ea87a561f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>