import numpy as np # Linear Alg
import pandas as pd # CSV file I/O & data processing

# Visualization
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import warnings 
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
warnings.filterwarnings("ignore")
style.use('ggplot')

%matplotlib inline
plt.rcParams['figure.figsize'] = (12.0, 8.0)

from subprocess import check_output

"""
Explanation: Waterfall Checkpoint Demo
Team: IBM (Itty Bitty Money)

Patrick Handley
Bhargavi Madhunala
Matt Maffa
Antonino Tan-Marcello

Date: 10-05-2017
This notebook is used for our waterfall checkpoint presentation demo.
Dependencies

Python3
Pandas
Numpy
Matplotlib
Seaborn
End of explanation
"""


data_dir = '../../input'
# Check what files our dataset contain
print('Our dataset contains the following files: \n')
print(check_output(["ls", data_dir]).decode("utf8"))

"""
Explanation: Dataset
We are using the Cryptocurrency Historical Prices dataset from Kaggle.
End of explanation
"""


# Reading in bitcoin price file
bitcoin_price = pd.read_csv('{}/bitcoin_price.csv'.format(data_dir), parse_dates=['Date'], index_col=0)
bitcoin_price.dtypes

# Lets look at the first 10 rows
bitcoin_price.head(10)

bitcoin_price.tail(10)

print('Date of newest data: {}'.format(bitcoin_price.index[0]))
print('Date of oldest data: {}'.format(bitcoin_price.index[-1]))

btc_ohlc = ['Open', 'High', 'Low', 'Close']

for feat in btc_ohlc:
    print('---------------------------------------------')
    print('Statistics for Bitcoin {} values:'.format(feat))
    print(bitcoin_price[feat].describe())

# Lets plot the Open, Close, High, Low values on a line plot
for feat in btc_ohlc:
    plt.plot(bitcoin_price[feat], label=feat)

plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()

# Lets looks at the more recent data
n_days = 365 # number of recent days

for feature in btc_ohlc:
    plt.plot(bitcoin_price[feature].iloc[:n_days], label=feature)

plt.title('Pricing Trend(last year)')
plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()

# Candlestick graph for Bitcoin Closing Price
btc_close_ohlc = bitcoin_price['Close'][:n_days].resample('10D').ohlc()
btc_close_ohlc.reset_index(inplace=True)
btc_close_ohlc['Date'] = btc_close_ohlc['Date'].map(mdates.date2num)

fig, ax = plt.subplots()

candlestick_ohlc(ax, btc_close_ohlc.values, width=2, colorup='g')
ax.xaxis_date()

plt.title('Candlestick Chart')
plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()

"""
Explanation: Bitcoin
We will explore the bitcoin data for the purpose of a demo.
End of explanation
"""


