# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Basic EDA for cryptocurrency

# In this notebook, we are going to try and explore the price history of different cryptocurrencies.
#
# As we created on the before notebook, the files that we will use are in the `data/processed/cryptocurrencypricehistory` directory. Now, we are going to import the necessary modules and then list the input files.

# +
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from pathlib import Path
DATA_PATH = Path('../../data/processed/cryptocurrencypricehistory')
# -

list(DATA_PATH.iterdir())

# ### Bitcoin vs. Ethereum
# First, if we want to explore `Ethereum` or the `Bitcoin` as it is the market leader in this space, we will be the following.

# +
df = pd.read_csv(DATA_PATH / 'cryptocurrency_close_values.csv', 
                 parse_dates=['Date'], index_col='Date')

df.head()
# -

df.index = pd.to_datetime(df.index)
df.sort_index(inplace=True)

# Now, let's create a plot of the closing values of the column `bitcoin_price` and `Ethereum_price` of the previous table and we will be able to observe how the price has changed over time.

# +
import matplotlib.dates as mdates

plt.figure(figsize=(12, 6))
plt.plot(df.index, df.bitcoin_price, label='Bitcoin')
plt.plot(df.index, df.ethereum_price, label='Ethereum')

plt.xlabel('Date', fontsize=12)
plt.ylabel('Price in $', fontsize=12)
plt.title("Closing price distribution of bitcoin and ethereum", fontsize=15)
plt.legend()

plt.show()
# -

# As we can see in the previous plot the difference between bitcoin and ethereum is very big, basically because bitcoin is the most valuable cryptocurrency that exists nowadays and the value it started to grow up since the first month of 2014. On the other hand, Ethereum grew up in the middñe of 2017, the years later.
#
# Now let us build a heat map using correlation to see how the price of different currencies change with respect to each other.

# +
corrmat = df[['bitcoin_price', 'dash_price', 
              'waves_price', 'stratis_price', 
              'ethereum_price', 'iota_price']].corr(method='spearman')
names = corrmat.columns
plt.figure(figsize=(11, 11))
plt.imshow(corrmat)
plt.title("Cryptocurrency correlation map", fontsize=15)
plt.colorbar()

plt.xticks(range(len(names)), names, rotation=90)
plt.yticks(range(len(names)), names)

plt.show()
# -

# ### Future price prediction
#
# Now that we have explored the dataset, one possible next step could be to predict the future price of the currency.
# First, we are going to install Prophet, to do so we are going to use pip.
# ```bash
# $ pip install fbprophet
# ```
# We could use the Prophet library of facebook here to do the predictions\[1\].

# +
# # !pip install fbprophet

# +
from fbprophet import Prophet

to_predict_df = df[['ethereum_price']]
to_predict_df.reset_index(inplace=True)
to_predict_df.columns = ['ds', 'y']

model = Prophet()
model.fit(to_predict_df)
# -

# Then, we can see the plot using the previous information to create a threshold that they can oscillate the predicted values.

future = model.make_future_dataframe(periods=360)
forecast = model.predict(future)

model.plot(forecast, xlabel='Date', ylabel='Price in $');

# As we can see in the previous graphics, we generated plots to estimate the values of Ethereum in the next year. Also, we can predict the different currencies in `cryptocurrency_close_values.csv` only changing the currency parameter in the before function.

# ## References
#
# \[1\] [Installation | Prophet](https://facebook.github.io/prophet/docs/installation.html)
#
# \[2\] [Quick Start | Prophet](https://facebook.github.io/prophet/docs/quick_start.html#python-api)



StarcoderdataJupyterScriptsDedupFiltered