Skip to content

Instantly share code, notes, and snippets.

@utahta
Created March 25, 2012 06:38
Show Gist options
  • Save utahta/2191883 to your computer and use it in GitHub Desktop.
Save utahta/2191883 to your computer and use it in GitHub Desktop.
3月末優待逆日歩
# coding:utf-8
require 'rubygems'
require 'jpstock'
# 逆日歩最高料率の計算
def max_gyakuhibu(price, lot)
m = price * lot
g = (m / 50000.0).ceil * 100
g = g / lot.to_f
if g <= 1
g = 1.5
else
g = g.ceil
end
return g
end
# 注意喚起銘柄 倍率返す
def chuuikanki(code)
if code == '4337' or code == '7616' or code == '4837'
return 2
end
return 1
end
class YutaiData
attr_accessor :code, :name, :benefit, :gyakuhibu, :cost, :loss, :rate
def initialize(code, name, price, lot, yutai_lot, benefit)
@code = code
@name = name
@price = price
@lot = lot
@benefit = benefit
@gyakuhibu = max_gyakuhibu(price, lot) * 4 * 3 * chuuikanki(code) # 権利日 * 3月末日数 * 注意喚起
@cost = (@gyakuhibu * yutai_lot).to_i # 逆日歩最高料率 * 優待取得に必要な株数
@loss = @benefit - @cost
@rate = (@loss / @benefit.to_f * 100).round(1)
end
def debug()
print "コード:#{@code} 会社名:#{@name} 株価:#{@price} 単元:#{@lot}\n"
print "逆日歩:#{@gyakuhibu} コスト:#{@cost} 損失:#{@loss}\n"
end
end
# 証券コード => [優待に必要な株数, 優待額]
codes = {2269 => [100, 2000],
2284 => [1000, 5000],
2669 => [100, 3000],
2922 => [100, 2000],
4337 => [100, 2500],
4800 => [1, 500],
4837 => [100, 2625],
6287 => [100, 1000],
6875 => [100, 3000],
7291 => [100, 1000],
7313 => [100, 3000],
7616 => [500, 10000],
7942 => [100, 3000],
8920 => [100, 1000],
9405 => [100, 500],
9857 => [500, 1000]}
quotes = JpStock.quote(:code => codes.keys)
results = []
quotes.keys.each do |code|
results.push(YutaiData.new(code,
quotes[code].company_name,
quotes[code].close,
quotes[code].round_lot,
codes[code.to_i][0],
codes[code.to_i][1]))
end
output = <<EOS
<table>
<tr>
<th>コード</th><th>企業名</th><th>逆日歩</th><th>優待額</th><th>コスト</th><th>損益</th><th>率</th>
</tr>
EOS
results.sort{|a, b|
a.rate <=> b.rate
}.reverse.each{|d|
output += <<EOS
<tr>
<td>#{d.code}</td><td>#{d.name}</td><td>#{d.gyakuhibu}</td><td>#{d.benefit}</td><td>#{d.cost}</td>
EOS
output += d.loss >= 0 ? "<td><font color=red>+#{d.loss}</font></td>" : "<td><font color=blue>#{d.loss}</font></td>"
output += "<td>#{d.rate}</td>"
output += "</tr>"
}
output += <<EOS
</table>
EOS
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment