In [1]:
from IPython.display import HTML
In [3]:
!curl -o mtgoxUSD.csv http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  829k    0  829k    0     0   542k      0 --:--:--  0:00:01 --:--:--  543k
In [4]:
!head mtgoxUSD.csv
1367570932,88.660020000000,1.000000000000
1367570925,88.829790000000,2.000000000000
1367570918,88.660010000000,0.016269960000
1367570918,88.670000000000,0.029680040000
1367570909,89.000000000000,10.755714540000
1367570905,89.000000000000,1.000000000000
1367570899,89.000000000000,0.010180200000
1367570896,89.000000000000,0.896400000000
1367570896,89.000000000000,17.518173580000
1367570895,90.000000000000,4.573877230000
In [5]:
import pandas as pd
In [6]:
df=pd.read_csv("mtgoxUSD.csv", 
               names=["unixtime", "price", "amount"], 
               header=None)
In [7]:
# Live-Abfrage
#df=pd.read_csv("http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD", 
#               names=["unixtime", "price", "amount"], 
#               header=None)
In [8]:
df
Out[8]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 20000 entries, 0 to 19999
Data columns (total 3 columns):
unixtime    20000  non-null values
price       20000  non-null values
amount      20000  non-null values
dtypes: float64(2), int64(1)
In [9]:
df.head()
Out[9]:
unixtime price amount
0 1367570932 88.66002 1.000000
1 1367570925 88.82979 2.000000
2 1367570918 88.66001 0.016270
3 1367570918 88.67000 0.029680
4 1367570909 89.00000 10.755715
In [10]:
import datetime
In [11]:
df["datetime"]=df["unixtime"].map(datetime.datetime.fromtimestamp)
In [12]:
df.head()
Out[12]:
unixtime price amount datetime
0 1367570932 88.66002 1.000000 2013-05-03 10:48:52
1 1367570925 88.82979 2.000000 2013-05-03 10:48:45
2 1367570918 88.66001 0.016270 2013-05-03 10:48:38
3 1367570918 88.67000 0.029680 2013-05-03 10:48:38
4 1367570909 89.00000 10.755715 2013-05-03 10:48:29
In [13]:
df.index
Out[13]:
Int64Index([0, 1, 2, ..., 19997, 19998, 19999], dtype=int64)
In [14]:
df["price"]
Out[14]:
0     88.66002
1     88.82979
2     88.66001
3     88.67000
4     89.00000
5     89.00000
6     89.00000
7     89.00000
8     89.00000
9     90.00000
10    89.67233
11    89.62752
12    89.47170
13    89.26982
14    89.00000
...
19985    113.41584
19986    113.41585
19987    113.41585
19988    113.41585
19989    113.90843
19990    113.90843
19991    113.41584
19992    113.90843
19993    113.90843
19994    113.00001
19995    113.00000
19996    113.00000
19997    113.00000
19998    113.00000
19999    113.00000
Name: price, Length: 20000, dtype: float64
In [15]:
ts=df.set_index("datetime")
In [16]:
ts.head()
Out[16]:
unixtime price amount
datetime
2013-05-03 10:48:52 1367570932 88.66002 1.000000
2013-05-03 10:48:45 1367570925 88.82979 2.000000
2013-05-03 10:48:38 1367570918 88.66001 0.016270
2013-05-03 10:48:38 1367570918 88.67000 0.029680
2013-05-03 10:48:29 1367570909 89.00000 10.755715
In [17]:
del ts["unixtime"]
In [18]:
ts.head()
Out[18]:
price amount
datetime
2013-05-03 10:48:52 88.66002 1.000000
2013-05-03 10:48:45 88.82979 2.000000
2013-05-03 10:48:38 88.66001 0.016270
2013-05-03 10:48:38 88.67000 0.029680
2013-05-03 10:48:29 89.00000 10.755715
In [19]:
ts.price
Out[19]:
datetime
2013-05-03 10:48:52    88.66002
2013-05-03 10:48:45    88.82979
2013-05-03 10:48:38    88.66001
2013-05-03 10:48:38    88.67000
2013-05-03 10:48:29    89.00000
2013-05-03 10:48:25    89.00000
2013-05-03 10:48:19    89.00000
2013-05-03 10:48:16    89.00000
2013-05-03 10:48:16    89.00000
2013-05-03 10:48:15    90.00000
2013-05-03 10:48:15    89.67233
2013-05-03 10:48:15    89.62752
2013-05-03 10:48:15    89.47170
2013-05-03 10:48:15    89.26982
2013-05-03 10:48:08    89.00000
...
2013-05-02 23:37:06    113.41584
2013-05-02 23:37:05    113.41585
2013-05-02 23:37:04    113.41585
2013-05-02 23:37:02    113.41585
2013-05-02 23:36:59    113.90843
2013-05-02 23:36:56    113.90843
2013-05-02 23:36:53    113.41584
2013-05-02 23:36:52    113.90843
2013-05-02 23:36:50    113.90843
2013-05-02 23:36:49    113.00001
2013-05-02 23:36:42    113.00000
2013-05-02 23:36:41    113.00000
2013-05-02 23:36:38    113.00000
2013-05-02 23:36:37    113.00000
2013-05-02 23:36:36    113.00000
Name: price, Length: 20000, dtype: float64
In [20]:
ts.price.describe()
Out[20]:
count    20000.000000
mean        97.886799
std          6.485139
min         85.010000
25%         93.000000
50%         97.625120
75%        102.962353
max        114.000000
dtype: float64
In [21]:
%pylab inline
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
In [22]:
figsize(15,9)
In [23]:
ts.price.plot()
Out[23]:
<matplotlib.axes.AxesSubplot at 0x3e10810>
In [24]:
ts.price.plot()
pd.rolling_mean(ts.price, 1000).plot(style="r-")
Out[24]:
<matplotlib.axes.AxesSubplot at 0x4087f10>
In [25]:
ts.amount.plot()
Out[25]:
<matplotlib.axes.AxesSubplot at 0x4094f90>
In [26]:
ts.amount.describe()
Out[26]:
count    2.000000e+04
mean     5.716326e+00
std      2.283848e+01
min      9.000000e-08
25%      4.810129e-02
50%      5.428574e-01
75%      3.593949e+00
max      9.632340e+02
dtype: float64

Umsatzvolumen ausrechnen

In [27]:
ts["volume"]=ts["price"]*ts["amount"]
In [28]:
ts.volume.plot()
Out[28]:
<matplotlib.axes.AxesSubplot at 0x4956490>
In [29]:
ts.volume.sum()
Out[29]:
11049420.640076589
In [30]:
ts.volume.max()
Out[30]:
89580.758641770008
In [31]:
ts.volume.idxmax()
Out[31]:
<Timestamp: 2013-05-03 10:01:39>
In [32]:
per_hour = ts.resample("H", how="sum")
per_hour
Out[32]:
price amount volume
datetime
2013-05-02 23:00:00 55270.68755 1797.114673 201076.050965
2013-05-03 00:00:00 126346.70511 5806.793318 630328.604279
2013-05-03 01:00:00 196072.21058 11734.055969 1220434.047567
2013-05-03 02:00:00 98563.30881 3901.101820 413226.440800
2013-05-03 03:00:00 77570.55590 1878.971340 196346.806882
2013-05-03 04:00:00 234328.00204 13767.752833 1365172.370100
2013-05-03 05:00:00 127677.64800 6640.089771 657910.394427
2013-05-03 06:00:00 282974.73665 19193.793631 1818347.071176
2013-05-03 07:00:00 201317.68245 6299.726781 615272.249169
2013-05-03 08:00:00 103206.79038 5544.781968 531549.828447
2013-05-03 09:00:00 164448.59770 13368.928290 1234107.477817
2013-05-03 10:00:00 289959.04870 24393.406447 2165649.298449
In [33]:
per_hour.volume.plot(kind="bar")
Out[33]:
<matplotlib.axes.AxesSubplot at 0x4a77710>

Weighted Prices

In [34]:
!curl -o bitcoin_weighted_prices.json http://api.bitcoincharts.com/v1/weighted_prices.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1221  100  1221    0     0  24023      0 --:--:-- --:--:-- --:--:-- 27133
In [35]:
import json
In [36]:
!head bitcoin_weighted_prices.json
{"JPY": {"7d": "12571.02", "30d": "11924.65", "24h": "9725.55"}, "USD": {"7d": "119.22", "30d": "114.39", "24h": "101.09"}, "AUD": {"7d": "119.21", "30d": "115.31", "24h": "99.10"}, "CHF": {"7d": "119.89", "30d": "114.46", "24h": "99.83"}, "RUB": {"7d": "3899.36", "30d": "3961.13", "24h": "3312.98"}, "timestamp": 1367570706, "THB": {"7d": "4001.93", "30d": "2580.31", "24h": "2800.00"}, "SLL": {"7d": "35291.65", "30d": "33266.80", "24h": "30565.66"}, "DKK": {"7d": "676.85", "30d": "693.10", "24h": "557.41"}, "XRP": {"7d": "33012.22", "30d": "42760.89", "24h": "21500.00"}, "BRL": {"7d": "298.62", "30d": "309.04", "24h": "236.22"}, "CAD": {"7d": "122.94", "30d": "128.12", "24h": "105.42"}, "ILS": {"7d": "444.77", "30d": "589.03", "24h": "391.27"}, "GBP": {"7d": "78.57", "30d": "76.39", "24h": "64.59"}, "NZD": {"7d": "140.40", "30d": "150.37", "24h": "117.72"}, "PLN": {"7d": "388.96", "30d": "435.09", "24h": "322.39"}, "CNY": {"7d": "763.84", "30d": "802.23", "24h": "657.48"}, "SEK": {"7d": "817.75", "30d": "827.22", "24h": "707.78"}, "SGD": {"7d": "159.39", "30d": "163.81", "24h": "130.12"}, "HKD": {"7d": "1010.62", "30d": "939.79", "24h": "784.94"}, "EUR": {"7d": "92.18", "30d": "95.61", "24h": "79.32"}}
In [37]:
data=[json.loads(line) for line in open("bitcoin_weighted_prices.json")]
In [38]:
data
Out[38]:
[{u'AUD': {u'24h': u'99.10', u'30d': u'115.31', u'7d': u'119.21'},
  u'BRL': {u'24h': u'236.22', u'30d': u'309.04', u'7d': u'298.62'},
  u'CAD': {u'24h': u'105.42', u'30d': u'128.12', u'7d': u'122.94'},
  u'CHF': {u'24h': u'99.83', u'30d': u'114.46', u'7d': u'119.89'},
  u'CNY': {u'24h': u'657.48', u'30d': u'802.23', u'7d': u'763.84'},
  u'DKK': {u'24h': u'557.41', u'30d': u'693.10', u'7d': u'676.85'},
  u'EUR': {u'24h': u'79.32', u'30d': u'95.61', u'7d': u'92.18'},
  u'GBP': {u'24h': u'64.59', u'30d': u'76.39', u'7d': u'78.57'},
  u'HKD': {u'24h': u'784.94', u'30d': u'939.79', u'7d': u'1010.62'},
  u'ILS': {u'24h': u'391.27', u'30d': u'589.03', u'7d': u'444.77'},
  u'JPY': {u'24h': u'9725.55', u'30d': u'11924.65', u'7d': u'12571.02'},
  u'NZD': {u'24h': u'117.72', u'30d': u'150.37', u'7d': u'140.40'},
  u'PLN': {u'24h': u'322.39', u'30d': u'435.09', u'7d': u'388.96'},
  u'RUB': {u'24h': u'3312.98', u'30d': u'3961.13', u'7d': u'3899.36'},
  u'SEK': {u'24h': u'707.78', u'30d': u'827.22', u'7d': u'817.75'},
  u'SGD': {u'24h': u'130.12', u'30d': u'163.81', u'7d': u'159.39'},
  u'SLL': {u'24h': u'30565.66', u'30d': u'33266.80', u'7d': u'35291.65'},
  u'THB': {u'24h': u'2800.00', u'30d': u'2580.31', u'7d': u'4001.93'},
  u'USD': {u'24h': u'101.09', u'30d': u'114.39', u'7d': u'119.22'},
  u'XRP': {u'24h': u'21500.00', u'30d': u'42760.89', u'7d': u'33012.22'},
  u'timestamp': 1367570706}]
In [39]:
data[0]
Out[39]:
{u'AUD': {u'24h': u'99.10', u'30d': u'115.31', u'7d': u'119.21'},
 u'BRL': {u'24h': u'236.22', u'30d': u'309.04', u'7d': u'298.62'},
 u'CAD': {u'24h': u'105.42', u'30d': u'128.12', u'7d': u'122.94'},
 u'CHF': {u'24h': u'99.83', u'30d': u'114.46', u'7d': u'119.89'},
 u'CNY': {u'24h': u'657.48', u'30d': u'802.23', u'7d': u'763.84'},
 u'DKK': {u'24h': u'557.41', u'30d': u'693.10', u'7d': u'676.85'},
 u'EUR': {u'24h': u'79.32', u'30d': u'95.61', u'7d': u'92.18'},
 u'GBP': {u'24h': u'64.59', u'30d': u'76.39', u'7d': u'78.57'},
 u'HKD': {u'24h': u'784.94', u'30d': u'939.79', u'7d': u'1010.62'},
 u'ILS': {u'24h': u'391.27', u'30d': u'589.03', u'7d': u'444.77'},
 u'JPY': {u'24h': u'9725.55', u'30d': u'11924.65', u'7d': u'12571.02'},
 u'NZD': {u'24h': u'117.72', u'30d': u'150.37', u'7d': u'140.40'},
 u'PLN': {u'24h': u'322.39', u'30d': u'435.09', u'7d': u'388.96'},
 u'RUB': {u'24h': u'3312.98', u'30d': u'3961.13', u'7d': u'3899.36'},
 u'SEK': {u'24h': u'707.78', u'30d': u'827.22', u'7d': u'817.75'},
 u'SGD': {u'24h': u'130.12', u'30d': u'163.81', u'7d': u'159.39'},
 u'SLL': {u'24h': u'30565.66', u'30d': u'33266.80', u'7d': u'35291.65'},
 u'THB': {u'24h': u'2800.00', u'30d': u'2580.31', u'7d': u'4001.93'},
 u'USD': {u'24h': u'101.09', u'30d': u'114.39', u'7d': u'119.22'},
 u'XRP': {u'24h': u'21500.00', u'30d': u'42760.89', u'7d': u'33012.22'},
 u'timestamp': 1367570706}
In [40]:
wp=pd.DataFrame(data[0])
wp
Out[40]:
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, 24h to 7d
Data columns (total 21 columns):
AUD          3  non-null values
BRL          3  non-null values
CAD          3  non-null values
CHF          3  non-null values
CNY          3  non-null values
DKK          3  non-null values
EUR          3  non-null values
GBP          3  non-null values
HKD          3  non-null values
ILS          3  non-null values
JPY          3  non-null values
NZD          3  non-null values
PLN          3  non-null values
RUB          3  non-null values
SEK          3  non-null values
SGD          3  non-null values
SLL          3  non-null values
THB          3  non-null values
USD          3  non-null values
XRP          3  non-null values
timestamp    3  non-null values
dtypes: int64(1), object(20)
In [41]:
wp[["CAD", "EUR"]].T
Out[41]:
24h 30d 7d
CAD 105.42 128.12 122.94
EUR 79.32 95.61 92.18
In [42]:
wp["datetime"]=wp.timestamp.apply(datetime.datetime.fromtimestamp)
del wp["timestamp"]
In [43]:
wp
Out[43]:
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, 24h to 7d
Data columns (total 21 columns):
AUD         3  non-null values
BRL         3  non-null values
CAD         3  non-null values
CHF         3  non-null values
CNY         3  non-null values
DKK         3  non-null values
EUR         3  non-null values
GBP         3  non-null values
HKD         3  non-null values
ILS         3  non-null values
JPY         3  non-null values
NZD         3  non-null values
PLN         3  non-null values
RUB         3  non-null values
SEK         3  non-null values
SGD         3  non-null values
SLL         3  non-null values
THB         3  non-null values
USD         3  non-null values
XRP         3  non-null values
datetime    3  non-null values
dtypes: datetime64[ns](1), object(20)
In [44]:
wp.T
Out[44]:
24h 30d 7d
AUD 99.10 115.31 119.21
BRL 236.22 309.04 298.62
CAD 105.42 128.12 122.94
CHF 99.83 114.46 119.89
CNY 657.48 802.23 763.84
DKK 557.41 693.10 676.85
EUR 79.32 95.61 92.18
GBP 64.59 76.39 78.57
HKD 784.94 939.79 1010.62
ILS 391.27 589.03 444.77
JPY 9725.55 11924.65 12571.02
NZD 117.72 150.37 140.40
PLN 322.39 435.09 388.96
RUB 3312.98 3961.13 3899.36
SEK 707.78 827.22 817.75
SGD 130.12 163.81 159.39
SLL 30565.66 33266.80 35291.65
THB 2800.00 2580.31 4001.93
USD 101.09 114.39 119.22
XRP 21500.00 42760.89 33012.22
datetime 2013-05-03 10:45:06 2013-05-03 10:45:06 2013-05-03 10:45:06
In [45]:
pd.DataFrame(wp.ix["24h", ["AUD", "EUR", "ILS"]]).T
Out[45]:
AUD EUR ILS
24h 99.10 79.32 391.27