9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mytradewizard/yahoo.rb', line 9
def OHLC(symbol, days, end_date = Date.today)
sd = start_date(end_date, days)
u = url(symbol, sd.month - 1, sd.day, sd.year, end_date.month, end_date.day, end_date.year, 'd')
csv = CSV.parse(open(u))
= csv.first
if (Date.parse(csv[1][0]) == end_date)
day = 0
else
day = -1
end
row = 1
daily_bars = MyTradeWizard::DailyBars.new
while (daily_bars.length < days)
bar = Hash.new
csv[row].each_with_index do |col, i|
name = [i]
value = csv[row][i]
if name == "Date"
value = Date.parse(value)
elsif ["Open", "High", "Low", "Close", "Adj Close"].include?(name)
value = value.to_f
elsif name == "Volume"
value = value.to_i
end
bar[name] = value
end
daily_bars.add(day, MyTradeWizard::OHLC.new(bar))
row += 1
day -= 1
end
daily_bars
end
|