<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Christian Dittmeier on Medium]]></title>
        <description><![CDATA[Stories by Christian Dittmeier on Medium]]></description>
        <link>https://medium.com/@christiangdittmeier?source=rss-f911738b93c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0YK-xV9iQ_JnFlH8DuLglg.jpeg</url>
            <title>Stories by Christian Dittmeier on Medium</title>
            <link>https://medium.com/@christiangdittmeier?source=rss-f911738b93c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:40:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christiangdittmeier/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I used R to automate my RobinHood portfolio. Unfortunately, It keeps buying J.C. Penney.]]></title>
            <link>https://medium.com/@christiangdittmeier/i-automated-my-robinhood-account-using-an-r-script-that-randomly-buys-and-sells-cheap-stocks-c93b18a1c04c?source=rss-f911738b93c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c93b18a1c04c</guid>
            <category><![CDATA[robinhood-app]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Christian Dittmeier]]></dc:creator>
            <pubDate>Wed, 10 Apr 2019 16:06:48 GMT</pubDate>
            <atom:updated>2024-06-17T22:24:05.993Z</atom:updated>
            <content:encoded><![CDATA[<h3>I automated my Robinhood account using an R script that randomly buys and sells cheap stocks. Unfortunately, it keeps buying JCPenney.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*tq0XH6hsS4GKBy9CFgdb-w.png" /></figure><p>While RobinHood has not released an official public API, there are few wrappers out there for the private API found <a href="https://github.com/sanko/Robinhood">here on GitHub</a> by sanko. I stumbled on a <a href="https://github.com/JestonBlu">R package</a> recently published on CRAN by user JestonBlu and found that it already had enough functionality to automate my RobinHood account.</p><p>I want to add a quick disclaimer to this post by clearly stating that <strong>I know next to nothing about investing, I am not a broker, dealer, or investment advisor, and I am not in any sense giving financial investment advise nor am I recommending that you take any of the steps listed below</strong>. I hope to simply share my experience using the RobinHood R package.</p><p>Also want to plug the <a href="https://github.com/moldach/vapoRwave">vapoRware</a> package by moldach, which I used to style the visualization in this post.</p><h3>Getting Started:</h3><p>Here are the packages I used in this project that can be installed using the install.packages() function, as well as some instructions for getting started in the RobinHood API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfbb872c6176dd165db8329f0bb3608e/href">https://medium.com/media/dfbb872c6176dd165db8329f0bb3608e/href</a></iframe><p>Note that you just enter your username and password as strings if you care less about security. Reference the keyringr documentation for instructions on how to set up a login on your OS if needed.</p><h3>The Strategy:</h3><p>I decided to start off by buying all non-pharma (other) stocks under $5 in the “Popular Stocks under $25” RobinHood collection. After logging in using the code listed above, I did that by running this command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c78c22b2ca326e374e020319476ee0e9/href">https://medium.com/media/c78c22b2ca326e374e020319476ee0e9/href</a></iframe><p>Note that I didn’t include this in the script I automated — this was simply used to buy stocks for the script to evaluate daily (I did use a variant of this to trigger a buy of one random stock when the account value rose a certain amount in one day).</p><p>The poor man’s “strategy” I used in the daily script evaluates the 12 shares I purchased using the code above and future buys. It does the following:</p><ol><li>Checks the total return of each share</li><li>If the return is above -5% and below 15%, do nothing (hold)</li><li>If the return is above 15% or below -15%, sell the share</li><li>If the share is between -5% and -15%, randomly decide to either sell the share or buy another</li></ol><p>Because I have other shares in the account that are not being evaluated, I left a small amount of cash in the account and added a 5th rule:</p><p>5. If the total account value increases more than $10 in one day, buy another non “pharma-other” stock from the “most popular under $25&quot; collection.</p><p>While these aren’t the most sophisticated or wise triggers, I thought it would be a good starting point as I anticipated there would be enough events to set off transactions nearly daily (which has been the case so far — thanks JCP).</p><h3>The Resulting Transactions (so far)</h3><p>I’ll include the full script in the next section and the method used to automate the script, but I wanted to quickly include the transactions the script has made so far:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dg63WMLLLB9S4BZ1o5-SMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFKg0syDe-p-rDBS-kyFJg.png" /><figcaption>*Starbucks sale was manually triggered</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbP7evO8vIgusY84937zyQ.png" /></figure><p>Other than selling WFT and RAD, and buying an additional share of AKS, the script has yet to do anything so far other than blessing me with 7 shares of the red-hot department store, J.C. Penney’s.</p><h3>The Script</h3><p>Here is the script in it’s entirety. While much of it could most likely be shortened and better explained, so far it has done a good enough job of bolstering my position in Penney’s (we are on a nickname basis now, right?) for me to lose motivation in improving it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd6d2c68c7bdd29ec2f023509444a135/href">https://medium.com/media/bd6d2c68c7bdd29ec2f023509444a135/href</a></iframe><h3>Automation and Conclusion</h3><p>I used this <a href="https://www.r-bloggers.com/how-to-source-an-r-script-automatically-on-a-mac-using-automator-and-ical/">post by Pass the ROC</a> to set up an iCal event to run the script every day at 9:45AM. There are more intuitive automation techniques on Windows using the taskscheduleR package.</p><p>As far as final remarks, I’d like to thank JestonBlu on GitHub for creating and actively improving the RobinHood package — providing a useful interface to the API in R. Looking forward to seeing stock option functionality so that I can do some serious damage to my finances, all within RStudio.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c93b18a1c04c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>