lib/cotcube-bardata/suggest.rb
# based on day(of year) and symbol, suggest best fitting contract
based on day(of year) and symbol, suggest best fitting contract
based on day ( of year ) and symbol suggest best fitting contract
def suggest_contract_for symbol:, date: Date.today, warnings: true
      ml = Cotcube::Bardata.continuous_table symbol: symbol, date: date, silent: true
      if ml.size != 1 
	puts "WARNING: No or no unique most liquid found for #{date}. please give :contract parameter".light_yellow if warnings
	if ml.size > 1
	  puts "\tUsing #{ml.last}. Consider breaking here, if that is not acceptable.".light_yellow if warnings
	  sleep 1
	else
	  puts "\tERROR: No suggestible contract found for #{symbol} and #{date}.".light_red
	  return
	end
      end
      year = date.year % 100
      if ml.last[2] < "K" and date.month > 9
        "#{ml.last}#{year + 1}"
      else
        "#{ml.last}#{year}"
      end
    end
def suggest_contract_for symbol : , date : Date . today , warnings : true ml = Cotcube :: Bardata . continuous_table symbol : symbol , date : date , silent : true if ml . size != 1 puts "WARNING: No or no unique most liquid found for #{date}. please give :contract parameter" . light_yellow if warnings if ml . size > 1 puts "\tUsing #{ml.last}. Consider breaking here, if that is not acceptable." . light_yellow if warnings sleep 1 else puts "\tERROR: No suggestible contract found for #{symbol} and #{date}." . light_red return end end year = date . year % 100 if ml . last [ 2 ] < "K" and date . month > 9 "#{ml.last}#{year + 1}" else "#{ml.last}#{year}" end end
based on day(of year) and symbol, suggest best fitting contract
based on day ( of year ) and symbol suggest best fitting contract
symbol
<not_specific>
date
<not_specific>
today
<not_specific>
warnings
<not_specific>