|
41 | 41 | cachedir = None
|
42 | 42 |
|
43 | 43 |
|
44 |
| -stock_dt = np.dtype([('date', object), |
| 44 | +stock_dt_ohlc = np.dtype([('date', object), |
45 | 45 | ('year', np.int16),
|
46 | 46 | ('month', np.int8),
|
47 | 47 | ('day', np.int8),
|
|
54 | 54 | ('aclose', np.float)])
|
55 | 55 |
|
56 | 56 |
|
57 |
| -def parse_yahoo_historical(fh, adjusted=True, asobject=False): |
| 57 | +stock_dt_ochl = np.dtype([('date', object), |
| 58 | + ('year', np.int16), |
| 59 | + ('month', np.int8), |
| 60 | + ('day', np.int8), |
| 61 | + ('d', np.float), # mpl datenum |
| 62 | + ('open', np.float), |
| 63 | + ('close', np.float), |
| 64 | + ('high', np.float), |
| 65 | + ('low', np.float), |
| 66 | + ('volume', np.float), |
| 67 | + ('aclose', np.float)]) |
| 68 | + |
| 69 | + |
| 70 | +def parse_yahoo_historical_ochl(fh, adjusted=True, asobject=False): |
| 71 | + """Parse the historical data in file handle fh from yahoo finance. |
| 72 | +
|
| 73 | +
|
| 74 | + This function has been deprecated in 1.4 in favor of |
| 75 | + `parse_yahoo_historical_ochl`, which maintains the original argument |
| 76 | + order, or `parse_yahoo_historical_ohlc`, which uses the |
| 77 | + open-high-low-close order. This function will be removed in 1.5 |
| 78 | +
|
| 79 | +
|
| 80 | + Parameters |
| 81 | + ---------- |
| 82 | +
|
| 83 | + adjusted : `bool` |
| 84 | + If True (default) replace open, high, low, close prices with |
| 85 | + their adjusted values. The adjustment is by a scale factor, S = |
| 86 | + adjusted_close/close. Adjusted prices are actual prices |
| 87 | + multiplied by S. |
| 88 | +
|
| 89 | + Volume is not adjusted as it is already backward split adjusted |
| 90 | + by Yahoo. If you want to compute dollars traded, multiply volume |
| 91 | + by the adjusted close, regardless of whether you choose adjusted |
| 92 | + = True|False. |
| 93 | +
|
| 94 | +
|
| 95 | + asobject : `bool` or :class:`None` |
| 96 | + If False (default for compatibility with earlier versions) |
| 97 | + return a list of tuples containing |
| 98 | +
|
| 99 | + d, open, close, high, low, volume |
| 100 | +
|
| 101 | + If None (preferred alternative to False), return |
| 102 | + a 2-D ndarray corresponding to the list of tuples. |
| 103 | +
|
| 104 | + Otherwise return a numpy recarray with |
| 105 | +
|
| 106 | + date, year, month, day, d, open, close, high, low, |
| 107 | + volume, adjusted_close |
| 108 | +
|
| 109 | + where d is a floating poing representation of date, |
| 110 | + as returned by date2num, and date is a python standard |
| 111 | + library datetime.date instance. |
| 112 | +
|
| 113 | + The name of this kwarg is a historical artifact. Formerly, |
| 114 | + True returned a cbook Bunch |
| 115 | + holding 1-D ndarrays. The behavior of a numpy recarray is |
| 116 | + very similar to the Bunch. |
| 117 | +
|
| 118 | + stock_dt : `np.dtype` |
| 119 | + The data type to be used for the returned array. This is a |
| 120 | + temporary argument to easy the transition from ochl -> ohlc |
| 121 | +
|
| 122 | + """ |
| 123 | + parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject, |
| 124 | + oclh=True) |
| 125 | + |
| 126 | + |
| 127 | +def parse_yahoo_historical_ohlc(fh, adjusted=True, asobject=False): |
58 | 128 | """Parse the historical data in file handle fh from yahoo finance.
|
59 | 129 |
|
| 130 | +
|
| 131 | + This function has been deprecated in 1.4 in favor of |
| 132 | + `parse_yahoo_historical_ochl`, which maintains the original argument |
| 133 | + order, or `parse_yahoo_historical_ohlc`, which uses the |
| 134 | + open-high-low-close order. This function will be removed in 1.5 |
| 135 | +
|
| 136 | +
|
| 137 | + Parameters |
| 138 | + ---------- |
| 139 | +
|
| 140 | + adjusted : `bool` |
| 141 | + If True (default) replace open, high, low, close prices with |
| 142 | + their adjusted values. The adjustment is by a scale factor, S = |
| 143 | + adjusted_close/close. Adjusted prices are actual prices |
| 144 | + multiplied by S. |
| 145 | +
|
| 146 | + Volume is not adjusted as it is already backward split adjusted |
| 147 | + by Yahoo. If you want to compute dollars traded, multiply volume |
| 148 | + by the adjusted close, regardless of whether you choose adjusted |
| 149 | + = True|False. |
| 150 | +
|
| 151 | +
|
| 152 | + asobject : `bool` or :class:`None` |
| 153 | + If False (default for compatibility with earlier versions) |
| 154 | + return a list of tuples containing |
| 155 | +
|
| 156 | + d, open, high, low, close, volume |
| 157 | +
|
| 158 | + If None (preferred alternative to False), return |
| 159 | + a 2-D ndarray corresponding to the list of tuples. |
| 160 | +
|
| 161 | + Otherwise return a numpy recarray with |
| 162 | +
|
| 163 | + date, year, month, day, d, open, high, low, close, |
| 164 | + volume, adjusted_close |
| 165 | +
|
| 166 | + where d is a floating poing representation of date, |
| 167 | + as returned by date2num, and date is a python standard |
| 168 | + library datetime.date instance. |
| 169 | +
|
| 170 | + The name of this kwarg is a historical artifact. Formerly, |
| 171 | + True returned a cbook Bunch |
| 172 | + holding 1-D ndarrays. The behavior of a numpy recarray is |
| 173 | + very similar to the Bunch. |
| 174 | +
|
| 175 | + stock_dt : `np.dtype` |
| 176 | + The data type to be used for the returned array. This is a |
| 177 | + temporary argument to easy the transition from ochl -> ohlc |
| 178 | +
|
| 179 | + """ |
| 180 | + parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject, |
| 181 | + ochl=False) |
| 182 | + |
| 183 | + |
| 184 | +def parse_yahoo_historical(fh, adjusted=True, asobject=False, |
| 185 | + ochl=True): |
| 186 | + """Parse the historical data in file handle fh from yahoo finance. |
| 187 | +
|
| 188 | +
|
| 189 | + This function has been deprecated in 1.4 in favor of |
| 190 | + `parse_yahoo_historical_ochl`, which maintains the original argument |
| 191 | + order, or `parse_yahoo_historical_ohlc`, which uses the |
| 192 | + open-high-low-close order. This function will be removed in 1.5 |
| 193 | +
|
| 194 | +
|
60 | 195 | Parameters
|
61 | 196 | ----------
|
62 | 197 |
|
@@ -95,7 +230,15 @@ def parse_yahoo_historical(fh, adjusted=True, asobject=False):
|
95 | 230 | holding 1-D ndarrays. The behavior of a numpy recarray is
|
96 | 231 | very similar to the Bunch.
|
97 | 232 |
|
| 233 | + stock_dt : `np.dtype` |
| 234 | + The data type to be used for the returned array. This is a |
| 235 | + temporary argument to easy the transition from ochl -> ohlc |
| 236 | +
|
98 | 237 | """
|
| 238 | + if ochl: |
| 239 | + stock_dt = stock_dt_ochl |
| 240 | + else: |
| 241 | + stock_dt = stock_dt_ohlc |
99 | 242 |
|
100 | 243 | lines = fh.readlines()
|
101 | 244 |
|
@@ -134,10 +277,16 @@ def parse_yahoo_historical(fh, adjusted=True, asobject=False):
|
134 | 277 | # 2-D sequence; formerly list of tuples, now ndarray
|
135 | 278 | ret = np.zeros((len(d), 6), dtype=np.float)
|
136 | 279 | ret[:, 0] = d['d']
|
137 |
| - ret[:, 1] = d['open'] |
138 |
| - ret[:, 3] = d['high'] |
139 |
| - ret[:, 4] = d['low'] |
140 |
| - ret[:, 2] = d['close'] |
| 280 | + if ochl: |
| 281 | + ret[:, 1] = d['open'] |
| 282 | + ret[:, 2] = d['close'] |
| 283 | + ret[:, 3] = d['high'] |
| 284 | + ret[:, 4] = d['low'] |
| 285 | + else: |
| 286 | + ret[:, 1] = d['open'] |
| 287 | + ret[:, 2] = d['high'] |
| 288 | + ret[:, 3] = d['low'] |
| 289 | + ret[:, 4] = d['close'] |
141 | 290 | ret[:, 5] = d['volume']
|
142 | 291 | if asobject is None:
|
143 | 292 | return ret
|
@@ -427,10 +576,10 @@ def plot_day_summary2(ax, opens, closes, highs, lows, ticksize=4,
|
427 | 576 | tick is the close.
|
428 | 577 |
|
429 | 578 |
|
430 |
| - This function has been deprecated in 1.3 in favor of |
| 579 | + This function has been deprecated in 1.4 in favor of |
431 | 580 | `plot_day_summary_ochl`, which maintains the original argument
|
432 | 581 | order, or `plot_day_summary_ohlc`, which uses the
|
433 |
| - open-high-low-close order. This function will be removed in 1.4 |
| 582 | + open-high-low-close order. This function will be removed in 1.5 |
434 | 583 |
|
435 | 584 |
|
436 | 585 | Parameters
|
|
0 commit comments