How to Run Python from R Studio

Modern data science is fundamentally multi-lingual. At a minimum, most data scientists are comfortable working in R, Python and SQL; many add Java and/or Scala to their toolkit, and it’s not uncommon to also know one’s way around JavaScript. Personally, I prefer to use R for data analysis. But, until recently, I’d tend to reach …

Read more

Financial Data Manipulation in dplyr for Quant Traders

In this post, we’re going to show how a quant trader can manipulate stock price data using the dplyr R package. Getting set up and loading data Load the dplyr package via the tidyverse package. if (!require(‘tidyverse’)) install.packages(‘tidyverse’) library(tidyverse) First, load some price data. energystockprices.RDS contains a data frame of daily price observations for 3 …

Read more

Get Rich Quick Trading Strategies (and why they don’t work)

Every aspiring millionaire who comes to the markets armed with some programming ability has implemented a systematic Get Rich Quick (GRQ) trading strategy. Of course, they don’t work. Deep down even the greenest of newbies knows this. Yet, still, we are compelled to give them a try, just once, just for fun (or so we …

Read more

How To Get Historical S&P 500 Constituents Data For Free

spx constituents historical mean return

In this post, we are going to construct snapshots of historic S&P 500 index constituents, from freely available data on the internet. Why? Well, one of the biggest challenges in looking for opportunities amongst a broad universe of stocks is choosing what stock “universe” to look at. One approach to dealing with this is to …

Read more

How to Hedge a Portfolio with Put Options

There are 2 good reasons to buy put options: because you think they are cheap because you want downside protection. In the latter case, you are looking to use the skewed payoff profile of the put option to protect a portfolio against large downside moves without capping your upside too much. The first requires a …

Read more

Pairs Trading Literature Review

This post summarises the key lessons of the academic literature that has been published on pairs trading.  The key themes are highlighted at the end of the page. Pair Trading Literature Review Gatev, Goetzmann, Rouwenhorst – “Pairs Trading: Performance of a Relative Value Arbitrage Strategy” https://papers.ssrn.com/sol3/papers.cfm?abstract_id=141615 This is the first meaningful academic paper on pair …

Read more

Using Apache Airflow to Extract CoT Data

In today’s post we are going to be extracting CoT (Commitment of Traders) reports from the CFTC website using a pipeline built on Apache Airflow. What is CoT data? The CoT report is a weekly publication which reports the open positions of market participants in the U.S futures market. It’s published every Friday at 3:30 …

Read more