本文整理汇总了Python中histogram.Histogram.bin_contrib_perc方法的典型用法代码示例。如果您正苦于以下问题:Python Histogram.bin_contrib_perc方法的具体用法?Python Histogram.bin_contrib_perc怎么用?Python Histogram.bin_contrib_perc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类histogram.Histogram
的用法示例。
在下文中一共展示了Histogram.bin_contrib_perc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_intraday_volatility_plots
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import bin_contrib_perc [as 别名]
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
示例2: analyse_daily_open_to_close_movement
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import bin_contrib_perc [as 别名]
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