Using python and dtale to analyze correlations

I can´t say this enough times, correlations matter and correlations are in deed a traders best friend.

Correlations are very useful but very hard to plot without some code knowledge. Fortunately the guys that made dtale are life savers.
https://github.com/man-group/dtale
dtatle is a library that allows you to manipulate data, you can re-order it, plot it, export it, etc.

Today I will share with you a simple way to plot ETF correlations.
For starters you should go to my shared content and download the spreadsheet with the ETF data, I will update this file at least monthly.
https://eod-notes.com/shared-content/ click on the “Reports” link and download the file.

I will assume you have python installed on your machine.

For starters you need to install dtale

pip install dtale

After dtale is installed you can copy paste this snippet.

import pandas as pd
import dtale

data = pd.read_excel("YOUR_FILE_PATH.xlsx") 
d= dtale.show(data)
d.open_browser()

Replace “YOUR_FILE_PATH.xlsx” with your file path and run it.
You will see something like this.

dtale start up

After this, go to the top left corner and click on the arrow. Select the correlation menu.

dtale correlation menu

A new window will pop up, now you are free to explore. search for specific correlations, change the Rolling Window for a smother data, have fun.

Find more stuff on my github:
https://github.com/tiagolvsantos/eod_notes

If you have any questions or want help to try some strategies up, feel free to drop me a message.

Have an awesome day,

Tiago

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
https://www.quandl.com/

You can find the code on my GitHub:
https://github.com/tiagolvsantos/eod_notes/blob/master/R/TANOS%20Commodities%20Correlation.Rmd

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.
https://www.anaconda.com/

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

https://pypi.org/project/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.
https://bitbucket.org/snippets/tanos-trader/onRn4G/quandl-cot-excel-report

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:

Recommendations:

  • 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:

https://www.alphavantage.co/support/#api-key

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:

install.packages(alphavantager)

install.packages(xlsx)

RStudio packages installation

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

Let´s start by initializing the libraries

library(alphavantager)

library(xlsx)

Replace “YOUR_API_KEY” with the API key you registered above

av_api_key("YOUR_API_KEY")

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",
  av_fun = "TIME_SERIES_INTRADAY",
  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

https://bitbucket.org/snippets/tanos-trader/Ebokz4/alphavantage-sample

If you have any question, just leave a comment.