In [1]:
import matplotlib.pyplot as plt
import pandas as pd

from pprint import pprint
from coindesk import btc_interval
from tobtc import tobtc

plt.style.use('ggplot')

In [2]:
btc = btc_interval('20170101', '20170119')

In [3]:
btc = btc['bpi']

In [4]:
df = pd.DataFrame(list(btc.items()), columns=['Date', 'USD'])
df


Out[4]:
Date USD
0 2017-01-01 997.6888
1 2017-01-02 1018.0500
2 2017-01-03 1030.8175
3 2017-01-04 1129.8700
4 2017-01-05 1005.8150
5 2017-01-06 895.6700
6 2017-01-07 905.1700
7 2017-01-08 913.5238
8 2017-01-09 899.3500
9 2017-01-10 904.7925
10 2017-01-11 775.9813
11 2017-01-12 802.8288
12 2017-01-13 826.1213
13 2017-01-14 818.6388
14 2017-01-15 822.4225
15 2017-01-16 830.2638
16 2017-01-17 904.4538
17 2017-01-18 884.2513
18 2017-01-19 898.0213

In [5]:
df.max()


Out[5]:
Date    2017-01-19
USD        1129.87
dtype: object

In [6]:
df.min()


Out[6]:
Date    2017-01-01
USD        775.981
dtype: object

In [7]:
df.plot(x='Date', y='USD', figsize=(20, 10))
plt.show()



In [8]:
df.plot.box()
plt.show()



In [9]:
percent_change = df['USD'].pct_change()
percent_change.plot(figsize=(20, 10))
plt.show()



In [10]:
h = df.merge(percent_change.to_frame(), left_index=True, right_index=True)
h.columns = ['Date', 'USD', 'percent_change']
h


Out[10]:
Date USD percent_change
0 2017-01-01 997.6888 NaN
1 2017-01-02 1018.0500 0.020408
2 2017-01-03 1030.8175 0.012541
3 2017-01-04 1129.8700 0.096091
4 2017-01-05 1005.8150 -0.109796
5 2017-01-06 895.6700 -0.109508
6 2017-01-07 905.1700 0.010607
7 2017-01-08 913.5238 0.009229
8 2017-01-09 899.3500 -0.015516
9 2017-01-10 904.7925 0.006052
10 2017-01-11 775.9813 -0.142365
11 2017-01-12 802.8288 0.034598
12 2017-01-13 826.1213 0.029013
13 2017-01-14 818.6388 -0.009057
14 2017-01-15 822.4225 0.004622
15 2017-01-16 830.2638 0.009534
16 2017-01-17 904.4538 0.089357
17 2017-01-18 884.2513 -0.022337
18 2017-01-19 898.0213 0.015572

In [11]:
date_inc = h[h['percent_change'] > 0.09]

date_inc['Date']


Out[11]:
3    2017-01-04
Name: Date, dtype: object

In [12]:
date_dec = h[h['percent_change'] < -0.09]
date_dec['Date']


Out[12]:
4     2017-01-05
5     2017-01-06
10    2017-01-11
Name: Date, dtype: object

In [13]:
from bitcoin_calc import timestamp_convert
t = timestamp_convert(h)
print(t)


{'high': [1483516800], 'low': [1483603200, 1483689600, 1484121600]}

In [14]:
# from reddit_search import reddit_search

# hi = reddit_search('InternationalNews', t['high'])
# lo = reddit_search('InternationalNews', t['low'])

# pprint(lo)

In [15]:
from nyt_get import nyt_bitcoin
from bitcoin_calc import high_percents, low_percents


tlo = nyt_bitcoin(low_percents(h).values.tolist())
pprint(tlo)


{'Battered Bitcoin Slides Another 12 Percent After China Warning': 'http://www.nytimes.com/reuters/2017/01/06/business/06reuters-global-markets-bitcoin.html',
 'Bitcoin Plunges as Much as 20 Percent as Chinese Yuan Soars': 'http://www.nytimes.com/reuters/2017/01/05/business/05reuters-global-markets-bitcoin.html',
 'Bitcoin Slides After China Central Bank Launches Investigation': 'http://www.nytimes.com/reuters/2017/01/11/business/11reuters-markets-bitcoin-pboc.html',
 "Bitcoin Slides as China's Central Bank Launches Checks on Exchanges": 'http://www.nytimes.com/reuters/2017/01/11/business/11reuters-china-bitcoin.html',
 'Bitstamp Adds Ripple Currency XRP to Trading Platform': 'http://www.nytimes.com/reuters/2017/01/10/business/10reuters-blockchain-ripple.html',
 'China Central Bank Urges Rational Investment in Bitcoin': 'http://www.nytimes.com/reuters/2017/01/06/business/06reuters-china-bitcoin.html'}