I found a great tutorial on Patrick Triest's blog that I summarized and share with you.
In this tutorial we focus on obtaining the raw data and each one will do his own analysis of the results.
To perform this basic tutorial you will need a basic understanding of Python and knowledge of the command line to set up a project.
1 - Install Anaconda
To install the dependencies for this project from scratch we are going to use Anaconda, a pre-packaged Python data science ecosystem and a dependency manager.
To setup Anaconda, I would recommend following the official installation instructions - https://www.continuum.io/downloads.
2 - Setup an Anaconda Project Environment
To create a new Anaconda environment, run:
To activate this environment, run:
For Linux
For Windows
To install the required dependencies in the environment, run:
This could take a few minutes to complete.
3 - Start An Interative Jupyter Notebook
Once the environment and dependencies are all set up, run:
This will start the iPython kernel, and open your browser to
For create a new Python notebook, making sure to use the Python
4 - Import the Dependencies
Once you've got a blank Jupyter notebook open, the first thing we'll do is import the required dependencies:
import numpy as np
import pandas as pd
import pickle
import quandl
from datetime import datetime
We'll also import Plotly and enable the offline mode:
import plotly.graph_objs as go
import plotly.figure_factory as ff
py.init_notebook_mode(connected=True)
With this we would have everything ready to start connecting with an API to bring data for example Bitcoin.
To test if everything is working we will start to retrieving data for analysis. First, we need to get Bitcoin pricing data using Quandl's free Bitcoin API.
For this, we will define Quandl Helper Function:
'''Download and cache Quandl dataseries'''
cache_path = '{}.pkl'.format(quandl_id).replace('/','-')
try:
f = open(cache_path, 'rb')
df = pickle.load(f)
print('Loaded {} from cache'.format(quandl_id))
except (OSError, IOError) as e:
print('Downloading {} from Quandl'.format(quandl_id))
df = quandl.get(quandl_id, returns="pandas")
df.to_pickle(cache_path)
print('Cached {} at {}'.format(quandl_id, cache_path))
return df
For this example we are going to extract the Kraken exchange price data:
btc_usd_price_kraken = get_quandl_data('BCHARTS/KRAKENUSD')
We can inspect the first 5 rows of the dataframe using the head() method:
We should see a table like this:
Open High Low Close Volume (BTC) Volume (Currency) Weighted Price
Date
2014-01-07 874.67040 892.06753 810.00000 810.00000 15.622378 13151.472844 841.835522
2014-01-08 810.00000 899.84281 788.00000 824.98287 19.182756 16097.329584 839.156269
2014-01-09 825.56345 870.00000 807.42084 841.86934 8.158335 6784.249982 831.572913
2014-01-10 839.99000 857.34056 817.00000 857.33056 8.024510 6780.220188 844.938794
2014-01-11 858.20000 918.05471 857.16554 899.84105 18.748285 16698.566929 890.671709
If you want to see the original tutorial, here is the link:
https://blog.patricktriest.com/analyzing-cryptocurrencies-python/