Ruby 或 Python 中的金融图表/图形
使用 Ruby 或 Python 等高级语言创建金融开盘价-最高价-最低价-收盘价 (OHLC) 图表的最佳选择是什么? 虽然似乎有很多图表选项,但我还没有看到任何带有这种图表的宝石或鸡蛋。
http://en.wikipedia.org/wiki/Open-high-low-close_chart (但我不需要移动平均线或布林线)
JFreeChart 可以在 Java 中做到这一点,但我想让我的代码库尽可能小和简单。
谢谢!
What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.
http://en.wikipedia.org/wiki/Open-high-low-close_chart (but I don't need the moving average or Bollinger bands)
JFreeChart can do this in Java, but I'd like to make my codebase as small and simple as possible.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以使用 matplotlib 和 matplotlib.pyplot.bar。 然后,您可以使用线
plot
来指示开盘价和收盘价:例如:
创建如下图:
显然,您希望将其打包在一个使用
(open, close, min, max)
元组绘制绘图的函数中(并且您可能不会想要随机分配您的开盘价和收盘价)。You can use matplotlib and the the optional
bottom
parameter of matplotlib.pyplot.bar. You can then use lineplot
to indicate the opening and closing prices:For example:
creates a plot like this:
Obviously, you'd want to package this up in a function that drew the plot using
(open, close, min, max)
tuples (and you probably wouldn't want to randomly assign your opening and closing prices).您可以将 Pylab (
matplotlib.finance
) 与 Python 结合使用。 以下是一些示例:http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo。 html 。 Beginning Python Visualization 中有一些专门讨论此问题的好材料。更新:我认为您可以使用 matplotlib.finance.candlestick 来实现日本烛台效果。
You can use Pylab (
matplotlib.finance
) with Python. Here are some examples: http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html . There is some good material specifically on this problem in Beginning Python Visualization.Update: I think you can use matplotlib.finance.candlestick for the Japanese candlestick effect.
您是否考虑过使用 R 和 quantmod 包? 它可能正是您所需要的。
Have you considered using R and the quantmod package? It likely provides exactly what you need.
有关使用 matplotlib 的财务图 (OHLC) 的一些示例可以在此处找到:
财务演示
Some examples about financial plots (OHLC) using matplotlib can be found here:
finance demo
您可以自由地使用 JRuby 而不是 Ruby 吗? 这样您就可以使用 JFreeChart,而且您的代码仍将使用 Ruby
Are you free to use JRuby instead of Ruby? That'd let you use JFreeChart, plus your code would still be in Ruby
请查看 WHIFF 的 Open Flash Chart 嵌入
http://aaron.oirt.rutgers.edu/myapp/docs/W1100_1600。打开FlashCharts
蜡烛图的示例位于顶部。 这将是特别
适合嵌入网页。
Please look at the Open Flash Chart embedding for WHIFF
http://aaron.oirt.rutgers.edu/myapp/docs/W1100_1600.openFlashCharts
An example of a candle chart is right at the top. This would be especially
good for embedding in web pages.
如果您喜欢示例的外观,Open Flash Chart 是不错的选择。 我已经转移到 JavaScript/Canvas 库,例如用于 HTML 嵌入图表的 Flot更具可定制性,无需太多黑客攻击即可获得所需的效果(http://itprolife.worona.eu/2009/08/scatter-chart-library-moving-to-flot.html)。
Open Flash Chart is nice choice if you like the look of examples. I've moved to JavaScript/Canvas library like Flot for HTML embedded charts, as it is more customizable and I get desired effect without much hacking (http://itprolife.worona.eu/2009/08/scatter-chart-library-moving-to-flot.html).
这是我几天前使用 Matplotlib 绘制的股票图表,我也发布了源代码,供您参考: StockChart_Matplotlib
This is the stock chart I draw just days ago using Matplotlib, I've posted the source too, for your reference: StockChart_Matplotlib