import pandas as pd
import matplotlib.pyplot as plt
data = get_pricing('SPY', start_date='2015-6-1', end_date='2015-7-1', fields='volume')
x = np.arange(len(data))
print data.values
print data.index
plt.bar(x, data.values)
tick_num = 12
tick_step = float(len(data))/tick_num
x_tick = np.arange(0, len(data), tick_step)
x_label = []
for i in range(0, tick_num):
x_label.append(data.index[int(x_tick[i])].date())
print x_tick
print x_label
plt.xticks(x_tick, x_label)
plt.xticks(rotation=-90)
plt.ylabel('Volume (USD)');
8.29844740e+07 7.15034260e+07 7.82032850e+07 1.01090613e+08
5.82412800e+07 8.38160790e+07 9.04484390e+07 6.10451090e+07
9.68857910e+07 1.11951254e+08 7.89226310e+07 5.74651720e+07
4.89672890e+07 6.57530870e+07 6.33106560e+07 7.72355920e+07
1.41736435e+08 1.27227662e+08 9.46635640e+07]
DatetimeIndex(['2015-06-01', '2015-06-02', '2015-06-03', '2015-06-04',
'2015-06-05', '2015-06-08', '2015-06-09', '2015-06-10',
'2015-06-11', '2015-06-12', '2015-06-15', '2015-06-16',
'2015-06-17', '2015-06-18', '2015-06-19', '2015-06-22',
'2015-06-23', '2015-06-24', '2015-06-25', '2015-06-26',
'2015-06-29', '2015-06-30', '2015-07-01'],
dtype='datetime64[ns, UTC]', freq='C')
[ 0. 1.91666667 3.83333333 5.75 7.66666667
9.58333333 11.5 13.41666667 15.33333333 17.25 19.16666667
21.08333333]
[datetime.date(2015, 6, 1), datetime.date(2015, 6, 2), datetime.date(2015, 6, 4), datetime.date(2015, 6, 8), datetime.date(2015, 6, 10), datetime.date(2015, 6, 12), datetime.date(2015, 6, 16), datetime.date(2015, 6, 18), datetime.date(2015, 6, 22), datetime.date(2015, 6, 24), datetime.date(2015, 6, 26), datetime.date(2015, 6, 30)]
daily trading volume graph over a month
data = get_pricing('SPY', start_date='2015-6-1', end_date='2017-7-1', fields='volume')
daily trading volume over 2 years
data = get_pricing('SPY', start_date='2015-6-1', end_date='2015-6-2', frequency='minute', fields='volume')
...
for i in range(0, tick_num):
x_label.append(data.index[int(x_tick[i])])
[ 1130598. 860265. 466341. 305119. 420599. 434213. 456097.
485796. 321990. 256441. 276184. 193212. 286944. 167065.
108485. 197818. 422527. 593151. 479281. 214867. 601252.
268215. 570393. 303907. 262587. 203801. 176336. 654809.
242458. 227793. 854860. 557071. 1116683. 310044. 356430.
...
100768. 366257. 81084. 184404. 86525. 167199. 196828.
111246. 203550. 299601. 147401. 122207. 235673. 216496.
278106. 352249. 1112440. 418138. 273468. 270791. 439510.
424709. 117943. 172694. 181214. 317756. 765112. 316917.
522166. 798810. 1502124.]
DatetimeIndex(['2015-06-01 13:31:00+00:00', '2015-06-01 13:32:00+00:00',
'2015-06-01 13:33:00+00:00', '2015-06-01 13:34:00+00:00',
'2015-06-01 13:35:00+00:00', '2015-06-01 13:36:00+00:00',
'2015-06-01 13:37:00+00:00', '2015-06-01 13:38:00+00:00',
'2015-06-01 13:39:00+00:00', '2015-06-01 13:40:00+00:00',
...
'2015-06-02 19:51:00+00:00', '2015-06-02 19:52:00+00:00',
'2015-06-02 19:53:00+00:00', '2015-06-02 19:54:00+00:00',
'2015-06-02 19:55:00+00:00', '2015-06-02 19:56:00+00:00',
'2015-06-02 19:57:00+00:00', '2015-06-02 19:58:00+00:00',
'2015-06-02 19:59:00+00:00', '2015-06-02 20:00:00+00:00'],
dtype='datetime64[ns, UTC]', length=780, freq=None)
[ 0. 65. 130. 195. 260. 325. 390. 455. 520. 585. 650. 715.]
[Timestamp('2015-06-01 13:31:00+0000', tz='UTC'), Timestamp('2015-06-01 14:36:00+0000', tz='UTC'), Timestamp('2015-06-01 15:41:00+0000', tz='UTC'), Timestamp('2015-06-01 16:46:00+0000', tz='UTC'), Timestamp('2015-06-01 17:51:00+0000', tz='UTC'), Timestamp('2015-06-01 18:56:00+0000', tz='UTC'), Timestamp('2015-06-02 13:31:00+0000', tz='UTC'), Timestamp('2015-06-02 14:36:00+0000', tz='UTC'), Timestamp('2015-06-02 15:41:00+0000', tz='UTC'), Timestamp('2015-06-02 16:46:00+0000', tz='UTC'), Timestamp('2015-06-02 17:51:00+0000', tz='UTC'), Timestamp('2015-06-02 18:56:00+0000', tz='UTC')]
minute trading volume over 2 days
data = get_pricing('SPY', start_date='2015-6-1', end_date='2015-6-2', frequency='minute', fields='volume')data = data.resample('60T').sum()
[ 11360751. 18557297. 7024886. 7016271. 5862379. 7315033.
17311150. 1869567. nan nan nan nan
nan nan nan nan nan nan
nan nan nan nan nan nan
16010783. 14301804. 5977053. 10200373. 4987498. 8257317.
14418781. 1502124.]
DatetimeIndex(['2015-06-01 13:00:00+00:00', '2015-06-01 14:00:00+00:00',
'2015-06-01 15:00:00+00:00', '2015-06-01 16:00:00+00:00',
'2015-06-01 17:00:00+00:00', '2015-06-01 18:00:00+00:00',
'2015-06-01 19:00:00+00:00', '2015-06-01 20:00:00+00:00',
'2015-06-01 21:00:00+00:00', '2015-06-01 22:00:00+00:00',
'2015-06-01 23:00:00+00:00', '2015-06-02 00:00:00+00:00',
'2015-06-02 01:00:00+00:00', '2015-06-02 02:00:00+00:00',
'2015-06-02 03:00:00+00:00', '2015-06-02 04:00:00+00:00',
'2015-06-02 05:00:00+00:00', '2015-06-02 06:00:00+00:00',
'2015-06-02 07:00:00+00:00', '2015-06-02 08:00:00+00:00',
'2015-06-02 09:00:00+00:00', '2015-06-02 10:00:00+00:00',
'2015-06-02 11:00:00+00:00', '2015-06-02 12:00:00+00:00',
'2015-06-02 13:00:00+00:00', '2015-06-02 14:00:00+00:00',
'2015-06-02 15:00:00+00:00', '2015-06-02 16:00:00+00:00',
'2015-06-02 17:00:00+00:00', '2015-06-02 18:00:00+00:00',
'2015-06-02 19:00:00+00:00', '2015-06-02 20:00:00+00:00'],
dtype='datetime64[ns, UTC]', freq='60T')
[ 0. 2.66666667 5.33333333 8. 10.66666667
13.33333333 16. 18.66666667 21.33333333 24. 26.66666667
29.33333333]
[Timestamp('2015-06-01 13:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-01 15:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-01 18:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-01 21:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-01 23:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 02:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 05:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 07:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 10:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 13:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 15:00:00+0000', tz='UTC', offset='60T'), Timestamp('2015-06-02 18:00:00+0000', tz='UTC', offset='60T')]
hourly trading volume in 2 days
reference:
https://www.quantopian.com/lectures/introduction-to-volume-slippage-and-liquidity
https://pythonspot.com/matplotlib-bar-chart/
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.xticks.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html
No comments:
Post a Comment