R + Quandl Dollar Vs Commodities correlations

The opportunity set for itself DXY had a major pump and the correlation between the dollar and commodities is unparalleled.

Correlations are a major tool on a traders belt and if you know a little of R here is a notebook that will give you the correlation between DXY and all major Commodity futures.

You just need to sign up for a Quandl account and get your free API key

You can find the code on my GitHub:

Quandl and Python CoT report

This week I will show you how to extract the CoT report data to an excel using Python and Quandl.

Fist of all, you will need to sign up to Quandl. Quandl is a Freemium quote provider.

Go to https://www.quandl.com/ and create your free account.

After you create your account you will need to get your private API Key

Just click on your account menu and your API Key will be displayed under the “Profile” tab.

If you don’t have Python installed on your machine I would recommend installing it via Anaconda.

Before getting into the code, just one last step. You will need to install the Python package for Quandl.

just run the command “pip install Quandl” on your console.

The code snippet is very big, so I will just post the link to the bitbucket Snippet.

In case you have any question just leave a comment or DM me on Twitter.

Download Stocks quotes using R and AlphaVantage

Let´s start by covering the basics.

What you need:


  • In case you are installing for the first time or doing a fresh install, I would recommend to install both R and RStudio in different folders inside the “C:\” directory.
  • Another recommendation, (not required) install everything using Anaconda. Anaconda is a built in suite for Quant and data analysis. It´s easy to use, install and maintain. From the Anaconda ecosystem you can install python, orange and others awesome tools. https://www.anaconda.com/distribution/

Now to the subject at hand. There are a few different ways to retrieve stock data. Some paid, some free, some fast, some slow. Today we will focus on AlphaVantage (https://www.alphavantage.co/)

Let´s start by claiming your free API Key:

You will have to fill a small form and no payment is required, It´s free:


AlphaVantage API Form

As all things free, it comes with limitations.

API free restrictions

Now Let´s bring up our Rstudio

To run our code, we will need to basic packages:

  • alphavantager to connect to AlphaVantage API
  • xlsx to export our data to excel/csv

Let´s start by installing the packages:



RStudio packages installation

Now we are set to go, let´s go right into the code:

Let´s start by initializing the libraries



Replace “YOUR_API_KEY” with the API key you registered above


We can retrieve data from AlphaVantage with different timeframes:

#Daily data
quoteData <- av_get(
  symbol = "AAPL",
  av_fun = "TIME_SERIES_DAILY",
  outputsize = "full"

#Hourly data
quoteData <- av_get(
  symbol = "AAPL",
  interval = "60min",
  outputsize = "full"

The Symbol is the ticker you want to retrieve. If you have any doubts or don´t know the ticker for the company, just try searching for it on yahoo finance ( https://finance.yahoo.com/) the ticker is exactly the same.

Finally, in order to export to excel you need to define where you want to save it and how you want to name the file

write.xlsx(quoteData, "C:\\Folder\\SymbolName.xlsx",sheetName = "Daily data")

Here is the full code snippet


If you have any question, just leave a comment.