This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
#static var | |
TIMESLICE = 20 | |
FIBONACCI_RATIO_1_3 = 1.382.to_f | |
FIBONACCI_RATIO_1_6 = 1.6185.to_f | |
#schema: Date,Open,High,Low,Close,Volume,Adj Close | |
#read data | |
rawdata = File.read("data.csv") | |
data = Array.new | |
csv = CSV.new(rawdata, :headers => true, :header_converters => :symbol) | |
csv.to_a.map do |row| | |
data << row.to_hash | |
end | |
data.each_slice(TIMESLICE).each do |dataSlice| | |
#get min and max value for the given time slide | |
highRow = dataSlice.max{ |x,y| x[:high].to_f <=> y[:high].to_f} | |
lowRow = dataSlice.min{ |x,y| x[:low].to_f <=> y[:low].to_f} | |
puts "High: #{highRow}" | |
puts "Low: #{lowRow}" | |
#calculate the diffenz | |
differenz = highRow[:high].to_f - lowRow[:low].to_f | |
puts differenz | |
if Date.parse(highRow[:date]) > Date.parse(lowRow[:date]) | |
puts "uptrend" | |
#calculate next posible values for this uptrend | |
puts "next up:" | |
puts "0.382 ratio: #{lowRow[:low].to_f + (differenz * FIBONACCI_RATIO_1_3)}" | |
puts "0.618 ratio: #{lowRow[:low].to_f + (differenz * FIBONACCI_RATIO_1_6)}" | |
else | |
puts "downtrend" | |
#calculate next posible values for this downtrend | |
puts "next up:" | |
puts "0.382 ratio: #{highRow[:high].to_f - (differenz * FIBONACCI_RATIO_1_3)}" | |
puts "0.618 ratio: #{highRow[:high].to_f - (differenz * FIBONACCI_RATIO_1_6)}" | |
end | |
puts "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment