|
2 | 2 | import numpy as np
|
3 | 3 |
|
4 | 4 | from matplotlib.ticker import MultipleLocator
|
5 |
| -from data_helper import get_two_stock_data |
| 5 | + |
| 6 | +def get_two_stock_data(): |
| 7 | + """ |
| 8 | + load stock time and price data for two stocks The return values |
| 9 | + (d1,p1,d2,p2) are the trade time (in days) and prices for stocks 1 |
| 10 | + and 2 (intc and aapl) |
| 11 | + """ |
| 12 | + ticker1, ticker2 = 'INTC', 'AAPL' |
| 13 | + |
| 14 | + file1 = cbook.get_sample_data('INTC.dat.gz') |
| 15 | + file2 = cbook.get_sample_data('AAPL.dat.gz') |
| 16 | + M1 = fromstring(file1.read(), '<d') |
| 17 | + |
| 18 | + M1 = resize(M1, (M1.shape[0]//2, 2)) |
| 19 | + |
| 20 | + M2 = fromstring(file2.read(), '<d') |
| 21 | + M2 = resize(M2, (M2.shape[0]//2, 2)) |
| 22 | + |
| 23 | + d1, p1 = M1[:, 0], M1[:, 1] |
| 24 | + d2, p2 = M2[:, 0], M2[:, 1] |
| 25 | + return (d1, p1, d2, p2) |
| 26 | + |
6 | 27 |
|
7 | 28 | d1, p1, d2, p2 = get_two_stock_data()
|
8 | 29 |
|
|
11 | 32 | lines2 = plt.plot(d2, p2, 'r', label="AAPL")
|
12 | 33 | plt.xlabel('Days')
|
13 | 34 | plt.ylabel('Normalized price')
|
14 |
| -plt.xlim(0, 3) |
| 35 | +plt.xlim(0, 3 ) |
15 | 36 | ax.xaxis.set_major_locator(MultipleLocator(1))
|
16 | 37 |
|
17 | 38 | plt.title('INTC vs AAPL')
|
|
0 commit comments