ここ5年の金相場のグラフ描いてみた(Pythonで)

[pukiwiki]
[[ヘッダ画像:http://boxheadroom.com/wp/wp-content/themes/default/images/y.jpg]]を廃墟写真風に。割と好きな一枚

//http://weather.goo.ne.jp/earthquake/index.html
*[[金の市場価格がインドの伝統的文化と連動?(田中貴金属):http://headlines.yahoo.co.jp/videonews/fnn/20080914/20080914-00000551-fnn-int.html]]

「金相場が下がってるわりに株にマネーが戻ってきませんねー?」 って話が時々出ますが、こんな記事も。
(田中貴金属のインフォマーシャル?)

“1年ごとの価格動向を見ると、過去10年、10~12月に平均で10%も高くなるなど、季節的な動きがあり、2008年、ある投資会社がその要因を調査した。
その結果、証明されたのは、主に年末に集中するインドの結婚式シーズンに、金の相場が上がるという事実だった。

「金(きん)」買うほど、「おかね」持ってないんですけれども。。。
クリスマスシーズンにアクセサリーを買う予定のあるかたは困るかもですね
(アクセは、目方売りじゃないですけど。私には関係ないですけれども ぐすん)

とりあえず、ホントに10~12月、値動きがあるのか、どないやねん?ということで5年分ぐらいグラフ描いてみますた。
(Python,PILの勉強兼ねて)

[[データは田中貴金属より:http://gold.tanaka.co.jp/commodity/souba/m-gold.php]]

[[http://boxheadroom.com/wp/wp-content/uploads/2008/09/gold0808-300×225.png:http://boxheadroom.com/wp/wp-content/uploads/2008/09/gold0808.png]]

素人目には、あまり”上がる気がしない” グラフではあります(汗
相場なので、なんともいえませんが。

2005年までは、年末あがる、ってよりも、ふつうに一定のペースでの右肩上がりに近いけど、2006年以降は値動き激しいなぁ、とか。
(投機マネーの流入時期?)

っていうか、インドの結婚式シーズンって年末なのがおどろき(そっちかよ)

以下プログラム。
[/pukiwiki]


[pukiwiki]
今回はmatplotlib使わずにPILのみで。
なんか、すげぇ冗長。線がギザギザしてるので、大きめに描いて縮小するとよいかも。

参考記事
-[[WindowsでPILを使う:http://d.hatena.ne.jp/kinneko/20070926#p5]]

_#!-*- coding: utf8 -*-
_
_”””
_       ロンドン金価格     為替.  田中小売価格(円/グラム)
_       (米ドル/トロイオンス)T.T.S    
_                   平均(円)   
_年   月 最高  最低  平均       最高 最低  平均
_”””
_
_#田中貴金属のホームページよりコピペ
_#http://gold.tanaka.co.jp/commodity/souba/m-gold.php
_
_txt=”””
_2008
_08 912.50 784.75 839.71 110.34 3,185 2,838 2,983
_以下略
_
_”””
_
_txt=txt.replace(“\t”,” “)
_txt=txt.replace(“,”,””)
_#”””
_#       ロンドン金価格     為替.  田中小売価格(円/グラム)
_#       (米ドル/トロイオンス)T.T.S    
_#                   平均(円)   
_#年   月 最高  最低  平均       最高 最低  平均
_#”””
_import re
_
_pat=re.compile(
_ #r”(?P\d{4})\s+”
_ r”\s*(?P\d{2})\s+”\
_ r”(?P\d{2,4}\.\d{2})\s+”\
_ r”(?P\d{2,4}\.\d{2})\s+”\
_ r”(?P\d{2,4}\.\d{2})\s+”\
_ r”(?P\d{3}\.\d{2})\s+”\
_ r”(?P\d{2,4})\s+”\
_ r”(?P\d{2,4})\s+”\
_ r”(?P\d{2,4})*”
_ )
_
_import Image,ImageDraw,ImageFont
_import colorsys
_
_im=Image.new(“RGB”,(640,480),color=(255,255,255))
_draw=ImageDraw.ImageDraw(im)
_dat=[]
_y=0
_for i in txt.splitlines():
_ ret = re.match(r”(\d{4})”,i)
_ if ret :
_ y=int(ret.groups()[0])
_ else:
_ ret=pat.match(i)
_ if ret :
_ g=ret.groupdict()
_ g[“year”]=y
_ dat.append(g)
_
_
_years=[x[“year”] for x in dat]
_years=sorted(set(years))
_print years
_
_low=min([float(x[“low1”]) for x in dat])
_high=max([float(x[“high1”] ) for x in dat])
_
_low=int(round(float(low)/100.0-0,25))*100
_high=int(round(float(high)/100.0+0.25))*100
_h=high-low
_
_print high,low
_font = ImageFont.truetype(“C:\\Windows\\Fonts\\msgothic.ttc”, 24)
_font2 = ImageFont.truetype(“C:\\Windows\\Fonts\\msgothic.ttc”, 32)
_huelist=range(6)
_colors=range(6)
_for i in range(6):
_ hue=float(i)/6.0
_ c=colors[i]=colorsys.hsv_to_rgb(hue,1,240)
_ huelist[i]=hue
_ print c
_
_for i in xrange(1,12+1) :
_ x= (i+1) *640/14-12
_ y=440
_ draw.text( (x,y), str(i), fill=(0,0,0),font=font)
_
_for i in xrange(low,high+1,100,) :
_ x=14
_ y=440-400*(i-low )/h-12
_ print x,y
_ draw.text( (x,y), str(i), fill=(0,0,0),font=font)
_
_for i in years:
_ d=sorted( [ [x[“month”],x] for x in dat if x[“year”]==i])
_ d=[x[1] for x in d]
_ col=colors[ i%6]
_ xy=[]
_ xy1=[]
_ xy2=[]
_ for j in d :
_ x=(int(j[“month”] )+1)*640/14
_ y = 440-400*(float(j[“avg1”])-low )/h
_ y2=440-400*(float(j[“low1”])-low )/h
_ y1=440-400*(float(j[“high1″])-low )/h
_ draw.line((x,y1,x,y2),fill=col,width=2)
_ xy.append((x,y))
_ draw.line(xy,fill=col,width=2)
_
_ draw.text( (x,y), str(i), fill=colorsys.hsv_to_rgb(huelist[i%6],1,128), font=font)
_draw.text( (32,0), u”ロンドン金価格 (米ドル/トロイオンス)”,
_ fill=colorsys.hsv_to_rgb(huelist[i%6],1,128), font=font)
_
_im.save(“gold0808.png”)
_
[/pukiwiki]

コメントを残す

メールアドレスが公開されることはありません。