Ruby或Python中的财务图表/图表

前端之家收集整理的这篇文章主要介绍了Ruby或Python中的财务图表/图表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
RubyPython等高级语言中创建财务开放高低关闭(OHLC)图表的最佳选择是什么?虽然似乎有很多图形的选择,我没有看到任何宝石或鸡蛋与这种图表.

http://en.wikipedia.org/wiki/Open-high-low-close_chart(但我不需要移动平均线或布林带)

JFreeChart可以在Java中执行此操作,但我希望使我的代码尽可能小而简单.

谢谢!

解决方法

您可以使用 matplotlibmatplotlib.pyplot.bar的可选底部参数.然后可以使用线条图来表示开盘价和收盘价:

例如:

#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import lines

import random


deltas = [4,6,13,18,15,14,10,9,1,2,4,11,16,17,12,7,8,16]
bases = [46,49,45,44,51,52,56,58,53,57,62,63,68,66,65,61,64,60,59,54,50,48,43,42,38,37,39,47,43]


def rand_pt(bases,deltas):
    return [random.randint(base,base + delta) for base,delta in zip(bases,deltas)]

# randomly assign opening and closing prices 
openings = rand_pt(bases,deltas)
closings = rand_pt(bases,deltas)

# First we draw the bars which show the high and low prices
# bottom holds the low price while deltas holds the difference 
# between high and low.
width = 0
ax = plt.axes()
rects1 = ax.bar(np.arange(50),deltas,width,color='r',bottom=bases)

# Now draw the ticks indicating the opening and closing price
for opening,closing,bar in zip(openings,closings,rects1):
    x,w = bar.get_x(),0.2

    args = {
    }

    ax.plot((x - w,x),(opening,opening),**args)
    ax.plot((x,x + w),(closing,closing),**args)


plt.show()

创建一个这样的情节:

很明显,你想把它打包成一个使用(打开,关闭,最小,最大)元组绘制图形的函数(你可能不想随机分配你的开价和收盘价).

原文链接:https://www.f2er.com/ruby/271964.html

猜你在找的Ruby相关文章