<?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 Caroline Okun on Medium]]></title>
        <description><![CDATA[Stories by Caroline Okun on Medium]]></description>
        <link>https://medium.com/@caroline.e.okun?source=rss-2b3beb9118a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nRaj6OQAHYs4IxLuULjDdw.jpeg</url>
            <title>Stories by Caroline Okun on Medium</title>
            <link>https://medium.com/@caroline.e.okun?source=rss-2b3beb9118a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:29:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@caroline.e.okun/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[Read This if You’re Using Passport for Authentication]]></title>
            <link>https://medium.com/@caroline.e.okun/read-this-if-youre-using-passport-for-authentication-188d00968f1b?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/188d00968f1b</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[passport]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Fri, 11 Aug 2017 03:59:49 GMT</pubDate>
            <atom:updated>2018-09-10T13:43:54.556Z</atom:updated>
            <content:encoded><![CDATA[<p>I was using Passport for authentication on my latest project. Login and register worked fine and when I signed out, req.user would log on my server as null. Yet, when I logged out and refreshed the page, req.user would be repopulated with the user from my previous session. My /logout route, copied from the Passport documentation had the code:</p><pre>router.get(&#39;/logout&#39;, function(req, res) {<br>   req.logout();<br>});</pre><p>I first tried force deleting the session with req.session.destroy.</p><pre>router.get(&#39;/logout&#39;, function(req, res) {<br>   req.logout();</pre><pre>   req.session.destroy(function (err) {<br>   if (err) {<br>     return next(err);<br>   }<br>   return res.send({ success: true });<br>   });<br>});</pre><p>This did the same thing as before, momentarily clearing req.user, but repopulating it on refresh.</p><p>I also read a few posts that said clearing your terminal would solve the issue, but my login still persisted.</p><p>After line by line console.log statements and a lot of failed attempts to clear req.user from Passport’s memory, the following code finally worked (specifically the line resave: false ).</p><pre>app.use(session(<br> {<br>   secret: process.env.SECRET,<br>   store: new MongoStore({mongooseConnection: mongoose.connection}),<br>   saveUninitialized: false,<br>   resave: false<br> }<br>));</pre><p>It turns out you have to specify that you want to clear the session from memory. If you leave out these config options, you will see cookies regenerated on subsequent requests in the browser after clearing the cookies.</p><p>The default value for resave is true. The best way to know if this is necessary for your store is to check if it implements the touch method. If it does, then you can safely set resave: false. If it does not implement the touch method and your store sets an expiration date on stored sessions, then you likely need resave: true.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=188d00968f1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Mastering Git]]></title>
            <link>https://medium.com/@caroline.e.okun/a-guide-to-mastering-git-ce91ae05ed03?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce91ae05ed03</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Tue, 08 Aug 2017 15:55:51 GMT</pubDate>
            <atom:updated>2017-08-10T02:04:22.817Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>What is Git?</strong></h4><p>Git is a distributed version control system. A version control system records changes to files over time so that you reference specific states of the file later. Distributed means every copy of the codebase has the same functionality (no central authority necessary). GitHub is a central authority designed to simplify using Git, but you can still use Git without it! To review the basics of Git before getting started, checkout <a href="http://learngitbranching.js.org/">this tutorial</a>.</p><h4>Commits and Branches</h4><p>A commit is a snapshot of the repo at some point in time. Each commit is identified by a hash and represents any changes made to the files that came before it. A branch is an independent line of development with a movable label attached to a single commit. To sign off of a commit, type:</p><pre>$ git commit -sm &lt;&quot;SOME COMMIT MESSAGE&quot;&gt;<br></pre><pre>//a normal commit message would be</pre><pre>$ git commit -m &lt;&quot;SOME COMMIT MESSAGE&quot;&gt;</pre><h4>The HEAD</h4><p>Every clone of the repo has a unique HEAD which points to the current commit. HEAD^ points to the parent of the current commit and HEAD^^ points to the parent of HEAD^. To go back to the previous commit, run one of the following commands in terminal, where &lt;COMMIT_HASH&gt; is the hash of target commit.</p><pre>$ git reset --hard HEAD^</pre><pre>$ git reset --hard &lt;COMMIT_HASH&gt;</pre><p>The previous commands allow you to look at a previous commit without changing where HEAD points to. This means you’ll have something called a “detached HEAD”, you won’t be on a branch and your previous branch will still point to the same commit. If you commit here the commit will not be attached to any branch. To create a branch pointing to this commit, type:</p><pre>$ git branch &lt;SOME_BRANCH_NAME&gt; &lt;COMMIT_HASH&gt;</pre><p>To access commit hashes, type</p><pre>$ git reflog</pre><p>to print a list of all the commits HEAD has pointed to. After viewing the old commits, type</p><pre>$ git checkout YOUR_BRANCH</pre><p>to navigate back to your branch.</p><h4>Adding Changes</h4><p>To add all your changes:</p><pre>$ git add --all</pre><p>To add just the changes from your current directory:</p><pre>$ git add .</pre><h4>Creating a New Branch</h4><p>To create a new branch and move HEAD to it:</p><pre>$ git checkout -b SOME_BRANCH</pre><p>To create new branch without moving HEAD:</p><pre>$ git branch NEW_BRANCH</pre><h4>Merging</h4><p>Merging adds changes from a target branch to the current branch. To add your personal commits to master:</p><pre>$ git checkout master<br>$ git merge &lt;YOUR_BRANCH&gt;</pre><p>There are two types of merging: merge commits and fast-forward merging. <strong>Merge commits</strong> create a new commit that represents the merged state. This commit will have two parents at this time, the two merged branches.</p><p><strong>Fast-forward</strong> merging occurs when when a target branch is the child of the current branch or vice-versa. In this case, git will move HEAD to the later commit without creating a new commit.</p><h4>Rewriting History</h4><p>You can ‘rewrite’ history using rebase commands. Rebase changes the base of a commit by taking a divergent situation and linearizing history. Below is an example of rebasing.</p><pre>//add on the changes to the end of master&#39;s branch (merge conflicts will have to be settled during the rebase not the merge)</pre><pre>$ git rebase master<br></pre><pre>//git merge master is now a fast-forward merge</pre><pre>$ git merge master</pre><p>Many open source projects prefer fast-forward merging, so rebasing is how you would avoid merge commits.</p><h4>Git Pull</h4><p>Running git pull is the same thing as running $ git fetch followed by $ git merge.</p><pre>$ git pull = $ git fetch + $ git merge</pre><p>Git fetch copies all the commits from the remote repository and git merge merges the commits. If the local repo and the remote repo have diverged the git pull command will result in a merge commit.</p><h4>Git Push</h4><p>Git push merges changes from a local repository to a remote repository. <strong>Note that</strong> git push won’t work if your local branch isn’t up to date because it only permits fast-forward commits. Remote repositories are often shared, so be deliberate about non-safe merge operations. To avoid merge commits, type:</p><pre>$ git pull --rebase</pre><p>If you want to keep your changes locally but are not ready to push them, commit and don’t push! Your changes will still be saved.</p><h4>Takeaways</h4><ul><li>Git history is a series of commits</li><li>Branches are pointers to commits (like sticky notes you can move around with $ git branch)</li><li>You can switch branches with $ git checkout</li><li>Merging branches usually creates a new commit with two parents</li><li>Fast-forward merges are when the target branch is a child (i.e. ancestor) of the current branch</li><li>Rebase: rewrite history so it is flat (i.e. no merge commits with multiple parents)</li><li>Pull: merge from remote to local</li><li>Push: merge from local to remote (Non-fast-forward merges disallowed for safety)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce91ae05ed03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is LoopBack and should I use it?]]></title>
            <link>https://medium.com/@caroline.e.okun/what-is-loopback-and-should-i-use-it-850207fac319?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/850207fac319</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[loopback]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[express]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Wed, 02 Aug 2017 04:17:17 GMT</pubDate>
            <atom:updated>2017-08-02T04:17:17.047Z</atom:updated>
            <content:encoded><![CDATA[<p>LoopBack is an open-source Node.js framework intended to facilititate creating dynamic end-to-end REST APIs. It has almost 10,000 stars on github right now so I decided to explore it this weekend while building a ML React platform. My team spent around six hours diving into the documentation and implementing our LoopBack server, although ultimately we decided to trade it in for the classic express server we knew and loved. While the framework didn’t happen to work great for our use case, it had some interesting tools that I would definitely consider worth exploring. LoopBack moves the majority of the setup and creation of your server to the command line. This makes creating models and connecting them to your database incredibly simple. You can have a REST API up and running with only a few lb model commands. Extending and linking models and defining access controls can also be done from the command line. All you have to do is answer a few questions and the interface will translate your responses into code. For example, to implement access controls you will be prompted with the following questions after running the command lb acl.</p><pre>? Select the model to apply the ACL entry to:<br>? Select the ACL scope:<br>? Select the access type:<br>? Select the role:<br>? Select the permission to apply:</pre><p>The parts of LoopBack built into its command-line interface are actually great to use. My biggest problem with LoopBack came when I was moving away from the command line and attempting to familiarize myself with the output of the auto-generated API. Because the API was all coded from the command line, I didn’t have the same understanding of my code that I usually do with a generic express server. Personally I would rather paste in a template than do everything from the command line, because I like to know what is happening in my code and what is changing. When we went on to add middleware and custom routes, the custom routes were rather straightforward but I found implementing the middleware to be overcomplicated. There are two options for adding middleware. The first includes going into the server/middleware.json file and adding to the JSON object. The second option is adding a :after or :before route to your server/server.js file as shown below.</p><pre>app.middleware(‘routes:before’, morgan(‘dev’));</pre><p>While neither of these methods are very complicated, they leave me missing the simplicity of app.use() and for me, I think this was the biggest drawback of the interface.</p><p>On the other hand, my favorite part of the LoopBack was definitely the remote hooks. A remote hook is a function that gets executed before or after a remote method (either a custom remote method or a built-in CRUD method). LoopBack made it incredibly easy to add remote hooks to our API like the example shown below where the hook adds on a date to every instance of the Review model.</p><pre>module.exports = function(Review) {<br>  Review.beforeRemote(‘create’, function(context, user, next) {<br>     context.args.data.date = Date.now();<br>     context.args.data.publisherId = context.req.accessToken.userId;<br>     next();<br>  });<br>};</pre><p>Personally I am not yet sold on LoopBack, mostly because I’m very hands on when it comes to coding and I like to type everything out. However, if you don’t mind being a little removed, its definitely worth checking out some of its features <a href="http://loopback.io/doc/index.html">here</a>. This <a href="http://loopback.io/doc/en/lb3/Getting-started-with-LoopBack.html">LoopBack tutorial</a> is also a great introduction into the interface and I would definitely recommend running through the example API if you’re interested.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=850207fac319" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the best library for making AJAX calls?]]></title>
            <link>https://medium.com/@caroline.e.okun/what-is-the-best-library-for-making-ajax-calls-c979b00e7984?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c979b00e7984</guid>
            <category><![CDATA[ajax]]></category>
            <category><![CDATA[axios]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 20:19:49 GMT</pubDate>
            <atom:updated>2017-07-28T20:19:49.211Z</atom:updated>
            <content:encoded><![CDATA[<h4>comparing and contrasting axios, request, and fetch</h4><p>I’ve been searching around for the answer to this question for a while so I decided to put some real research into it and this is what I’ve found. If you’re looking for a quick one word answer, I would recommend axios. That said, there’s definitely an argument for each of these options and hopefully this article will help you pick your personal favorite.</p><h3><strong>Fetch</strong></h3><p>Below is the syntax for a common fetch call. Note that when making a fetch call, we first get back a response object containing type, useFinalURL, url, status, ok, statusText, and headers. To get the actual data we have to call response.text() or response.json() depending on the format of the data we’re receiving.</p><pre>fetch(url)<br>.then(response =&gt; response.json())<br>.then(data =&gt; console.log(data));</pre><p>Fetch, the newest ajax library, is a standardized API implemented with the intention of replacing XMLHttpRequests and unifying fetching across the web. While fetch is a very nice API to use because of its simple syntax, it lacks some of the staple characteristics of more developed libraries such as canceling requests. Fetch also doesn’t haven’t have built-in mechanisms to override defaults so credentials, mode, and headers will all have to be specified with each request. While this is may not be an issue in smaller applications, its definitely something to consider when building a larger scale project where your calls take similar specifications. However, in my opinion, the largest drawback to fetch is the way it handles errors. Fetch rejects the promise only in case of network error so when server returns 404, we actually receive “success” as the response. To more effectively check for errors we would have to write something like:</p><pre>fetch(url)<br>.then(response =&gt; {<br>   return response.json().then(data =&gt; {<br>      if (response.ok) {<br>         return data;<br>      } else {<br>         return Promise.reject({status: response.status, data});<br>      }<br>   });<br>})<br>.then(result =&gt; console.log(‘success:’, result))<br>.catch(error =&gt; console.log(‘error:’, error));</pre><p>Nevertheless, fetch is an overall popular choice because of its accessiblity and readability, especially in projects with less demanding/frequent API calls. The library uses concise syntax, is promise based, and is supported in React Native apps, unlike axios and request.</p><h3><strong>Axios</strong></h3><p>Axios setup requires a quick npm install axios and you’re ready to go. Axios is a promise based library that is supported in all browsers, while fetch is only supported in Chrome and Firefox. Like fetch and request it uses concise syntax with easy to read documentation. A basic axios get request would look like:</p><pre>axios.get(‘/’)<br>.then(function (response) {<br>   console.log(response);<br>})<br>.catch(function (error) {<br>   console.log(error);<br>});</pre><p>Unlike fetch, the catch block will be triggered on all errors and the data is stored on the response object at response.data. Although axios is not supported in React Native, I have found it to be a great option in many other use cases such as web and desktop apps.</p><h3><strong>Request</strong></h3><p>Like axios, to set up request, run npm install request. Request is structured a bit differently than axios and fetch. The library is not promise based (however request-promise is an easy to use wrapper that returns promises), and instead it emits a “response” event when a response is received. Similarly, to listen for errors, simply replace “response” with “error”. An example request call would be:</p><pre>request<br>.get(‘http://google.com/img.png&#39;)<br>.on(‘response’, function(response) {<br>   console.log(response)<br>})</pre><p>Request can also pipe to itself. For example:</p><pre>request.get(‘http://google.com/img.png&#39;)<br>.pipe(request.put(&#39;http://mysite.com/img.png&#39;))</pre><p>The .pipe() function preserves content-length and content-type in the PUT headers and chains on another request call.</p><h3>So which should I use?</h3><p>In the end, there is no real right or wrong answer to the posed question. These three libraries, are for the most part, slightly different configurations of the same functionality. I personally find axios to be the most readable and easiest to use, but all would be suitable for your classic web app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c979b00e7984" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Date-a-baes: A Dating App For Hackers]]></title>
            <link>https://medium.com/@caroline.e.okun/date-a-baes-a-dating-app-for-hackers-40d6d31e665f?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/40d6d31e665f</guid>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 02:23:18 GMT</pubDate>
            <atom:updated>2017-07-28T02:30:59.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*ryIzcFjRSy8F35XiR3JWJQ.png" /></figure><p>I’m in San Francisco this summer at a twelve-week coding boot camp called Horizons School of Technology. Horizons hosted a hackathon two weeks ago where my team and I built a dating app for hackers called date-a-baes. Check out their post about it <a href="https://blog.joinhorizons.com/how-penn-horizonites-built-a-tinder-clone-and-biometric-authentication-software-in-just-24-hours-331243674f40">here</a>!</p><p>I’d never been in a hackathon before so I knew little about the intensity of a 24 hour coding session. At the start of the day, the first challenge we faced was coming up with this idea. We were looking for something that would be interesting and educational while still being fun. Once we had an idea, we were faced with the challenge of execution. We mapped out the user interface and scale of our app, and decided two of us would work on technical development while our third partner designed the UI. My assignment was to develop the technical functionality from the React Redux front-end to the back-end database connections. Prior to the hackathon, we had a one-day introduction to mobile development using React Native and I became obsessed and spent the rest of the week teaching myself how to create mobile apps. If you’re looking for an awesome React Native tutorial, I highly recommend <a href="https://www.udemy.com/the-complete-react-native-and-redux-course/learn/v4/overview">Stephen Grider’s Advanced React and Redux course</a>.</p><p>Three days into my mobile app education, however, even with a solid background in web development, a full-scale dating app was definitely a challenge. The two biggest hurdles were choosing and implementing a database to facilitate a live chat feature, and creating swiping cards so users could browse for potential matches. Before touching code, I researched web sockets and how to link action listeners to a realtime database. We ended up using <a href="https://firebase.google.com/">Firebase</a>, which runs in the cloud and includes identity management, realtime data views and a document database, everything we needed to build our app. This research definitely paid off and we didn’t run into nearly as many debugging issues down the line as many other groups. Because the swiping cards are a very popular feature on apps such as Tinder and Bumble, I suspected there would be boilerplates that would save some serious coding time. After scanning projects on GitHub to see what dependencies people were using, I was able to easily piece together my own implementation of the swiping cards with almost no issues. You can play around with an example <a href="https://github.com/meteor-factory/react-native-tinder-swipe-cards">here</a>! I learned a lot about the value of understanding and utilizing available resources to build a project in the best and most efficient way. Our project overall was focused on personal development and I definitely came away with a lot of new knowledge and understanding of mobile applications. Last week that we learned we won the prize for best design! Thanks to an awesome team I had a great first hackathon experience. And we haven’t stopped working so definitely keep your eye out for the deployment of our app!</p><p><a href="https://drive.google.com/file/d/0B9wU6uBDDQJ_RnJsQ0t3Wm5qcFE/view">dateabaes.mov</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40d6d31e665f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Technical Deep Dive Into the Jane Street ETC]]></title>
            <link>https://medium.com/@caroline.e.okun/a-technical-deep-dive-into-the-jane-street-etc-20a801974378?source=rss-2b3beb9118a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/20a801974378</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <dc:creator><![CDATA[Caroline Okun]]></dc:creator>
            <pubDate>Thu, 27 Jul 2017 05:25:35 GMT</pubDate>
            <atom:updated>2017-07-27T05:25:35.051Z</atom:updated>
            <content:encoded><![CDATA[<h4>Coauthored with <a href="https://medium.com/u/5d65f4223a9a">Ben Hubsch</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*V986YHbne3KYfDrMivQSyw.jpeg" /></figure><p><em>This past weekend,</em> our team <em>participated in Jane Street’s Electronic Trading Competition, a day-long programming contest where teams </em>competed<em> against each other in a simulated market. Contestants wrote algorithms to trade various financial instruments such as bonds, stocks, ETFs, and ADRs, with the intention of maximizing</em><strong><em> </em></strong><em>profit. The competition was structured into five minute rounds, each simulating one day in the market. During the first competition, teams traded and built up their portfolio for ten hours. In the last hour, portfolios were reset, allowing teams to compete in a second competition with the best version of their bots. In this latter competition, we developed algorithms that placed us 2nd out of 44 teams.</em></p><p>At the start of the day, our first order of business was getting our development and competition environment set up on our machines. The competition was hosted using the Amazon EC2 Cloud, where the automated exchange would run. None of us had experience coding in an Ubuntu Linux virtual box, so before we had the opportunity to dive into the algorithms, one of our challenges was getting ourselves connected to the server and ready to trade. We ultimately established a TCP connection using JSON protocol by passing in the IP address of the exchange to a socket function inside our bot. We then wrote code locally on our personal computers, pushed to Github, and pulled those changes into the virtual box, where we were able to run our files. We chose this flow because we were most comfortable developing locally, and we set up aliases for the most common git commands to avoid wasting time — efficiency was crucial.</p><p>The one critical decision we had to make pre-competition was what programming language to use. We decided on Python because of its simple syntax: we didn’t have to worry about the verbosity of declaring variables, and our code was more succinct than it would have been in a non-scripting language. Because of its inherent readability, it was suitable for use in a group with team members from varying technical backgrounds. Also, its extensive libraries simplified implementation and allowed us to focus on the logic of our algorithms. Nevertheless, we encountered two problematic setbacks in the form of complex server errors.</p><p>The first error resulted in a loss of connection to the marketplace and an error message of “broken pipe”. We commented out various chunks of code, realizing that it had to do with the frequency with which we were placing orders. Since we were reading the state of the book one line at a time (as per the JSON TCP client protocol) and placing orders at a constant rate directly after, the number of messages being sent to us increased at an exponential rate, ultimately bogging down the server to the point where it crashed. We reconciled this by placing orders at randomized frequency, instead of every time we read from the market. The second error logged “connection refused by peer”. It occurred to us while reviewing the writeup Jane Street provided, that we were making requests too frequently to the server. This was fixed by sleeping our program for 0.01 seconds every time we placed a trade.</p><p>Once we were connected to the server, we wrote our first algorithm to trade bonds with a simple penny-pinching strategy. Because not many people were trading yet, this strategy did relatively well for the first two hours of the competition, keeping us at 7th place.</p><p>After we had solidified our bond algorithm, we needed a more profitable strategy, so we moved on to analyzing American Depository Receipts (ADRs). Our first approach was to average the book’s buy and sell price for the liquid stock and trade the illiquid ADR at a margin of ±15 USD. We added a global counter to avoid placing any trades before analyzing at least 200 buy and sell prices. However, we later realized our counter was being incremented in our infinite while loop,which resulted in us placing trades too soon at values well outside the fair market. Additionally, we should have been analyzing the price of the trades executed and not all the buy and sell offers placed on the book.We seemed to be making no progress with this strategy, so in an attempt to debug our logic, we added more structure to our code to track and output the status of our assets, which showed us we were making no trades. Although now more informed, we were slowly slipping down the leaderboard as more teams joined the competition with better strategies than our bond trading.</p><p>Around five hours in, we hit rock bottom. We found ourselves ranked at 23rd and steadily slipping without a source of income. At this point, our team stepped back to rehash our strategy. We decided to do a serious overhaul of this algorithm and start over with a new way to analyze the ADRs. This time, we targeted the price of the illiquid ADR using the most recent trade price of the liquid ADR. Trade prices are a much more reliable measure of a stock’s true market value than the book’s offers, and because the liquid stock is less volatile in price, its value is a good estimate of the illiquid ADR’s value. If we had more time, we would have averaged the past five trade prices, but we wanted to get our new algorithm running. Also, we knew the liquid stock’s value was only fluctuating within a few dollars, and our margin was larger than that. We placed trades on the book for the liquid ADR with a smarter margin of ±10 USD, knowing no trades went through while using the wider margin. Additionally, we incorporated hedging to keep our assets more stable, so every time we made a trade we then converted back to the illiquid ADR. Once this was all implemented, we ran our algorithm in the test server. Seeing one successful round, we let it fly in the production market. With this new strategy, our Profit and Loss (PnL) was 1,000 USD per round, a promising turn of events following our previous downslide. Because of the conversion fee, we quickly refactored our algorithm to only convert back and forth when we had either bought or sold 10 units of the liquid ADR. At this point we had a steady PnL of around 2,000 USD, so we decided to move on to a more advanced third algorithm and tackle the ETFs.</p><p>The ETF held bonds and three different stocks all at different quantities and all liquid than the ETF itself. Our strategy started off fairly similar to our previous one with the ADRs, except now we were valuing the ETF using a bundle of stocks as opposed to just one. As before, we valued the three stocks using their most recent trade price, which we updated each time one of these was traded. Once we had valued all the stocks, we estimated the price of the ETF and placed trades with a margin of ±30 USD. We used a wider margin here because of the greater volatility we observed with the ETF. We deployed this strategy to production after seeing success in the test market, which resulted in a steady PnL of roughly 7,000 USD, our best result yet. With this last algorithm, we quickly climbed up the ranks to seventh place before the end of the first competition. If we had more time, we would have liked to try out trading with a smaller margin and converting back to the liquid stocks and bonds. For the second competition, Jane Street cleared the leaderboard, and we started off strong as 1st of 44 teams. We were making a sizable and steady profit, but towards the end, the team behind us gained ground due to their penny-pinching strategy. During the last five-minute round, they surpassed us. As a last-gasp effort to keep our place, we changed our margin but ended the game with a lower PnL and second place in the competition. Nevertheless, given that a few hours earlier we were scrapping our code, second place was a thrill and a great end to a long day.</p><p>The competition was a great introduction into algorithmic trading and an opportunity to learn a new real-world technical application for computer science. We had the chance to familiarize ourselves with new technologies like virtual boxes, debug puzzling scenarios, and explore the logic behind an untried discipline. Definitely worth <strong>investing</strong> our time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20a801974378" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>