def gen_intraday_volatility_plots(symbol, dates, high, low, close, start_date, end_date, gen_title) : (start_idx, end_idx) = get_start_end_idxs(dates, start_date, end_date) # cut slice date_slice = dates[start_idx : end_idx] slice_start_date = dates[start_idx] slice_end_date = dates[end_idx] low_slice = low[start_idx : end_idx] high_slice = high[start_idx : end_idx] close_slice = close[start_idx : end_idx] delta = [] for i in range(len(high_slice)): delta.append(float(100 * (high_slice[i] - low_slice[i]) / close_slice[i]) ) # generate matplotlib plot x = np.array(date_slice) y = np.array(delta) fever_fig = plt.figure() ax = fever_fig.add_subplot(111) ax.plot(x,y) # leg = ax.legend(('Model length'), 'upper center', shadow=True) ax.grid(False) ax.set_ylabel('100 * (High - Low) / Close') title = gen_title(symbol, 'Intra-Day Range as a Percentage of Closing Price', slice_start_date, slice_end_date) ax.set_title(title) # date intervals & markers (formatter, locator) = tick_info(slice_start_date, slice_end_date) ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_major_locator(locator) fever_fig.autofmt_xdate(rotation=90) ax.set_xlim([slice_start_date, slice_end_date]) ax.set_xlabel('Date') # ------------ h = Histogram(delta) left_edge = [] height = [] for bin in h.bins: left_edge.append(float(bin.floor)) height.append(h.bin_contrib_perc(bin)) x = np.array(left_edge) y = np.array(height) dist_fig = plt.figure() ax = dist_fig.add_subplot(111) ax.bar(x, y, width=h.bins[0].range) ax.set_xlim(h.min, h.max) ax.set_ylabel('% of Population') ax.set_xlabel('Intra-Day Range i.t.o Close : 100 * (High - Low) / Close') title = gen_title(symbol, 'Distribution of Intra-Day Range', slice_start_date, slice_end_date) ax.set_title(title) reports = [] reports.append(AnalysisReport(symbol, slice_start_date, slice_end_date, 'Intra-Day Range Fever', '', fever_fig)) reports.append(AnalysisReport(symbol, slice_start_date, slice_end_date, 'Distribution of Intra-day Range', h.report(date_slice, delta), dist_fig)) return reports
def analyse_daily_open_to_close_movement(symbol, dates, openn, close, start_date, end_date, gen_title) : (start_idx, end_idx) = get_start_end_idxs(dates, start_date, end_date) # cut time slice # date_slice = dates[start_idx : end_idx] slice_start_date = dates[start_idx] slice_end_date = dates[end_idx] open_slice = openn[start_idx : end_idx] close_slice = close[start_idx : end_idx] delta = [] for i in range(len(open_slice)): delta.append(float(100 * (close_slice[i] - open_slice[i]) / close_slice[i]) ) # ------------------------------------- # % intra-day movement - time series # generate matplotlib plot # x = np.array(date_slice) y = np.array(delta) fever_fig = plt.figure() ax = fever_fig.add_subplot(111) ax.plot(x,y) # leg = ax.legend(('Model length'), 'upper center', shadow=True) title = gen_title(symbol, '% (close - open) / open', slice_start_date, slice_end_date) ax.grid(False) ax.set_ylabel('100 * (Close - Open) / Open') ax.set_title(title) # date intervals & markersanalyse_daily_open_to_close_movement (formatter, locator) = tick_info(slice_start_date, slice_end_date) ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_major_locator(locator) fever_fig.autofmt_xdate(rotation=90) ax.set_xlim([slice_start_date, slice_end_date]) ax.set_xlabel('Date') # ------------------------------------- # % intra-day movement - distribution h = Histogram(delta) left_edge = [] height = [] for bin in h.bins: left_edge.append(float(bin.floor)) height.append(h.bin_contrib_perc(bin)) x = np.array(left_edge) y = np.array(height) dist_fig = plt.figure() ax = dist_fig.add_subplot(111) ax.bar(x, y, width=h.bins[0].range) ax.set_xlim(h.min, h.max) ax.set_ylabel('% of Population') ax.set_xlabel('Move i.t.o Open : 100 * (Close - Open) / Open') title = gen_title(symbol, 'Distribution of Daily Movements', slice_start_date, slice_end_date) ax.set_title(title) reports = [] reports.append(AnalysisReport(symbol, slice_start_date, slice_end_date, 'Day Move Fever', '', fever_fig)) reports.append(AnalysisReport(symbol, slice_start_date, slice_end_date, 'Distribution of Daily Moves', '', dist_fig)) return reports