<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[samchaaa++ (trading algorithms and quantitative studies)]]></title><description><![CDATA[Working algorithms, quantitative studies, and code snippets, directly in your inbox.]]></description><link>https://samchaaa.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!dcNF!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsamchaaa.substack.com%2Fimg%2Fsubstack.png</url><title>samchaaa++ (trading algorithms and quantitative studies)</title><link>https://samchaaa.substack.com</link></image><generator>Substack</generator><lastBuildDate>Wed, 29 Jul 2026 00:37:29 GMT</lastBuildDate><atom:link href="https://samchaaa.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[samchaaa]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[samchaaa@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[samchaaa@substack.com]]></itunes:email><itunes:name><![CDATA[samchaaa]]></itunes:name></itunes:owner><itunes:author><![CDATA[samchaaa]]></itunes:author><googleplay:owner><![CDATA[samchaaa@substack.com]]></googleplay:owner><googleplay:email><![CDATA[samchaaa@substack.com]]></googleplay:email><googleplay:author><![CDATA[samchaaa]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Live code: basic spreader (handling multiple orderbooks in ccxt async)]]></title><description><![CDATA[Example of combining async data with order management, by spreading two perps in binance]]></description><link>https://samchaaa.substack.com/p/live-code-basic-spreader-handling</link><guid isPermaLink="false">https://samchaaa.substack.com/p/live-code-basic-spreader-handling</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Sat, 06 Apr 2024 21:35:49 GMT</pubDate><content:encoded><![CDATA[<p>Code here: <a href="https://github.com/samchaaa/ccxt_async_example/">https://github.com/samchaaa/ccxt_async_example/</a></p><h2>Intro</h2><p>Noticed a few new followers, so doing a quick share. This is some code I wish I had much earlier.&nbsp;It handles two issues: getting better execution, and using async operations.</p><p>This is for people struggling to learn async, and keep their code organized.</p><p>One time I came up with a strategy that looked great on paper, but did not perform live. This was due to assuming fills at last traded price. In real life, to get filled instantly, you need to market in. However this kills a lot of strategies.</p><p>Another issue is graduating from using REST APIs to async. This is my MVP for handling continuous data, orders, and execution. If you are new to async (like I was), it may be big leap to wrap all these operations together!</p><p>This code is an example of continuously moving your order to best bid/ask, in order to maximize your fill price but also get a fill ASAP (across multiple instruments).</p><h2>What it does</h2><ul><li><p>buy one perpetual, sell another on binance, always staying on the best bid/ask</p></li></ul><h2>How to run</h2><pre><code>python3 main.py binance:BTCUSDT binance:ETHUSDT 1000</code></pre><p>exchange1:pair1 exchange2:pair2 notional</p><h2>How it works</h2><ul><li><p>Wait for orderbook updates with watch_order_book_for_symbols(), put best bid/ask in a data object (dict of dicts)</p></li><li><p>Keep track of orders in self.oms (order management system)</p></li><li><p>Handle order logic in oms.py (if our limit px != best bid/ask, move to best bid/ask)</p></li></ul><p>Here&#8217;s the magic line that ties it all together:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!njbF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!njbF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 424w, https://substackcdn.com/image/fetch/$s_!njbF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 848w, https://substackcdn.com/image/fetch/$s_!njbF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 1272w, https://substackcdn.com/image/fetch/$s_!njbF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!njbF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png" width="245" height="137" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:137,&quot;width&quot;:245,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10077,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!njbF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 424w, https://substackcdn.com/image/fetch/$s_!njbF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 848w, https://substackcdn.com/image/fetch/$s_!njbF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 1272w, https://substackcdn.com/image/fetch/$s_!njbF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb64c3c4d-c99c-405d-bb1c-549fdf8f86a4_245x137.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><h2>Disclaimer and quirks</h2><ul><li><p>wait_time: Does not actually do anything, you can update to wait a bit before moving your orders though.</p></li><li><p>Data.watch_multiple_ob() changes the symbols from &#8220;/USDT:USDT&#8221; to &#8220;USDT&#8221; (you may want to modify if integrating spot instruments)</p></li><li><p>Note these are postonly orders, so if the order book moves quickly (between the time you request bid/ask and submit the order) and the code tries to post at a price that would be taking liquidity, and would break</p><ul><li><p>in this case, there&#8217;s a try/except in the OMS logic that will wait half a second, then replace the order again</p></li></ul></li><li><p>Currently exchange arguments (in `exchange1:pair1 exchange2:pair2`) don&#8217;t do anything, it&#8217;s just there to handle multiple exchanges later.</p></li></ul><h2>What you can do with it</h2><p>You can use this code to execute discretionary trades algorithmically (plot out a bunch of correlated pairs, trade divergences long/short).</p><p>With addition of spot instruments, you could use it to put on basis trades.</p><p>This code can be easily updated to handle:</p><ul><li><p>multiple exchanges</p></li><li><p>spot as well as perps</p></li><li><p>vary order size according to how fast the other leg is filling</p></li><li><p>instead of sizing to notional, size to volatility</p></li></ul><p>I hope this helps someone&#8217;s learning curve! Hit me up with input and ideas anytime.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://samchaaa.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">samchaaa++ (trading algorithms and quantitative studies) is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Weekly Finds - 2023 #8]]></title><description><![CDATA[Easy crypto HFT data collector, simple introduction to copulas, how to search twitter in <3 seconds]]></description><link>https://samchaaa.substack.com/p/weekly-finds-2023-8</link><guid isPermaLink="false">https://samchaaa.substack.com/p/weekly-finds-2023-8</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Fri, 24 Feb 2023 00:00:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!mgnD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Moving forward I&#8217;ll be sharing useful information (quant and discretionary), as I find it, on a weekly basis. </p><h2><a href="https://github.com/SpiralDevelopment/crypto-hft-data">Crypto HFT Data Aggregator</a> </h2><p><em>github.com, <a href="https://github.com/SpiralDevelopment">@SpiralDevelopment</a></em></p><p>Great entry into collecting your own HFT crypto data. Solid python code, runs right out of the box. Includes connections for Binance, Bitmex, Okex, Bitfinex, Coinbase, Bitstamp, and Kraken. </p><p></p><h2><a href="https://www.youtube.com/watch?v=WFEzkoK7tsE">A Simple Introduction to Copulas</a></h2><p><em>YouTube, <a href="https://www.youtube.com/@dirtyquant">@DirtyQuant</a></em></p><p>An amazingly to-the-point explanation of copulas, and why they are useful. Includes sample python code. Video production skills are top notch, highly recommended.</p><p></p><h2>Search New Tickers on Twitter, in &lt;3 Seconds</h2><p><em>Substack, <a href="https://samchaaa.substack.com/">@samchaaa</a></em></p><p>You know how to bookmark a search engine in Chrome as a hotkey, right? Go to chrome://settings/searchEngines &gt; &#8220;Site search&#8221;, and click &#8220;Add&#8221;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mgnD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mgnD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 424w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 848w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 1272w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mgnD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png" width="541" height="375" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:375,&quot;width&quot;:541,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18071,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mgnD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 424w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 848w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 1272w, https://substackcdn.com/image/fetch/$s_!mgnD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82e9f45d-923f-4cd5-be10-c785e454d12b_541x375.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Add &#8220;t&#8221; (or your preference) as a shortcut, and paste in the twitter search URL with &#8220;%s&#8221; instead of your search term (https://twitter.com/search?q=%24%s&amp;src=cashtag_click).</p><p>Now, all you have to do is hit: <strong>Ctrl + T, &#8220;T&#8221; (or your shortcut), Tab, &#8220;COIN&#8221;, Enter</strong></p><p>I timed myself, and it takes consistently &lt;3 seconds to enter and get search results.</p><p></p><div><hr></div><p>Thanks for reading. Good luck and good trading.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://samchaaa.substack.com/p/weekly-finds-2023-8?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://samchaaa.substack.com/p/weekly-finds-2023-8?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://samchaaa.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">samchaaa++ (trading algorithms and quantitative studies) is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[[Early Access] Market Rotation Dashboard (Google Sheets / python, works with any financial instrument)]]></title><description><![CDATA[Manage your risk intelligently as the market changes. This dashboard automatically downloads free tick data, measures &#8220;rotations&#8221; of each instrument, and writes to Google Sheets]]></description><link>https://samchaaa.substack.com/p/early-access-market-rotation-dashboard</link><guid isPermaLink="false">https://samchaaa.substack.com/p/early-access-market-rotation-dashboard</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Fri, 30 Apr 2021 20:40:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HVfI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://docs.google.com/spreadsheets/d/1Ur7CJJu-cDkhcFjEXG4smsxlKYc_323PcPYloLEvshA/edit#gid=0" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HVfI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 424w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 848w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 1272w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HVfI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png" width="481" height="255.63636363636363" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:608,&quot;width&quot;:1144,&quot;resizeWidth&quot;:481,&quot;bytes&quot;:98135,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://docs.google.com/spreadsheets/d/1Ur7CJJu-cDkhcFjEXG4smsxlKYc_323PcPYloLEvshA/edit#gid=0&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HVfI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 424w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 848w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 1272w, https://substackcdn.com/image/fetch/$s_!HVfI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F35caa94b-5d71-4716-a4b8-23f68f3cf84f_1144x608.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Dark Mode recommended</figcaption></figure></div><p>Hey readers!</p><p>Here&#8217;s a tool I use myself (for intraday trading) that will soon be written up on Medium. I want you to know about it before it gets published&#8230; let me know if you have any feedback!</p><p><a href="https://docs.google.com/spreadsheets/d/1Ur7CJJu-cDkhcFjEXG4smsxlKYc_323PcPYloLEvshA/edit#gid=0">Here&#8217;s the Google Sheet</a>.</p><p><a href="https://github.com/samchaaa/avg_rotations_dash">Here&#8217;s the repo (if you&#8217;d like to run it yourself).</a></p><p>All it does is download free tick data from https://datafeed.dukascopy.com/datafeed, run some calculations, and write to Google Sheets. It&#8217;s simple, but highly effective.</p>]]></content:encoded></item><item><title><![CDATA[Simple visualization of 121 moving average parameters and their outcome on BTCUSD]]></title><description><![CDATA[A quick example of rapidly iterating through technical parameters, using vectorized backtesting (while avoiding overfitting).]]></description><link>https://samchaaa.substack.com/p/simple-visualization-of-121-moving</link><guid isPermaLink="false">https://samchaaa.substack.com/p/simple-visualization-of-121-moving</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Sun, 15 Nov 2020 10:02:59 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!1brC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1brC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1brC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 424w, https://substackcdn.com/image/fetch/$s_!1brC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 848w, https://substackcdn.com/image/fetch/$s_!1brC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 1272w, https://substackcdn.com/image/fetch/$s_!1brC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1brC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png" width="832" height="481" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:481,&quot;width&quot;:832,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43799,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1brC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 424w, https://substackcdn.com/image/fetch/$s_!1brC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 848w, https://substackcdn.com/image/fetch/$s_!1brC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 1272w, https://substackcdn.com/image/fetch/$s_!1brC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4404caf7-924d-4034-84bf-b4db3e8688a7_832x481.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Explanation of this visual further down in the article.</figcaption></figure></div><p>At the time of this writing, bitcoin is $16,000&#8230; up +40% in the last month. While I am late to the party, I want to implement a simple trend following system (so I don&#8217;t miss trends in the future). However, I&#8217;ve never developed trend following system before, so am starting absolutely from square one.</p>
      <p>
          <a href="https://samchaaa.substack.com/p/simple-visualization-of-121-moving">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How to make a quick-and-dirty dynamic risk dashboard, using only Google Sheets, Part I]]></title><description><![CDATA[Disclaimer: This article is for entertainment purposes only. It discusses risk in terms of distance and size, while purposefully ignoring&#8230;]]></description><link>https://samchaaa.substack.com/p/how-to-make-a-quick-and-dirty-dynamic-risk-dashboard-using-only-google-sheets-part-i-a684fe5b0df3</link><guid isPermaLink="false">https://samchaaa.substack.com/p/how-to-make-a-quick-and-dirty-dynamic-risk-dashboard-using-only-google-sheets-part-i-a684fe5b0df3</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Wed, 04 Nov 2020 09:39:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SY35!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Disclaimer: This article is for entertainment purposes only. It discusses risk in terms of distance and size, while purposely ignoring percentage risk (to be discussed later). By reading this article, you take full responsibility for all your decisions as a trader.</em></p><p>This article shows how you can make money more consistently, by standardizing your risk (distance and size) across any asset classes&#8230; using only Google Sheets.</p><p>Our goal is to standardize our risk, and make it instantly accessible and understandable to you, at a single glance.</p><p>Here&#8217;s the final product (scroll to the end for the HTML version):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SY35!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SY35!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 424w, https://substackcdn.com/image/fetch/$s_!SY35!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 848w, https://substackcdn.com/image/fetch/$s_!SY35!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 1272w, https://substackcdn.com/image/fetch/$s_!SY35!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SY35!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/bce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SY35!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 424w, https://substackcdn.com/image/fetch/$s_!SY35!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 848w, https://substackcdn.com/image/fetch/$s_!SY35!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 1272w, https://substackcdn.com/image/fetch/$s_!SY35!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fbce10275-7bbf-46a1-aaa1-3d44402d0a33_800x542.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>Background: A while ago I was trying to standardize my risk more exactly across different instruments. I realized a 20 pip stop on GBPUSD is not the same monetary value as a 20 pip stop on USDJPY. Not only that, but the pairs have a different volatility&#8230; one could stop out out in hours, and the other in seconds. How do you go across asset classes, say futures (with variable contract sizes) or bitcoin? What about something denominated in a different currency, like DAX futures (denominated in Euro, calculating risk in US dollars)?</p><p><em><strong>Given a reasonable percentage stop of 1&#8211;2%, how do we get a reasonable stop distance, for any instrument, taking into account volatility, contract size, and quote currency?</strong></em></p><p>This article (part one) will be a guide for setting up the framework of the sheet, using a simple AVERAGE as a placeholder metric.</p><p>Exploring other more robust measures of market movement, and better risk parameters will be part two.</p><p>Finally, we&#8217;ll talk about percentage risk in part three (you can get distance and size right, but percentage wrong&#8230; and completely blow up).</p><p><strong>Actual instructions bolded</strong>, everything else is commentary.</p><h3>Step 0.) Set up Sheet</h3><p><strong>Create two tabs, name one &#8220;main&#8221; and the other &#8220;data&#8221;.</strong></p><p><strong>In &#8220;main&#8221;, set up your sheet like this:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wyVU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wyVU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 424w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 848w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 1272w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wyVU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/f055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wyVU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 424w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 848w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 1272w, https://substackcdn.com/image/fetch/$s_!wyVU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff055def7-ee49-4843-aad6-6b3f069db6d8_789x828.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Enter your own values in B1, B2, and <code>=B1*B2</code> in B3.</strong></p><h3>Step 1.) Get data</h3><p>To prototype this I used Google Sheets, with the GOOGLEFINANCE function. GOOGLEFINANCE offers daily data on stocks, forex, and a few cryptocurrencies. GOOGLEFINANCE does not have futures, but they do have a few indices. For assets not covered by GOOGLEFINANCE, we have a workaround to get the data from external sources.</p><p>Entering the following will give you the last 300 closes for EURUSD (just an example):</p><p><code>=GOOGLEFINANCE(&#8220;EURUSD&#8221;, &#8220;close&#8221;, TODAY()-300, TODAY())</code></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!x0JO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!x0JO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 424w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 848w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 1272w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!x0JO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/cf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!x0JO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 424w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 848w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 1272w, https://substackcdn.com/image/fetch/$s_!x0JO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf856091-9cff-43e2-a0e7-d84a6ef4d720_446x247.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>GOOGLEFINANCE doesn&#8217;t have OHLC&#8230; so to get daily change, we take movement from close to close. Using the QUERY function, we shift the data by OFFSET 1 to remove header from our selection, and shift by OFFSET 2 and remove the header and shift by one day. Then we get the difference subtracting one QUERY from the other, inside ARRAYFORMULA:</p><pre><code>=IFERROR(  ARRAYFORMULA(    QUERY(GOOGLEFINANCE("EURUSD","price",TODAY()-300,TODAY()), "SELECT Col2 OFFSET 2", 0)-    QUERY(GOOGLEFINANCE("EURUSD","price",TODAY()-300,TODAY()), "SELECT Col2 OFFSET 1", 0)  ))</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GsNZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GsNZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 424w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 848w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 1272w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GsNZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GsNZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 424w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 848w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 1272w, https://substackcdn.com/image/fetch/$s_!GsNZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F024c670f-6552-4aa4-874b-a5a56f09a29a_800x656.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note GOOGLEFINANCE will give you the close prices over the weekend&#8230; leading to 0&#8217;s every 7 days.</p><p>Let&#8217;s quickly look at the MEAN and MEDIAN:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ied7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ied7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 424w, https://substackcdn.com/image/fetch/$s_!ied7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 848w, https://substackcdn.com/image/fetch/$s_!ied7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 1272w, https://substackcdn.com/image/fetch/$s_!ied7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ied7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/a7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ied7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 424w, https://substackcdn.com/image/fetch/$s_!ied7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 848w, https://substackcdn.com/image/fetch/$s_!ied7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 1272w, https://substackcdn.com/image/fetch/$s_!ied7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7f50de3-1bc4-4b5a-ad96-c06e7ffa65e8_800x186.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The median comes out 0? Must be those duplicate weekend closes. Also, the average looks abnormally small&#8230; 1.7 pips average daily movement for EURUSD. This is because the daily movements are coming out both negative and positive. I knew we said &#8220;quick-and-dirty&#8221;, but this will artificially understate our final number.</p><p>So, we filter out 0 and look at movements as absolute. We do this with IF(close2-close1 &lt;&gt; 0, ABS(close2-close1), &#8220;&#8221;), and wrapping it in an ARRAYFORMULA.</p><pre><code>=IFERROR(   ARRAYFORMULA(     IF(        QUERY(GOOGLEFINANCE("EURUSD", "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 2", 0)-        QUERY(GOOGLEFINANCE("EURUSD", "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 1", 0) &lt;&gt; 0,        ABS(         QUERY(GOOGLEFINANCE("EURUSD", "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 2", 0)-          QUERY(GOOGLEFINANCE("EURUSD", "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 1", 0)       ),       ""     )   ) )</code></pre><p>Looking at the results, this gives us a way less understated amount:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2eK4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2eK4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 424w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 848w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 1272w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2eK4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/7274c784-c491-4cc1-9261-93132bd487fa_752x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2eK4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 424w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 848w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 1272w, https://substackcdn.com/image/fetch/$s_!2eK4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7274c784-c491-4cc1-9261-93132bd487fa_752x390.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Original vs. new average: 1.7 pips / 37 pips</p><p>Original vs. new median: 0 pips / 28 pips</p><p>I would say the new method is much more robust; this <em>roughly </em>checks out to something I&#8217;d want to use.</p><h3>Step 2.) Reshape the sheet</h3><p>Originally, I called all of the data stuff inside the final metric formula. This is cumbersome and inefficient. Eventually, we&#8217;ll want to add many instruments and test out many metrics.</p><p>Let&#8217;s break our data into another tab, then put our final numbers in the main tab.</p><p><strong>Go to &#8220;main&#8221;, and add the instruments you want in A6:A.</strong></p><p><strong>In cell B6, enter the following and drag all the way down:</strong></p><pre><code>=IFNA(GOOGLEFINANCE(A6))</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f-1o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f-1o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 424w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 848w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 1272w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f-1o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f-1o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 424w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 848w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 1272w, https://substackcdn.com/image/fetch/$s_!f-1o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7d4e8111-f295-4eb6-835a-0890945bea41_448x401.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This allows you to check if GOOGLEFINANCE has the data you want.</p><p>Note: There are some instruments you can&#8217;t immediately find on GOOGLEFINANCE, such as ES and NQ futures&#8230; however, if you search S&amp;P 500 or NASDAQ you can find the symbol for the indices&#8230; &#8220;.IXIC&#8221; and &#8220;.INX&#8221;, which is available on GOOGLEFINANCE.</p><p>For anything you can&#8217;t find, you may be able to find externally (see Step 5 below).</p><p><strong>Switch over to &#8220;data&#8221;. Put the following in cell A1:</strong></p><pre><code>=TRANSPOSE(main!A6:A)</code></pre><p>Your list from <code>main!A6:A</code> should populate horizontally.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!12qR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!12qR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 424w, https://substackcdn.com/image/fetch/$s_!12qR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 848w, https://substackcdn.com/image/fetch/$s_!12qR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 1272w, https://substackcdn.com/image/fetch/$s_!12qR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!12qR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!12qR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 424w, https://substackcdn.com/image/fetch/$s_!12qR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 848w, https://substackcdn.com/image/fetch/$s_!12qR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 1272w, https://substackcdn.com/image/fetch/$s_!12qR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0c4abc6e-2b87-47a0-9842-f30c37c4b78c_800x175.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Enter the following in cell A2 and drag all the way to the right:</strong></p><pre><code>=IFERROR(  ARRAYFORMULA(    IF(       QUERY(GOOGLEFINANCE(A1, "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 2", 0)-       QUERY(GOOGLEFINANCE(A1, "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 1", 0) &lt;&gt; 0,       ABS(        QUERY(GOOGLEFINANCE(A1, "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 2", 0)-         QUERY(GOOGLEFINANCE(A1, "price", TODAY()-300, TODAY()), "SELECT Col2 OFFSET 1", 0)      ),       ""    )  ))</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Dk6P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Dk6P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 424w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 848w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 1272w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Dk6P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Dk6P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 424w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 848w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 1272w, https://substackcdn.com/image/fetch/$s_!Dk6P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F458bd706-616b-4a75-adc1-6e90d5f61d0d_800x644.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>*Looking at the data, you can see some instruments are leaving out the weekend gap, while others don&#8217;t (bitcoin). It looks like the ETF (SPY) doesn&#8217;t have the gaps, and GBPJPY doesn&#8217;t (although the other fx pairs do). I&#8217;ll leave this to you to figure out. This is the quick-and-dirty guide, after all.</p><h3>Average the arrays in the main tab</h3><p>Back in our main tab, &#8220;main&#8221;, we take each instrument name, and look up the array from tab &#8220;data&#8221;.</p><p><strong>Enter the following in C6, and drag all the way down:</strong></p><pre><code>=IFNA(AVERAGE(ARRAYFORMULA(IF(data!$1:$1=A6, data!A$6:Z, ))), &#8220;&#8221;)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q5V2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q5V2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 424w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 848w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 1272w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q5V2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/f5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q5V2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 424w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 848w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 1272w, https://substackcdn.com/image/fetch/$s_!Q5V2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5fb0c77-a60c-42ab-b60a-ecdf82444306_545x364.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Step 3.) Standardizing for contract size, denominations, and pip/tick/point size</h3><p>So now we have our framework in place. Ideally, we would be able to just divide our stop value (in $) by our average daily distance (also in $) to get trade size.</p><p>Unfortunately, that will only work for stocks and crypto. If you only trade stocks and crypto, you may skip this part.</p><p>For forex and futures, we will be dealing with different contract sizes and quote currencies. How do we standardize?</p><p><strong>Break this down by adding three more columns to the right: &#8220;Denomination&#8221;, &#8220;Contract Size&#8221;, and &#8220;Daily Movement $&#8221;.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wh3V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wh3V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 424w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 848w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 1272w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wh3V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/dd319656-a963-4e92-91c9-388e3cee2886_800x384.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wh3V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 424w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 848w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 1272w, https://substackcdn.com/image/fetch/$s_!wh3V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd319656-a963-4e92-91c9-388e3cee2886_800x384.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Denomination (or quote currency)</h3><p><strong>Paste the following in E6, and copy down:</strong></p><pre><code>=IF(  A6&lt;&gt;"",   IF(    LEN(A6) &lt;&gt; 6,    1,    IF(      RIGHT(A6, 3) = "USD",       1,       GOOGLEFINANCE(CONCATENATE(RIGHT(A6, 3), "USD"))    )  ),   "")</code></pre><p>Here is what this means in plain English:</p><ul><li><p>If the length of the instrument string is not six, it is probably not forex. So let&#8217;s just use one dollar (1).</p></li><li><p>If the length of the instrument is six, it&#8217;s probably forex or something else. Look at the last three letters of the string to get the quote currency.</p></li><li><p>If the last three letters are &#8220;USD&#8221;, then it&#8217;s denominated in dollars anyway&#8230; so we just use 1.</p></li><li><p>If it is denominated in anything else, we need to find the conversion from that currency to our account currency (the GOOGLEFINANCE(CONCAT()) term).</p></li></ul><p>Could any of these rules potentially break? Sure &#8212; for example, it would not automatically cover ASX 200 futures denominated in Aussie dollars, and would incorrectly denominate those in US dollars. You may add conditions in the formula.</p><p>Also, for our purposes we are dealing with a USD-denominated account.</p><h3>Contract size</h3><p><strong>Look up and enter contract size manually in F6 down.</strong></p><p>Contract size you need to look up and enter manually (this could potentially be broken out into a formula, or scraping futures websites for contract specs&#8230; let me know if you do).</p><p>Here are some rules of thumb:</p><ul><li><p>Forex lots are in 100,000&#8217;s of the quote currency (the last three letters in the pair name)</p></li><li><p>Futures vary&#8230; look them up.</p></li><li><p>For stocks and crypto, one share is one share&#8230; so use 1.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JXQA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JXQA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 424w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 848w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 1272w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JXQA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JXQA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 424w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 848w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 1272w, https://substackcdn.com/image/fetch/$s_!JXQA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8c3c4ea7-838b-4e33-acb0-db54d3bb2fdf_791x430.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Get the dollar value of average daily movement, completely standardized</h3><p>Finally, to get the dollar value of the daily movement of your instrument, just multiply across.</p><p><strong>Enter the following formula in G6, and copy down:</strong></p><pre><code>=IF(A6&lt;&gt;&#8221;&#8221;, C6*E6*F6, )</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yKBB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yKBB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 424w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 848w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 1272w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yKBB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yKBB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 424w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 848w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 1272w, https://substackcdn.com/image/fetch/$s_!yKBB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F898dc94b-edf9-4387-b6aa-10ea034bef8f_800x394.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And finally, to get the size, you divide your stop value in $ / the daily movement to get lot size.</p><p><strong>Put the following in D6 and copy down:</strong></p><pre><code>=IF(A6&lt;&gt;&#8221;&#8221;, $B$3/G6, &#8220;&#8221;)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MOZo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MOZo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 424w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 848w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 1272w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MOZo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/f84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MOZo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 424w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 848w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 1272w, https://substackcdn.com/image/fetch/$s_!MOZo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff84a5044-5d84-480c-8feb-07ee2cfbef66_800x377.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Converting pips to round numbers</h3><p>But wait, there&#8217;s more!</p><p>The purpose of this sheet is to look in one place, and instantly know the stop distance and trade size for your trade.</p><p>For anything not forex, we&#8217;re good to go, but for forex we could clean it up a bit to get round pip numbers.</p><p>Put the following in H6 and copy down:</p><pre><code>=IF(  A6&lt;&gt;"",   IF(    G6=100000,    E6*IF(         RIGHT(A6, 3) = "JPY",          100,          10000       ),     E6  ),  "")</code></pre><p>What this means in plain English:</p><ul><li><p>If your contract size is 100,000, you have a forex pair.</p></li><li><p>If it is a forex pair:</p></li><li><p>If the pair ends in &#8220;JPY&#8221;, multiply the price movement in decimals by 100 to get pips.</p></li><li><p>If the pair ends in anything else, multiply times 10,000 to get pips.</p></li><li><p>Otherwise, the instrument movement is in round dollar numbers, just return the distance column.</p></li></ul><p>*Note this may not apply to exotics, check it out for yourself and let me know if you add any conditions successfully.</p><p><strong>After this step, rename the column &#8220;Pips/Ticks/Points&#8221; to &#8220;Distance&#8221;, and name our new column &#8220;Pips/Ticks/Points&#8221;:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TS1u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TS1u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 424w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 848w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 1272w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TS1u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/a78937c7-7426-4748-9081-331a28799d21_800x491.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TS1u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 424w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 848w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 1272w, https://substackcdn.com/image/fetch/$s_!TS1u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fa78937c7-7426-4748-9081-331a28799d21_800x491.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Step 4.) Styling</h3><p>Now to make the sheet pretty. We want this sheet to instantly tell us stop distance and lot size. Any styling we can do to make it more readable, easier on the eyes, or more accessible helps that goal.</p><p><strong>Drag the columns in the following order: &#8220;Instrument&#8221;, &#8220;Last&#8221;, &#8220;Pips/Ticks/Points&#8221;, and &#8220;Size&#8221;:</strong></p><p><strong>Select all, make font &#8220;Helvetica Neue&#8221;.</strong></p><p><strong>Center everything vertically and horizontally.</strong></p><p><strong>Set everything to font color &#8220;dark gray 3&#8221;.</strong></p><p>Now we want to emphasize the three most important columns, &#8220;Instrument&#8221;, &#8220;Pips/Ticks/Points&#8221;, and &#8220;Size&#8221;.</p><p><strong>Select A6:A, C6:C, and D6:D, set font color to &#8220;dark grey 2&#8221;, and set font size to 18.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jzAe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jzAe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 424w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 848w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 1272w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jzAe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/f75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jzAe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 424w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 848w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 1272w, https://substackcdn.com/image/fetch/$s_!jzAe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff75f90b0-c41d-4156-a68e-99c3cdba8962_800x420.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Finally, select column &#8220;Size&#8221; (D:D).</strong></p><p><strong>Go to &#8220;Format&#8221; &gt; &#8220;Conditional Formatting&#8221; and select &#8220;Color Scale&#8221;.</strong></p><p><strong>Under &#8220;Preview&#8221;, select &#8220;green to yellow to red&#8221;.</strong></p><p><strong>Switch the green with the red.</strong></p><p><strong>Select &#8220;light green 3&#8221;, &#8220;light yellow 2&#8221;, and &#8220;light red 2&#8221;.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8ZGZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 424w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 848w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 1272w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/d540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 424w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 848w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 1272w, https://substackcdn.com/image/fetch/$s_!8ZGZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd540f08c-8b0f-462c-a057-a727ffa70d5c_800x414.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Sorting</h3><p>I like to sort just once*, after we get our preliminary results. It&#8217;s kind of nice to see things in order of volatility.</p><p>*Note: sorting will break down after you add external data. If you come up with an elegant solution to this, let me know.</p><p>In this example, my stuff is already sorted. So I added some instruments to show it out of order.</p><p><strong>Select all rows A5 and down, hit &#8220;Filter&#8221;. Sort by &#8220;Size&#8221;, &#8220;A to Z&#8221;.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2pFi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2pFi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 424w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 848w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 1272w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2pFi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/73a7c13b-f365-4620-8676-b37717d5207f_800x567.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2pFi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 424w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 848w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 1272w, https://substackcdn.com/image/fetch/$s_!2pFi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F73a7c13b-f365-4620-8676-b37717d5207f_800x567.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0UgH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0UgH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 424w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 848w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 1272w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0UgH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/da72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0UgH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 424w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 848w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 1272w, https://substackcdn.com/image/fetch/$s_!0UgH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fda72d9b1-0f84-4d0c-ba05-40ec53dae06a_800x493.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note: This will rearrange your data in the data tab. It will take a while to reload, so use sparingly.</p><p>Now we&#8217;ve got our instruments, sorted by daily volatility, factoring in contract size and pip value. I&#8217;m starting to like this sheet.</p><h3>Step 5.) How to add instruments with no data on GOOGLEFINANCE</h3><p>Despite how freakin&#8217; cool this sheet is thus far, there are a few instruments not listed on GOOGLEFINANCE.</p><p>For example, I&#8217;d like to see gold futures, oil futures, and DAX. For now we&#8217;ll just look at gold and oil.</p><p><strong>Add the symbols &#8220;XAUUSD&#8221; and &#8220;/CL&#8221; in the tab &#8220;main&#8221;. These names are just placeholders, it doesn&#8217;t really matter what you put:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qqj4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qqj4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 424w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 848w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 1272w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qqj4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/d644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Qqj4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 424w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 848w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 1272w, https://substackcdn.com/image/fetch/$s_!Qqj4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fd644fd38-04dc-47a3-a0bf-e86da8f79dbb_800x594.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>To work around this, you will need to go outside GOOGLEFINANCE and find the data somewhere else on the internet. Here, I used &#8220;myfxbook.com&#8221; for XAUUSD:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rwNa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rwNa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 424w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 848w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 1272w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rwNa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/275792f7-f686-401b-9085-60978032161c_800x683.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rwNa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 424w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 848w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 1272w, https://substackcdn.com/image/fetch/$s_!rwNa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F275792f7-f686-401b-9085-60978032161c_800x683.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>In &#8220;data&#8221;, replace GOOGLEFINANCE with IMPORTHTML (table number will differ between sources):</strong></p><pre><code>=IFERROR(  ARRAYFORMULA(    ABS(      QUERY(IMPORTHTML("<a href="https://www.myfxbook.com/en/forex-market/currencies/XAUUSD-historical-data">https://www.myfxbook.com/en/forex-market/currencies/XAUUSD-historical-data</a>", "table", 4), "SELECT Col4 OFFSET 2", 0)-      QUERY(IMPORTHTML("<a href="https://www.myfxbook.com/en/forex-market/currencies/XAUUSD-historical-data">https://www.myfxbook.com/en/forex-market/currencies/XAUUSD-historical-data</a>", "table", 4), "SELECT Col4 OFFSET 1", 0)    )  ))</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OmUc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OmUc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 424w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 848w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 1272w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OmUc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OmUc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 424w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 848w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 1272w, https://substackcdn.com/image/fetch/$s_!OmUc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F50349b17-a1ec-4255-91d9-1408c09c94af_800x459.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>*Note there is only 100 days of data from this source, making it less reliable (but more representative of recent volatility) than our 300 day averages.</p><p>Note that now sorting values in the main tab will break, as this formula is tied to Col I, returning the analytic results for XAUUSD under a different instrument&#8217;s symbol.</p><p>Potentially this could be fixed with a more elaborate formula, or making a separate tab for external data.</p><p><strong>Do the same for /CL in tab &#8220;data&#8221;, with this URL from &#8220;Investing.com&#8221;:</strong></p><pre><code>=IFERROR(  ARRAYFORMULA(    ABS(      QUERY(IMPORTHTML("<a href="https://www.investing.com/commodities/crude-oil-historical-data">https://www.investing.com/commodities/crude-oil-historical-data</a>", "table", 2), "SELECT Col4 OFFSET 2", 0)-      QUERY(IMPORTHTML("<a href="https://www.investing.com/commodities/crude-oil-historical-data">https://www.investing.com/commodities/crude-oil-historical-data</a>", "table", 2), "SELECT Col4 OFFSET 1", 0)     )   ) )</code></pre><p><strong>Head back over to the tab &#8220;main&#8221;, and enter your contract sizes:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cjqS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cjqS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 424w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 848w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 1272w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cjqS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cjqS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 424w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 848w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 1272w, https://substackcdn.com/image/fetch/$s_!cjqS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F517e3b3e-7fd8-49ca-9941-6f08540982d6_800x542.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>*Investing.com only shows past month of data.</p><p>**You could add length of data in &#8220;main&#8221;&#8230; just so you know the reliability and recency. For example, most data from GOOGLEFINANCE will come in around 299 samples. However, the external stuff could be limited to 100 or 30 samples. Actually, you could get external sources with MORE data than GOOGLEFINANCE, and that would be even better.</p><p>If all you wanted was the functional sheet, now you are good to go.</p><p>However, I do not actually use AVERAGE in my own calculations. There are a lot of ways to skin a cat, especially when the cat is making up risk models from scratch in Google Sheets. To be discussed in part 2.</p><p>Again, a disclaimer: we purposely haven&#8217;t discussed what to use as a percentage risk yet. This is just as important as distance and size in your risk management. To be discussed in part 3.</p><p><a href="https://docs.google.com/spreadsheets/d/e/2PACX-1vTl86W7AWmqB0S5kP_TL2FCPPGvkE0adQDnljueoVrcPD7zRaOKfb8gcgaW2_y_Og9VRvyYqzI6edRN/pubhtml">See the sheet results in HTML format here.</a></p><p>Anything I can write about to help you find success in trading? Tell me about it here: <a href="https://bit.ly/3mStNJG">https://bit.ly/3mStNJG</a></p><p>Finally, if you would like the completed sheet to copy for yourself&#8230; <a href="https://samchaaa.github.io/checkout">get it $5 here</a>. On top of that, I will send you any tools, quantitative studies, and algos I come up with in the future (not available to public).</p>]]></content:encoded></item><item><title><![CDATA[Step-by-step guide to run a simple trading algorithm in the cloud using Python, Alpaca, and AWS]]></title><description><![CDATA[The benefits of AWS include billing by usage and a free tier of cloud services, meaning you can get up and running with zero upfront cost!]]></description><link>https://samchaaa.substack.com/p/step-by-step-guide-to-run-a-simple-trading-algorithm-in-the-cloud-using-python-alpaca-and-aws-34c899b678b0</link><guid isPermaLink="false">https://samchaaa.substack.com/p/step-by-step-guide-to-run-a-simple-trading-algorithm-in-the-cloud-using-python-alpaca-and-aws-34c899b678b0</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Tue, 19 Feb 2019 13:06:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uK21!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uK21!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uK21!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 424w, https://substackcdn.com/image/fetch/$s_!uK21!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 848w, https://substackcdn.com/image/fetch/$s_!uK21!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 1272w, https://substackcdn.com/image/fetch/$s_!uK21!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uK21!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uK21!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 424w, https://substackcdn.com/image/fetch/$s_!uK21!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 848w, https://substackcdn.com/image/fetch/$s_!uK21!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 1272w, https://substackcdn.com/image/fetch/$s_!uK21!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0fcec6cb-69b8-4f36-b359-99606975b1f5_800x242.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><h3>Setting up AWS with Python with Alpaca Trade API</h3><p>It is always challenging for a new quant trader to get an algorithm up and running live in the cloud. In my last post, I wrote an instruction for using PythonAnywhere.</p><p>This walkthrough focuses on the basics of setting up AWS with Python, the Alpaca Trade API, and running a basic algorithm.</p><p><strong><a href="https://aws.amazon.com/" title="https://aws.amazon.com/">Amazon Web Services (AWS) - Cloud Computing Services</a></strong><a href="https://aws.amazon.com/" title="https://aws.amazon.com/"><br></a><em><a href="https://aws.amazon.com/" title="https://aws.amazon.com/">Amazon Web Services offers reliable, scalable, and inexpensive cloud computing services. Free to join, pay only for&#8230;</a></em><a href="https://aws.amazon.com/" title="https://aws.amazon.com/">aws.amazon.com</a></p><p><strong><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">Alpaca Documents</a></strong><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/"><br></a><em><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">All about Alpaca.</a></em><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">docs.alpaca.markets</a></p><p>AWS may seem daunting at first, but is well worth the time to get comfortable with. The benefits of AWS include billing by usage and a free tier of cloud services, meaning you can get up and running with zero upfront cost!</p><p>Let&#8217;s jump in with a fresh account.</p><h3>Step 1.) Sign up for AWS.</h3><p><a href="https://aws.amazon.com/">https://aws.amazon.com/</a></p><p>AWS will ask you for a credit card and phone number to verify your account, but you do not need to spend a dime to get started.</p><p>Go to the console sign-in.</p><h3>Step 2.) Launch EC2 instance.</h3><p>When you sign in, &#8220;Launch a virtual machine&#8221; with EC2 on your front page. Click that.</p><p>(Or, search &#8220;EC2&#8221; and click the &#8220;Launch Instance&#8221; button.)</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fx_k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fx_k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 424w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 848w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 1272w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fx_k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fx_k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 424w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 848w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 1272w, https://substackcdn.com/image/fetch/$s_!fx_k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F78e51216-8b54-4c89-9eec-fd4b981b67f0_702x588.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Click the &#8220;Amazon Linux 2 AMI&#8221; free tier eligible option.</p><p>Use the t2.micro free tier eligible and click &#8220;Review and Launch&#8221;.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kcSb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kcSb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 424w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 848w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 1272w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kcSb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/fd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kcSb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 424w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 848w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 1272w, https://substackcdn.com/image/fetch/$s_!kcSb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd428dd0-b16b-4006-81ce-e6dc25094ad6_800x449.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You&#8217;ll get notified to set a security group if this is your first time create a new key pair and download the .pem file. <strong>You&#8217;ll need the path to this file later.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4ah6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4ah6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 424w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 848w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 1272w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4ah6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/b52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4ah6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 424w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 848w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 1272w, https://substackcdn.com/image/fetch/$s_!4ah6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52f3487-a0f7-41aa-861d-8e6d8ab211cc_800x585.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Click &#8220;Launch Instances&#8221;. Click the instance id link on the following page to go to your EC2 instances.</p><h3>Step 3.) SSH to instance from local computer.</h3><p>Your instance will take a bit to initialize, while it&#8217;s doing that, copy your public DNS.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bCfN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bCfN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 424w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 848w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 1272w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bCfN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/2f29ee84-8183-4b06-b680-69378b65e704_800x471.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bCfN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 424w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 848w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 1272w, https://substackcdn.com/image/fetch/$s_!bCfN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2f29ee84-8183-4b06-b680-69378b65e704_800x471.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Open a terminal window (I&#8217;m doing this from Mac OSX) and type the following:</p><pre><code>ssh -i [path to your key here] ec2-user@[your public DNS here]</code></pre><p>My example:</p><pre><code>ssh -i demo_ec2_key.pem ec2-user@ec2&#8211;18&#8211;220&#8211;99&#8211;177.us-east-2.compute.amazonaws.com</code></pre><p>(If you ever use a different image, your log-in may be <code>ubuntu@[yourDNShere]</code>)</p><p>*Some troubleshooting may be required. In this case, my connection was timing out, so I searched &#8220;EC2 timeout&#8221; and found the solution. In my security group, I had to specify port 22 as inbound traffic. This was because I originally skipped the security group step above, by default your security group should include port 22 for inbound traffic.</p><h4><strong>How to fix your key permissions</strong></h4><p>The first time you try to connect, you&#8217;ll probably get &#8220;bad permissions&#8221; as a result:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WEoe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WEoe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 424w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 848w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 1272w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WEoe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WEoe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 424w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 848w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 1272w, https://substackcdn.com/image/fetch/$s_!WEoe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F16e49d7f-59bd-4906-865e-8903034a39b9_800x307.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>All you have to do fix this is run:</p><pre><code>sudo chmod 600 [path to your key]</code></pre><p>Now run the command again. This screen means you did everything correctly:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!16-0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!16-0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 424w, https://substackcdn.com/image/fetch/$s_!16-0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 848w, https://substackcdn.com/image/fetch/$s_!16-0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 1272w, https://substackcdn.com/image/fetch/$s_!16-0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!16-0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!16-0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 424w, https://substackcdn.com/image/fetch/$s_!16-0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 848w, https://substackcdn.com/image/fetch/$s_!16-0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 1272w, https://substackcdn.com/image/fetch/$s_!16-0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F2e613a04-60c4-4c07-a3d4-9353882b9a39_800x191.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Step 4.) Set up Alpaca Trade API.</h3><h4><strong>Step 4A.) Install Python 3</strong></h4><p>Enter <code>python -V</code> to see what version of python you&#8217;re running. By default, I get 2.7. Run the following to install Python3.7:</p><pre><code>sudo yum install python37</code></pre><h4>Step 4B.) Install Alpaca Trade API</h4><pre><code>pip3 install --user alpaca-trade-api</code></pre><p>Now your EC2 instance should be good to go! Keep this window up for later.</p><h3>Step 5.) Copy your algo over to EC2.</h3><p>For this tutorial, we&#8217;ll be running the following sample algorithm. The strategy is a simple EMA crossover, checking a list of stocks every 1 minute.</p><p>Open a new terminal window, and run the following:</p><pre><code>scp -i [path to your key] [path to your algo] ec2-user@[your public DNS]:/~</code></pre><p>My example:</p><pre><code>scp -i demo_ec2_key.pem apca_5min_ema.py ec2-user@ec2&#8211;18&#8211;220&#8211;99&#8211;177.us-east-2.compute.amazonaws.com:~/</code></pre><p>Go over to your original EC2 window, and run <code>ls</code> to check if the upload worked.</p><p>You should see your algorithm listed in the directory. Test it by running <code>python3 apca_5min_ema.py</code>.</p><h3>Step 7.) Closing your terminal without quitting your algo.</h3><h4>Start a new instance of screen</h4><p>In order to keep our algo running without quitting when we disconnect, we can use a handy Linux command, <code>screen</code>. Go ahead and run it.</p><p>This will pop up a new, blank terminal. It&#8217;s actually another window of your terminal. Now run <code>python3 apca_algo.py</code>.</p><p>Hit <strong>CTRL + A + D</strong> to detach the screen and return to your normal terminal.</p><p>Now you can type <code>screen -ls</code> to see your process is still running.</p><p>Typing <code>tail apca_log.log</code> confirms this as well, seeing the results in our log file.</p><p>Hit <strong>CTRL + D</strong> to logout of EC2 altogether.</p><p>Log into your Alpaca account, and confirm your orders are being placed.</p><h4>Reconnecting to your screen</h4><p>To get back to your algo, log into EC2 with SSH.</p><p>Run <code>screen -ls</code> to see what screens are running. You should see something like:</p><pre><code>There is a screen on:     3634.pts-0.ip-172&#8211;31&#8211;34&#8211;247 (Detached)1 Socket in /var/run/screen/S-ec2-user.</code></pre><p>That long screen id is what you&#8217;ll type in next to reconnect:</p><pre><code>screen -r 3634.pts-0.ip-172&#8211;31&#8211;34&#8211;247</code></pre><p>Alternatively, if you just want to quit the screen you can use <code>ps aux | grep apca_5min_algo.py</code> to see the process ID:</p><pre><code>ec2-user 3658 0.1 6.4 427400 65388 pts/1 S+ 22:14 0:00 python3 <strong>apca_5min_ema.py</strong>ec2-user 3726 0.0 0.1 119468 1040 pts/0 S+ 22:20 0:00 grep &#8212; color=auto <strong>apca_5min_ema.py</strong></code></pre><p>Then, you can use <code>screen -XS [process id] quit</code> to quit the screen immediately. My example:</p><pre><code>screen -SX 3658 quit</code></pre><p>Finally, confirm if you&#8217;ve quit your algo with <code>screen -ls</code> .</p><p>There you have it! This should give you a good starting point for spinning up new EC2 instances, navigating AWS, and managing your algorithms.</p><h4>References:</h4><p><strong><a href="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html" title="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html">Step 1: Launch an Amazon EC2 Instance - AWS Quick Start Guide</a></strong><a href="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html" title="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html"><br></a><em><a href="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html" title="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html">Quick start guide to launching an EC2 instance.</a></em><a href="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html" title="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html">docs.aws.amazon.com</a></p><p><strong><a href="https://www.howtoforge.com/linux_screen" title="https://www.howtoforge.com/linux_screen">Linux screen Command: Keep Processes Running Despite a Dropped Connection</a></strong><a href="https://www.howtoforge.com/linux_screen" title="https://www.howtoforge.com/linux_screen"><br></a><em><a href="https://www.howtoforge.com/linux_screen" title="https://www.howtoforge.com/linux_screen">I guess you all know this: you are connected to your server with SSH and in the middle of compiling some software (e.g&#8230;</a></em><a href="https://www.howtoforge.com/linux_screen" title="https://www.howtoforge.com/linux_screen">www.howtoforge.com</a></p><p>Technology and services are offered by AlpacaDB, Inc. Brokerage services are provided by Alpaca Securities LLC (<a href="https://alpaca.markets/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=strategy_list&amp;utm_content=part1">alpaca.markets</a>), member FINRA/SIPC. Alpaca Securities LLC is a wholly-owned subsidiary of AlpacaDB, Inc.</p><p><em><strong>You can find us <a href="https://twitter.com/AlpacaHQ">@AlpacaHQ</a>, if you use twitter.</strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gWV_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gWV_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gWV_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/11af76e7-87db-4be1-9010-de34738b210f_800x39.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gWV_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!gWV_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F11af76e7-87db-4be1-9010-de34738b210f_800x39.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4>Follow <a href="https://medium.com/automation-generation">Automation Generation</a>, a Medium&#8217;s publication created for developers/makers in trading and fintech.</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cFAM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cFAM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cFAM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cFAM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!cFAM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3a5ab168-cda2-4a42-bb7b-51a06d5c128b_800x4.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div>]]></content:encoded></item><item><title><![CDATA[Step-by-step guide to running a simple trading algorithm in the cloud using PythonAnywhere]]></title><description><![CDATA[PythonAnywhere is a nice option because it gives you some manner of GUI for accessing consoles, files, notebooks, and even scheduling tasks]]></description><link>https://samchaaa.substack.com/p/step-by-step-guide-to-running-a-simple-trading-algorithm-in-the-cloud-using-pythonanywhere-bc66835d1521</link><guid isPermaLink="false">https://samchaaa.substack.com/p/step-by-step-guide-to-running-a-simple-trading-algorithm-in-the-cloud-using-pythonanywhere-bc66835d1521</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Thu, 14 Feb 2019 13:06:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JyAR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JyAR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JyAR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 424w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 848w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 1272w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JyAR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/ee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JyAR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 424w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 848w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 1272w, https://substackcdn.com/image/fetch/$s_!JyAR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fee86b2a3-0ba1-43fa-9b39-509210c8619c_800x242.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><h3>Using PythonAnywhere When Running an Algorithm Live in the Cloud</h3><p>After first getting into quant trading and writing algos on your local machine, the biggest area of resistance for newbie quant traders is running an algorithm live in the cloud.</p><p>There are many cloud services on the market, including <strong>AWS</strong>, <strong>Google Cloud</strong>, <strong>Heroku</strong>, <strong>Digital Ocean</strong>, and <strong>PythonAnywhere</strong>. This walkthrough focuses on setting up <strong><a href="https://www.pythonanywhere.com/">PythonAnywhere</a></strong> and running a sample algorithm in Python and the <a href="https://docs.alpaca.markets/">Alpaca Trade API</a>.</p><p><em><strong><a href="https://www.pythonanywhere.com/" title="https://www.pythonanywhere.com/">Host, run, and code Python in the cloud: PythonAnywhere</a></strong></em><a href="https://www.pythonanywhere.com/" title="https://www.pythonanywhere.com/"><br>Host, run, and code Python in the cloud: PythonAnywherewww.pythonanywhere.com</a></p><p><strong><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">Alpaca Documents</a></strong><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/"><br></a><em><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">All about Alpaca.</a></em><a href="https://docs.alpaca.markets/" title="https://docs.alpaca.markets/">docs.alpaca.markets</a></p><p>PythonAnywhere has a free tier of accounts, but only with access to whitelisted URLs. To access the Alpaca endpoints, you will need a paid account ($5/month).</p><p>PythonAnywhere is a nice option because it gives you some manner of GUI for accessing consoles, files, notebooks, and even scheduling tasks that automatically restart if they go down (excellent for algo trading).</p><p>Let&#8217;s jump in with a fresh account.</p><h3>Step 1.) Setting up PythonAnywhere.</h3><p><strong>Step A.) Make a new PythonAnywhere account.</strong></p><p><a href="https://www.pythonanywhere.com/?affiliate_id=003f00f0">https://www.pythonanywhere.com/</a></p><p>You&#8217;re welcomed with a dashboard like below.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!06LX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!06LX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 424w, https://substackcdn.com/image/fetch/$s_!06LX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 848w, https://substackcdn.com/image/fetch/$s_!06LX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 1272w, https://substackcdn.com/image/fetch/$s_!06LX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!06LX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!06LX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 424w, https://substackcdn.com/image/fetch/$s_!06LX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 848w, https://substackcdn.com/image/fetch/$s_!06LX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 1272w, https://substackcdn.com/image/fetch/$s_!06LX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F732bfb44-ae2a-4e69-b187-5a29699881e7_800x521.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Step B.) Install alpaca-trade-api.</strong></p><p>Under &#8220;Consoles&#8221;, open a new Bash console.</p><p>Run the following:</p><pre><code>pip3 install --user alpaca-trade-api</code></pre><h3>Step 2.) Set up algo.</h3><p>Our sample algo for this walkthrough is a simple 5/20 period ema (exponential moving average) crossover on the 5-minute timeframe, checking every 1 minute for signals.</p><p>Upload the algo as a file, or go to &#8220;Open another file&#8221; on the dashboard.</p><p>Enter it as /home/yourusername/algoname.py</p><p>You can run this right from the terminal editor, and see if it works. If you&#8217;re missing any dependencies, install them in the Bash console.</p><p>If the algo runs, you can leave it up and check results in the log file.</p><h3>Step 3.) Set as task.</h3><p>Go to &#8220;Tasks&#8221;, and go down to &#8220;Always On Tasks&#8221;.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qaO1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qaO1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 424w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 848w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 1272w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qaO1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qaO1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 424w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 848w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 1272w, https://substackcdn.com/image/fetch/$s_!qaO1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F797299fa-de4b-4643-95fa-5561da7a0eaa_800x401.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can schedule your algo to automatically restart if it crashes by entering &#8220;python3.6 /home/yourusername/algoname.py&#8221;.</p><p>This works especially well with our sample algo, which dynamically finds the amount of time to sleep until next market open.</p><p>Checking our Alpaca account, using the below as an example, we can see it&#8217;s generating signals about every minute:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T0oI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T0oI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 424w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 848w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 1272w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T0oI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!T0oI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 424w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 848w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 1272w, https://substackcdn.com/image/fetch/$s_!T0oI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8a189a57-c347-415e-8b21-dd3a616a5245_800x771.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>Please note that this example is for illustrative purposes only. Past performance is not indicative of future results.</em></p><p>Technology and services are offered by AlpacaDB, Inc. Brokerage services are provided by Alpaca Securities LLC (<a href="https://alpaca.markets/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=strategy_list&amp;utm_content=part1">alpaca.markets</a>), member FINRA/SIPC. Alpaca Securities LLC is a wholly-owned subsidiary of AlpacaDB, Inc.</p><p><em><strong>You can find us <a href="https://twitter.com/AlpacaHQ">@AlpacaHQ</a>, if you use twitter.</strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WgH1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WgH1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WgH1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/61578874-dbb5-4c52-a103-0a4b51925214_800x39.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WgH1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!WgH1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61578874-dbb5-4c52-a103-0a4b51925214_800x39.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4>Follow <a href="https://medium.com/automation-generation">Automation Generation</a>, a Medium&#8217;s publication created for developers/makers in trading and fintech.</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!loMf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!loMf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!loMf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!loMf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!loMf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!loMf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!loMf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!loMf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!loMf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!loMf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5a490f85-aeeb-4d79-b198-6c4de550a5d2_800x4.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div>]]></content:encoded></item><item><title><![CDATA[Algorithmically Detecting (and Trading) Technical Chart Patterns with Python]]></title><description><![CDATA[Algorithmically trade technical Chart patterns using Python and the Alpaca API.]]></description><link>https://samchaaa.substack.com/p/algorithmically-detecting-and-trading-technical-chart-patterns-with-python-c577b3a396ed</link><guid isPermaLink="false">https://samchaaa.substack.com/p/algorithmically-detecting-and-trading-technical-chart-patterns-with-python-c577b3a396ed</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Thu, 24 Jan 2019 23:39:31 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!FlQ6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FlQ6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FlQ6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 424w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 848w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 1272w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FlQ6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/62636073-b1f5-4477-8307-38771178d547_800x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FlQ6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 424w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 848w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 1272w, https://substackcdn.com/image/fetch/$s_!FlQ6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F62636073-b1f5-4477-8307-38771178d547_800x256.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><h3>Defining Technical Chart Patterns Programmatically</h3><p>Ever wondered how to programmatically define technical patterns in price data?</p><p>At the fundamental level, technical patterns come from local minimum and maximum points in price. From there, the technical patterns may be defined by relative comparisons in these min/max points.</p><p>Let&#8217;s see if we could have played this by algorithmically identifying any inverse head &amp; shoulders patterns!</p><p><a href="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb">Follow along with the notebook here.</a></p><p><strong><a href="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb" title="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb">samchaaa/alpaca_tech_screener</a></strong><a href="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb" title="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb"><br></a><em><a href="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb" title="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb">Contribute to samchaaa/alpaca_tech_screener development by creating an account on GitHub.</a></em><a href="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb" title="https://github.com/samchaaa/alpaca_tech_screener/blob/master/tech_screener_notebook.ipynb">github.com</a></p><p>The following code can easily be retooled to work as a screener, backtester, or trading algo, with any timeframe or patterns you define.</p><p><em>Disclaimer: this code is intended as a starting point for finding technical patterns, it is for educational purposes only. <a href="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis">The framework for this code came from here.</a></em></p><p><strong><a href="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis" title="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis">An Empirical Algorithmic Evaluation of Technical Analysis</a></strong><a href="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis" title="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis"><br></a><em><a href="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis" title="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis">At a recent meeting of the Quantopian staff journal club, I presented a paper by Andrew Lo, Harry Mamaysky, and Jiang&#8230;</a></em><a href="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis" title="https://www.quantopian.com/posts/an-empirical-algorithmic-evaluation-of-technical-analysis">www.quantopian.com</a></p><h3><strong>Step 1.) Read in data</strong></h3><p>I&#8217;m reading in data using the <a href="https://alpaca.markets">Alpaca</a> API (which I&#8217;ll also use to place trades later).</p><p>I wrote this function to grab data beyond the one request limit of 2,000 minute bars. Later we&#8217;ll resample to our timeframe of choice.</p><p>We&#8217;ll resample data separately, in case we want to try out different timeframes later.</p><h3><strong>Step 2.) Find minima and maxima</strong></h3><p>For this step we&#8217;ll use a function from scipy&#8217;s signal processing library to find peaks in the data.</p><p>This code looks complicated, but the point is to return the integer index values with price, for each min/max point.</p><p>Let&#8217;s plot it with the resampled price data to visually confirm we&#8217;re on the right track.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6iO6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6iO6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 424w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 848w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 1272w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6iO6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/fdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6iO6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 424w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 848w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 1272w, https://substackcdn.com/image/fetch/$s_!6iO6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdbdbbb5-3807-4e17-8420-b52b26fd2624_800x522.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3><strong>Step 3.) Find patterns</strong></h3><p>To find patterns, we simply iterate over all our min max points, and find windows where the points meet some pattern criteria.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q6_z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q6_z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 424w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 848w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 1272w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q6_z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/e740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q6_z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 424w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 848w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 1272w, https://substackcdn.com/image/fetch/$s_!Q6_z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe740e5a3-23be-400b-aa72-6bae6724a13b_800x681.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>For example, an inverse head and shoulders can roughly be defined as:</p><p>C &lt; A, B, D, E</p><p>A, E &lt; B, D</p><p>To filter for head and shoulders with even necklines:</p><p>abs(B-D) &lt; np.mean([B, D])*0.05</p><p>(The difference between the necklines must not be more than 5%.)</p><p>Here&#8217;s the code:</p><p>And a plot for visual confirmation:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YnyO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YnyO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 424w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 848w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 1272w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YnyO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/af3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YnyO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 424w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 848w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 1272w, https://substackcdn.com/image/fetch/$s_!YnyO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Faf3aaff4-49d0-4871-a68d-6b6bbe38b06a_800x256.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>As you can see, we are getting more patterns than we need. Our params (smoothing and window range) are too sensitive for this timeframe (60 minutes).</p><h3>Step 4.) Reorganize and iterate to find best params</h3><p>In order to find the best params, I reorganized my code into functions and iterated through multiple stocks, smoothing, and window parameters.</p><p>Run the above like so:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DbN-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DbN-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 424w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 848w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 1272w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DbN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DbN-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 424w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 848w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 1272w, https://substackcdn.com/image/fetch/$s_!DbN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F242afe34-7c68-4bd4-a415-7dd5551dc501_800x819.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Now we can see how our timeframes, patterns, and params are playing out!</p><h3>Step 5.) Go live!</h3><p>To use this live, I made the following changes to screener():</p><pre><code>def screener(stock_data, ema_list, window_list):        triggers = []        all_results = pd.DataFrame()        for stock in stock_data:        prices = stock_data[stock]                for ema_ in ema_list:            for window_ in window_list:                 max_min = get_max_min(prices, smoothing=ema_, window_range=window_)                pat = find_patterns(max_min)                                if len(pat) &gt; 0:                    triggers.append(stock)                    return triggers</code></pre><p>And ran like so:</p><pre><code>stocklist = ['AA', 'AAL', 'AAPL', 'AMZN'] # Long list of stocks here</code></pre><pre><code>stock_data = get_stock_data(stocklist, 2)</code></pre><pre><code>resampled_stock_data = resample(stock_data, '360T')</code></pre><pre><code>ema_list = [5]window_list = [5]</code></pre><pre><code>results = screener(resampled_stock_data, ema_list, window_list)</code></pre><pre><code>for x in results:    api.submit_order(x, 100, 'buy', 'market', 'day')</code></pre><p>Finding the right params for your pattern to play out may take experimentation. See the results() function in the notebook to confirm whether your patterns have a positive edge or not.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SDF-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SDF-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 424w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 848w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 1272w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SDF-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SDF-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 424w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 848w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 1272w, https://substackcdn.com/image/fetch/$s_!SDF-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1e3c97e3-0b67-4611-aba8-18e2c4986455_800x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Technology and services are offered by AlpacaDB, Inc. Brokerage services are provided by Alpaca Securities LLC (<a href="https://alpaca.markets/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=strategy_list&amp;utm_content=part1">alpaca.markets</a>), member FINRA/SIPC. Alpaca Securities LLC is a wholly-owned subsidiary of AlpacaDB, Inc.</p><p><em><strong>You can find us <a href="https://twitter.com/AlpacaHQ">@AlpacaHQ</a>, if you use twitter.</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Easily visualize the correlation of your portfolio in Python]]></title><description><![CDATA[Roll your own stock market visualizations using the Alpaca API with Python]]></description><link>https://samchaaa.substack.com/p/easily-visualize-the-correlation-of-your-portfolio-in-python-alpaca-api-6c381274bcbd</link><guid isPermaLink="false">https://samchaaa.substack.com/p/easily-visualize-the-correlation-of-your-portfolio-in-python-alpaca-api-6c381274bcbd</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Wed, 02 Jan 2019 19:43:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nMEn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nMEn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nMEn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 424w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 848w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 1272w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nMEn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/ff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nMEn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 424w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 848w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 1272w, https://substackcdn.com/image/fetch/$s_!nMEn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fff722bbe-b6c3-48db-95d3-d09668f35c23_800x540.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption"><em>Red = more correlation, green = less correlation</em></figcaption></figure></div><p><em>In this article, I will show how you can make &#8220;roll-your-own&#8221; visualizations, using the <a href="https://docs.alpaca.markets/web-api/">Alpaca API</a> with Python.</em></p><p><em><strong><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">See the final code on GitHub here</a>.</strong></em></p><p><strong><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">samchaaa/alpaca_correlation_viz</a></strong><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb"><br></a><em><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">Contribute to samchaaa/alpaca_correlation_viz development by creating an account on GitHub.</a></em><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">github.com</a></p><h3><em>Visualizing your portfolio correlation by heatmap in Python (jupyter notebook)</em></h3><h3><em>Step 1: Setup</em></h3><p><em>For this tutorial, I used Python 3 in jupyter notebook, some basic libraries, and the Alpaca trade API. Of course, you&#8217;ll need an Alpaca account for the API key as well!</em></p><ol><li><p><em>Get Python 3 + <a href="https://jupyter.readthedocs.io/en/latest/install.html">jupyter notebook</a>. If you&#8217;re not setup with this already, just download Anaconda (it will install everything you need in one go).</em></p></li><li><p><em><a href="https://app.alpaca.markets/signup">Sign up for an Alpaca account.</a> Make note of the API key you get when you sign up.</em></p></li><li><p><em><a href="https://github.com/alpacahq/alpaca-trade-api-python">Install the Alpaca trade API for Python</a>.</em></p></li></ol><p><em>Once you have a fresh notebook started, here are the imports you&#8217;ll need:</em></p><pre><code><em>import pandas as pd</em></code></pre><pre><code><em>import matplotlib.pyplot as plt</em></code></pre><pre><code><em>import seaborn as sns</em></code></pre><pre><code><em>import alpaca_trade_api as tradeapi</em></code></pre><pre><code><em># Makes output higher resolution.</em></code></pre><pre><code><em>%config InlineBackend.figure_format = &#8216;retina&#8217;</em></code></pre><p><em>To sign into your Alpaca account, initialize REST with the API key you got at signup:</em></p><pre><code><em># Paper trade log-in</em></code></pre><pre><code><em>api = tradeapi.REST(&#8216;YOUR_API_KEY_HERE&#8217;,</em></code></pre><pre><code><em>                    &#8216;YOUR_SECRET_CODE_HERE&#8217;,</em></code></pre><pre><code><em>                    &#8216;https://paper-api.alpaca.markets')</em></code></pre><p><em>*Note the endpoint (&#8216;https://paper-api.alpaca.markets') will be different for live trading.</em></p><h3><em>Step 2: Get account positions.</em></h3><p><em>If you&#8217;ve already started paper trading and have positions on, you can call these with:</em></p><pre><code><em>api.list_positions()</em></code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XqKY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XqKY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 424w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 848w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 1272w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XqKY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XqKY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 424w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 848w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 1272w, https://substackcdn.com/image/fetch/$s_!XqKY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F9d4f4889-24d9-4807-aa04-2933e3ce1ff1_800x557.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>If you&#8217;re working with a fresh account, submit some fresh orders like so:</em></p><pre><code><em>api.submit_order(&#8216;SNAP&#8217;, 100, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;SLV&#8217;, 100, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;JNJ&#8217;, 100, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;AAPL&#8217;, 10, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;GLD&#8217;, 100, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;GOOG&#8217;, 1, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;CAT&#8217;, 100, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><pre><code><em>api.submit_order(&#8216;EWZ&#8217;, 10, &#8216;buy&#8217;, &#8216;market&#8217;, &#8216;day&#8217;)</em></code></pre><p><em>To request our data, we just need a list of the symbol of each security:</em></p><pre><code><em>pos_list = [x.symbol for x in api.list_positions()]</em></code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3sTn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3sTn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 424w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 848w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 1272w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3sTn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/f6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3sTn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 424w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 848w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 1272w, https://substackcdn.com/image/fetch/$s_!3sTn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6553d83-d0f2-4390-a42b-48a6b2a7df69_800x185.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3><em>Step 3: Get data.</em></h3><p><em>Alpaca has several methods of requesting data. Learn more <a href="https://docs.alpaca.markets/web-api/market-data/">here</a>.</em></p><p><em>The short version is, if you sign up with a paper trading account, you may only access data from the IEX exchange.</em></p><p><em>If you have a live account, you may access IEX and full-volume data from Polygon. Polygon includes quotes, bars, fundamentals, and volume data (both historical and real-time) from all exchanges. This is extremely valuable!</em></p><p><em>This distinction is only important if you&#8217;re doing more demanding trading strategies. For our purposes, we only need the daily close of each security.</em></p><p><em>We&#8217;ll do this by requesting a &#8220;barset&#8221; object for each symbol:</em></p><pre><code><em>def get_bars(symbol):</em></code></pre><pre><code><em>     data = api.get_barset(symbol, &#8216;day&#8217;, limit=1000)</em></code></pre><pre><code><em>     data = data.df[symbol][&#8216;close&#8217;]</em></code></pre><pre><code><em>     return data</em></code></pre><p><em>We&#8217;ll call this later, within our next step.</em></p><h3><em>Step 4: Get correlations.</em></h3><p><em>Here&#8217;s our code for getting all the correlations within our portfolio:</em></p><pre><code><em>def correlation(equity_list):          df = pd.DataFrame()    equity_columns = []        # Get symbol history    for symbol in equity_list:           try:            symbol_df = get_bars(symbol)            df = pd.concat([df, symbol_df], axis=1)            equity_columns.append(symbol)        except:            print('Exception with {}'.format(symbol))                df.columns = equity_columns        # Get correlation and sort by sum    sum_corr = df.corr().sum().sort_values(ascending=True).index.values        return df[sum_corr].corr()</em></code></pre><p><em>For each equity in our portfolio, we call <strong>get_bars()</strong>, then concatenate the results to our dataframe.</em></p><p><em>The results of this step alone would return a df like this:</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sCnK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sCnK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 424w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 848w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 1272w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sCnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sCnK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 424w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 848w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 1272w, https://substackcdn.com/image/fetch/$s_!sCnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F57abc030-9124-4a5e-b843-d2a33d818b56_800x566.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>(<strong>equity_columns</strong> collects the symbols we&#8217;ve successfully requested, so we don&#8217;t get a mismatch with the df later.)</em></p><p><em>Calling <strong>.corr()</strong> returns a dataframe with the correlation coefficient (Pearson&#8217;s correlation, by default) of each symbol. It looks like this:</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XWoo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XWoo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 424w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 848w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 1272w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XWoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XWoo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 424w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 848w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 1272w, https://substackcdn.com/image/fetch/$s_!XWoo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F21730c63-074f-4080-91d1-4c7a7628e2d5_800x298.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em><strong>Note if you&#8217;re not familiar with correlations:</strong> Correlation coefficients range from (-1, 1). A positive value means two things move together, and a negative value that they move opposite. A value close to zero is &#8220;weak&#8221;, meaning there is no correlation, and a value close to -1 or +1 is &#8220;strong&#8221;.</em></p><p><em>For better visual organization, sort symbols by total correlation* by summing the correlation df and sorting:</em></p><pre><code><em>sum_corr = df.corr().sum().sort_values(ascending=True).index.values</em></code></pre><p><em>This returns a list of symbols, from least to most correlated.</em></p><p><em>Calling <strong>df.corr()</strong> again with this list sorts it by summed correlation:</em></p><pre><code><em>return df[sum_corr].corr()</em></code></pre><h3><em>Step 5: Plot heatmap.</em></h3><p><em>Finally, the easiest step:</em></p><pre><code><em>plt.figure(figsize=(13, 8))</em></code></pre><pre><code><em>sns.heatmap(correlation(pos_list), annot=True, cmap=&#8221;Greens&#8221;);</em></code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mjDY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mjDY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 424w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 848w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 1272w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mjDY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/ad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mjDY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 424w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 848w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 1272w, https://substackcdn.com/image/fetch/$s_!mjDY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fad9e91f0-20d4-4e7b-bb5b-a0b4b28aa9bb_800x555.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em><strong>plt.figure()</strong> sets our figure size nice and big.</em></p><p><em><strong>sns.heatmap()</strong> plots colors along a linear colormap. Calling annot adds numerical values, cmap defines your color scheme.</em></p><p><em>(I&#8217;m a fan of &#8220;RdYlGn_r&#8221;, &#8220;summer_r&#8221;, &#8220;Blues&#8221;, and &#8220;Greens&#8221;.)</em></p><h3><em>Further Steps and Ideas</em></h3><p><em>Thanks for reading! <a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">See the final code here</a>.</em></p><p><strong><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">samchaaa/alpaca_correlation_viz</a></strong><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb"><br></a><em><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">Contribute to samchaaa/alpaca_correlation_viz development by creating an account on GitHub.</a></em><a href="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb" title="https://github.com/samchaaa/alpaca_correlation_viz/blob/master/notebook.ipynb">github.com</a></p><ul><li><p><em>For each position, return the top three least correlated S&amp;P100 stocks.</em></p></li><li><p><em>Hedge 5% of each position with least correlated stocks.</em></p></li><li><p><em>Find rolling correlation over time (divergence strategies!)</em></p></li><li><p><em>Scale heatmap to position size and volatility.</em></p></li></ul><h3><em>Notes</em></h3><p><em>*On sorting overall correlation by summing correlations:</em></p><p><em>Isn&#8217;t this disregarding data (due to +/- coefficients canceling each other out)?</em></p><p><em>In a way, yes. An alternative approach is summing the absolute values of the correlation coefficients:</em></p><pre><code><em># Get correlation and sort by sum</em></code></pre><pre><code><em>sum_corr = abs(df.corr()).sum().sort_values(ascending=True).index.values</em></code></pre><pre><code><em>df[sum_corr].corr()</em></code></pre><p><em>However, this method is also disregarding data &#8212; the direction of the correlation coefficient.</em></p><p><em>Here is a comparison of results using both methods (with a larger portfolio):</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WdQE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WdQE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 424w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 848w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 1272w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WdQE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/078e343d-f804-40e6-b949-16d015230bd3_600x806.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WdQE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 424w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 848w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 1272w, https://substackcdn.com/image/fetch/$s_!WdQE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F078e343d-f804-40e6-b949-16d015230bd3_600x806.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em><strong>As you can see, using the absolute method is visually smoother.</strong> For example, sorting normally (negative coefs cancelling positive), some assets such as EWZ or GS get moved further down the list, even though they have greater strengths of coefficients.</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cTtP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cTtP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 424w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 848w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 1272w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cTtP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/b15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cTtP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 424w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 848w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 1272w, https://substackcdn.com/image/fetch/$s_!cTtP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15d04d9-3f04-4cdb-bb6b-5e5a5afc9d45_600x800.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>As another example, using the normal method SNAP gets sorted all the way to the left. It is the top least correlated. However, using the absolute method its strength of correlation is actually in the middle.</em></p><p><em>Overall the method you use should depend on which metric you care more about: strength of correlation, strength and direction, or having a visually smooth heatmap.</em></p><h3><em>Resources</em></h3><p><em><a href="https://docs.alpaca.markets/web-api/">Alpaca Documentation &#8212; Web API</a></em></p><p><em><a href="https://docs.alpaca.markets/getting-started/tutorials/python/">Alpaca Documentation &#8212; Getting Started Sample Algorithm</a></em></p><p><em><a href="https://github.com/alpacahq/alpaca-trade-api-python">Alpaca Trade API Documentation</a></em></p><p><em><strong>Why did I use Alpaca API?</strong></em></p><p><em>As a trader, I&#8217;m really stoked about <a href="https://alpaca.markets">Alpaca</a>.</em></p><p><em>At the time of this writing, no other platform offers live trading, backtesting, accurate market data, or commission-free trading &#8212; all in one place.</em></p><p><em>Unlike other trading platforms out there, Alpaca not only offers an API for backtesting and live trading, but also brokerage services through Alpaca Securities LLC, meaning they can fill your trades (for free!) in the same ecosystem.</em></p><p><em>The catch? You must be (at least barely) code-literate. Beside the online dashboard, Alpaca has no GUI features.</em></p><p><em>The benefits, however, are endless. Essentially Alpaca&#8217;s API is a tool for building whatever you want- backtesting, live trading, paper trading, or even <a href="https://medium.com/automation-generation/buying-and-selling-stocks-from-the-command-line-5b4dd5628078">entering trades from the command line</a> or <a href="https://medium.com/automation-generation/manage-your-stocks-from-google-spreadsheet-using-api-43026db44289">Google Sheets</a> (!).</em></p><p>Technology and services are offered by AlpacaDB, Inc. Brokerage services are provided by Alpaca Securities LLC (<a href="https://alpaca.markets/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=strategy_list&amp;utm_content=part1">alpaca.markets</a>), member FINRA/SIPC. Alpaca Securities LLC is a wholly-owned subsidiary of AlpacaDB, Inc.</p><p><em><strong>You can find us <a href="https://twitter.com/AlpacaHQ">@AlpacaHQ</a>, if you use twitter.</strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aWGy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aWGy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aWGy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/b27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aWGy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 424w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 848w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 1272w, https://substackcdn.com/image/fetch/$s_!aWGy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27663d7-8eaf-45b0-bb79-700eafc6a864_800x39.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4>Follow <a href="https://medium.com/automation-generation">Automation Generation</a>, a Medium&#8217;s publication created for developers/makers in trading and fintech.</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ky8f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ky8f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ky8f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ky8f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 424w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 848w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 1272w, https://substackcdn.com/image/fetch/$s_!ky8f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F541d93d7-7ae4-4762-a0fe-3a2c68a7ac13_800x4.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div>]]></content:encoded></item><item><title><![CDATA[How to implement a basic trading algorithm in QuantConnect using Python (for data scientists)]]></title><description><![CDATA[Code adapted from https://www.quantopian.com/posts/simple-machine-learning-example-mk-ii.]]></description><link>https://samchaaa.substack.com/p/how-to-implement-a-basic-trading-algorithm-in-quantconnect-using-python-for-data-scientists-a786292e949c</link><guid isPermaLink="false">https://samchaaa.substack.com/p/how-to-implement-a-basic-trading-algorithm-in-quantconnect-using-python-for-data-scientists-a786292e949c</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Thu, 18 Oct 2018 21:34:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Gq97!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Code adapted from <a href="https://www.quantopian.com/posts/simple-machine-learning-example-mk-ii">https://www.quantopian.com/posts/simple-machine-learning-example-mk-ii</a>.</em></p><p>Ever wondered how to apply your machine learning/data science skills to algorithmic trading?</p><p>If you already know Python and basic statistical principles of data science (like train-test-split, over-fitting, etc), you&#8217;re already way ahead of the curve.</p><p>Translating machine learning models into trading algorithms is pretty simple, once you know some of the quirks of how data is handled and executed in these environments.</p><p>Let&#8217;s look at a super-basic machine learning model (adapted to QuantConnect from the Quantopian platform).</p><p><a href="https://www.quantconnect.com/">Go here to make an account for QuantConnect.</a></p><p><a href="https://www.quantconnect.com/terminal/processCache/?request=embedded_backtest_ff2c9a9eed50b57ed48319daf0534b1e.html">See the code, backtest, and stats here.</a></p><h3>1. Get imports</h3><pre><code>import numpy as npfrom sklearn.ensemble import GradientBoostingRegressor</code></pre><h3>2. Understand the basic QuantConnect structure</h3><p>Here&#8217;s a code skeleton of our algo:</p><pre><code>class SimpleML(QCAlgorithm):</code></pre><pre><code>    def Initialize(self):          # Set settings here.        # Instantiate variables here.        # Schedule events here.</code></pre><pre><code>    def OnData(self, data):</code></pre><pre><code>        # Handle data live.                def scheduled_event(self):                # Scheduled event function.</code></pre><p>In platforms like QuantConnect and Quantopian, algos are structured in classes. This is where you set your settings, instantiate variables, and schedule other functions you want to run.</p><h3>3. Settings</h3><p>Let&#8217;s fill out the def Initialize(self) part.</p><pre><code>def Initialize(self):</code></pre><pre><code>    self.SetStartDate(2018,1,1)    self.SetEndDate(2018,9,1)    self.SetCash(100000)    self.AddEquity('AMZN', Resolution.Daily)            self.model = GradientBoostingRegressor()            self.lookback = 30    self.history_range = 200            self.X = []    self.y = []            self.Schedule.On(self.DateRules.WeekStart(), self.TimeRules.BeforeMarketClose('AMZN', minutes=10), Action(self.create_model))</code></pre><pre><code>    self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('AMZN', minutes=1), Action(self.trade))</code></pre><ul><li><p><strong>self.SetStartDate()</strong>: The start date of backtest (YYYY, MM, DD).</p></li><li><p><strong>self.SetEndDate()</strong>: The end date of backtest (YYYY, MM, DD).</p></li><li><p><strong>self.SetCash(100000)</strong>: How much cash to trade.</p></li><li><p><strong>self.AddEquity(&#8216;AMZN&#8217;, Resolution.Daily)</strong>: Add any instruments we want data on, as well as the resolution. <a href="https://www.quantconnect.com/docs/data-library/equity">More on adding instruments in QuantConnect&#8217;s documentation.</a></p></li><li><p><strong>self.model</strong>: Instantiate our model.</p></li><li><p><strong>self.lookback</strong>: Number of past samples to train on.</p></li><li><p><strong>self.history_range</strong>: Range of history we&#8217;ll train on.</p></li><li><p><strong>self.X</strong>: Empty list for our features (in this case, past returns).</p></li><li><p><strong>self.y</strong>: Empty list for target (the next day&#8217;s return).</p></li><li><p><strong>self.Schedule.On()</strong>: This is how we call functions we&#8217;ve defined.</p></li></ul><p>Note we&#8217;re calling our create_model function on the first trading day of the week, 10 minutes before close. Then we predict and trade off the model each day 10 minutes after open.</p><h3>4. OnData</h3><p>OnData handles live data for the algo. This is only used if your algo is executing on a lower timeframe (like HTF algorithms). We won&#8217;t need this because we&#8217;re only fitting and trading once per day.</p><pre><code>def OnData(self, data):        pass</code></pre><h3>5. Write modeling function</h3><p>This part should look familiar. The important thing here is knowing how to read in past price data.</p><pre><code>def create_model(self):            recent_prices = self.History(['AMZN'], self.history_range)['close'].values</code></pre><pre><code>    price_changes = np.diff(recent_prices).tolist()            for i in range(self.history_range-self.lookback-1):        self.X.append(price_changes[i:i+self.lookback])        self.y.append(price_changes[i+self.lookback])                self.model.fit(self.X, self.y)</code></pre><ul><li><p><strong>recent_prices = self.History()</strong>: This is how we call in past data for whatever instruments we added at the top of the algo. This will return a dataframe of open, high, low, and close for bid and ask, plus volume over the timeframe you specify. Selecting [&#8216;close&#8217;] selects just the close of each day. (Remember, we specified Resolution.Daily at the top.)</p></li><li><p><strong>price_changes = np.diff(recent_prices).to_list()</strong>: We&#8217;ll be predicting off the percentage price changes, from daily close to daily close. (If we wanted to be more statistically sound, we&#8217;d use the log returns, but let&#8217;s keep it simple for now.)</p></li><li><p><strong>for loop</strong>: For each day in our history, our X will be the number of days in our look back. The y will be the return for that day. We loop through the number of days in history, less the lookback (so we don&#8217;t run out of room!).</p></li><li><p><strong>Fit the model.</strong></p></li></ul><h3><strong>6. Write trade execution</strong></h3><p>Last part!</p><pre><code>def trade(self):            if len(self.y) &gt; self.lookback:                    recent_prices = self.History(['AMZN'], self.lookback+1)['close'].values        price_changes = np.diff(recent_prices)                    prediction = self.model.predict(price_changes.reshape(1, -1))                    if prediction &gt; 0:            self.SetHoldings('AMZN', 1.0)        else:            self.SetHoldings('AMZN', 0)</code></pre><ul><li><p><strong>if len(self.y) &gt; self.lookback: </strong>This is a check to make sure our y is at least the amount of our lookback.</p></li><li><p><strong>prediction</strong>: Predict using our model, feeding in the most recent price changes.</p></li></ul><p>If our prediction is positive, we go all-in! If not, we&#8217;re flat.</p><h3>Results:</h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Gq97!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Gq97!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 424w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 848w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 1272w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Gq97!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/4fc0757c-5d23-449a-942d-3442339ed827_800x562.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Gq97!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 424w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 848w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 1272w, https://substackcdn.com/image/fetch/$s_!Gq97!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc0757c-5d23-449a-942d-3442339ed827_800x562.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Here&#8217;s a look at our results on the QuantConnect platform. While it beats the market, you would have made +72% buy-and-hold AMZN during this time.</p><h3>Complete code:</h3><pre><code>import numpy as npfrom sklearn.ensemble import GradientBoostingRegressor# Adapted from https://www.quantopian.com/posts/simple-machine-learning-example-mk-iiclass SimpleML(QCAlgorithm):      def Initialize(self):          self.SetStartDate(2018,1,1)        self.SetEndDate(2018,9,1)        self.SetCash(100000)        self.AddEquity('AMZN', Resolution.Daily)                self.model = GradientBoostingRegressor()                self.lookback = 30        self.history_range = 200                self.X = []        self.y = []                self.Schedule.On(self.DateRules.WeekStart(), self.TimeRules.BeforeMarketClose('AMZN', minutes=10), Action(self.create_model))        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('AMZN', minutes=1), Action(self.trade))    def OnData(self, data):        pass                def create_model(self):                recent_prices = self.History(['AMZN'], self.history_range)['close'].values        price_changes = np.diff(recent_prices).tolist()                for i in range(self.history_range-self.lookback-1):            self.X.append(price_changes[i:i+self.lookback])            self.y.append(price_changes[i+self.lookback])                    self.model.fit(self.X, self.y)        def trade(self):                if len(self.y) &gt; self.lookback:                        recent_prices = self.History(['AMZN'], self.lookback+1)['close'].values            price_changes = np.diff(recent_prices)                        prediction = self.model.predict(price_changes.reshape(1, -1))                        if prediction &gt; 0:                self.SetHoldings('AMZN', 1.0)            else:                self.SetHoldings('AMZN', 0)</code></pre><p>Anything I can write about to help you find success in data science or trading? Tell me about it here: <a href="https://bit.ly/3mStNJG">https://bit.ly/3mStNJG</a></p>]]></content:encoded></item><item><title><![CDATA[How to plot two different scales on one plot in matplotlib (with legend)]]></title><description><![CDATA[Here&#8217;s a breakdown of how this works:]]></description><link>https://samchaaa.substack.com/p/how-to-plot-two-different-scales-on-one-plot-in-matplotlib-with-legend-46554ba5915a</link><guid isPermaLink="false">https://samchaaa.substack.com/p/how-to-plot-two-different-scales-on-one-plot-in-matplotlib-with-legend-46554ba5915a</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Wed, 17 Oct 2018 16:52:47 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SwbG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SwbG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SwbG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 424w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 848w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 1272w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SwbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SwbG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 424w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 848w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 1272w, https://substackcdn.com/image/fetch/$s_!SwbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc135f6-7f7c-421d-878a-3a1ccaf03a65_800x505.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><pre><code># Plot two lines with different scales on the same plot</code></pre><pre><code>fig = plt.figure(figsize=(8, 5))</code></pre><pre><code>line_weight = 3alpha = .5</code></pre><pre><code>ax1 = fig.add_axes([0, 0, 1, 1])ax2 = fig.add_axes()</code></pre><pre><code># This is the magic that joins the x-axisax2 = ax1.twinx()</code></pre><pre><code>lns1 = ax1.plot(wnv3['mosq'], color='blue', lw=line_weight, alpha=alpha, label='Mosquitos')lns2 = ax2.plot(wnv3['wnv'], color='orange', lw=line_weight, alpha=alpha, label='Westnile')</code></pre><pre><code># Solution for having two legendsleg = lns1 + lns2labs = [l.get_label() for l in leg]ax1.legend(leg, labs, loc=0)</code></pre><pre><code>plt.title('Cumulative yearly mosquito &amp; West Nile levels', fontsize=20)        plt.show()</code></pre><p>Here&#8217;s a breakdown of how this works:</p><pre><code>ax2 = ax1.twinx()</code></pre><p>The magic of the graph is the <strong>.twinx() </strong>element, which makes the new axis share the old axes x-axis, but keeps an independent y-axis.</p><pre><code># Solution for having two legendsleg = lns1 + lns2labs = [l.get_label() for l in leg]ax1.legend(leg, labs, loc=0)</code></pre><p>One difficulty with this is creating a legend with both labels. There is no default way to do this, and calling two .legends() will result in one legend being on top of the other.</p><p>One solution is to set different loc variables in .legend(), but this looks too annoying.</p><p>Thanks to <a href="https://stackoverflow.com/questions/5484922/secondary-axis-with-twinx-how-to-add-to-legend">this StackOverflow thread</a>, we have the above solution to getting everything onto one legend.</p><p>Anything I can write about to help you find success in data science or trading? Tell me about it here: <a href="https://bit.ly/3mStNJG">https://bit.ly/3mStNJG</a></p>]]></content:encoded></item><item><title><![CDATA[Jupyter Notebook Hacks For Cleaner, Simpler Notebooks]]></title><description><![CDATA[1.) Make your plot settings &#8220;sticky&#8221;]]></description><link>https://samchaaa.substack.com/p/jupyter-notebook-hacks-for-cleaner-simpler-notebooks-2e088b8407f3</link><guid isPermaLink="false">https://samchaaa.substack.com/p/jupyter-notebook-hacks-for-cleaner-simpler-notebooks-2e088b8407f3</guid><dc:creator><![CDATA[samchaaa]]></dc:creator><pubDate>Fri, 05 Oct 2018 20:29:29 GMT</pubDate><content:encoded><![CDATA[<h3>1.) Make your plot settings &#8220;sticky&#8221;</h3><p>Typing the same command more than two times is annoying. Run this at the top of your notebook to set a default size for your matplotlib plots:</p><pre><code>matplotlib.rcParams[&#8216;figure.figsize&#8217;] = (13,8)</code></pre><p>You can also use this for other matplotlib settings like so:</p><pre><code>matplotlib.rcParams['lines.linewidth'] = 2matplotlib.rcParams['lines.color'] = 'r'</code></pre><p>Or group them together:</p><pre><code>matplotlib.rc('lines', linewidth=2, color='r')</code></pre><p>(From <a href="https://matplotlib.org/users/customizing.html">matplotlib &#8212; Customizing matplotlib</a>)</p><p>What does &#8220;rc&#8221; stand for? <a href="https://en.wikipedia.org/wiki/Run_commands">Apparently the suffix stands for &#8220;run command&#8221; and is a &#8220;fossil&#8221; in UNIX systems from CTSS, invented in the 1960's</a>.</p><h3>2.) Make your Jupyter Notebook wider</h3><pre><code>from IPython.core.display import display, HTML</code></pre><pre><code>display(HTML(&#8220;&lt;style&gt;.container { width:80% !important; }&lt;/style&gt;&#8221;))</code></pre><p>Why waste all that wonderful space?</p><h3>3.) Make your plots higher resolution</h3><pre><code>%config InlineBackend.figure_format = &#8216;retina&#8217;</code></pre><h3>4.) Link to other notebooks</h3><pre><code># In Markdown cell:</code></pre><pre><code>[Link text here](&#8216;/path/notebook.ipynb&#8217;)</code></pre><p>This goes a long way in organizing notebooks, so you don&#8217;t have to scroll through a bunch of DataFrame printouts to get to your fancy graphs at the end.</p><h3>6.) Present your Notebook as slides</h3><pre><code>!jupyter nbconvert this_notebook.ipynb --to slides --post serve</code></pre><p>Go to View &gt; Cell Toolbar &gt; Slideshow to group your cells into slides. This will allow you to arrow through slides once it is in the presentation.</p><p><strong>My default settings:</strong></p><p>I just run this at the top of every notebook.</p><pre><code>import matplotlib</code></pre><pre><code>matplotlib.rcParams['figure.figsize'] = (13,8)</code></pre><pre><code>%config InlineBackend.figure_format = 'retina'</code></pre><p>Anything I can write about to help you find success in data science or trading? Tell me about it here: <a href="https://bit.ly/3mStNJG">https://bit.ly/3mStNJG</a></p>]]></content:encoded></item></channel></rss>