Class: Rirera
- Inherits:
-
Object
- Object
- Rirera
- Defined in:
- lib/rirera.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#broker ⇒ Object
Returns the value of attribute broker.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#target ⇒ Object
Returns the value of attribute target.
-
#volume ⇒ Object
Returns the value of attribute volume.
Instance Method Summary collapse
- #decorate ⇒ Object
- #get_amount ⇒ Object
- #get_break_even ⇒ Object
- #get_broker(broker) ⇒ Object
- #get_loss ⇒ Object
- #get_max_gain ⇒ Object
- #get_rrr ⇒ Object
- #get_total_commission ⇒ Object
-
#initialize ⇒ Rirera
constructor
A new instance of Rirera.
- #is_numeric?(s) ⇒ Boolean
- #load_config ⇒ Object
- #print_result ⇒ Object
- #print_rrr ⇒ Object
- #print_title ⇒ Object
- #sanity_check(num) ⇒ Object
- #stop_loss(actual_price, stop_loss) ⇒ Object
Constructor Details
#initialize ⇒ Rirera
Returns a new instance of Rirera.
7 8 9 |
# File 'lib/rirera.rb', line 7 def initialize @conf = load_config end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
5 6 7 |
# File 'lib/rirera.rb', line 5 def actual @actual end |
#broker ⇒ Object
Returns the value of attribute broker.
5 6 7 |
# File 'lib/rirera.rb', line 5 def broker @broker end |
#stop ⇒ Object
Returns the value of attribute stop.
5 6 7 |
# File 'lib/rirera.rb', line 5 def stop @stop end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'lib/rirera.rb', line 5 def target @target end |
#volume ⇒ Object
Returns the value of attribute volume.
5 6 7 |
# File 'lib/rirera.rb', line 5 def volume @volume end |
Instance Method Details
#decorate ⇒ Object
19 20 21 22 23 |
# File 'lib/rirera.rb', line 19 def decorate 12.times do print "#" end end |
#get_amount ⇒ Object
113 114 115 |
# File 'lib/rirera.rb', line 113 def get_amount (@volume/@actual).round end |
#get_break_even ⇒ Object
125 126 127 |
# File 'lib/rirera.rb', line 125 def get_break_even ((@volume + get_total_commission) / get_amount).round(2) end |
#get_broker(broker) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rirera.rb', line 11 def get_broker(broker) unless @conf['broker'][broker].nil? broker else abort "Not a valid broker" end end |
#get_loss ⇒ Object
121 122 123 |
# File 'lib/rirera.rb', line 121 def get_loss ((@volume-(get_amount*@stop)) + get_total_commission).round(2) end |
#get_max_gain ⇒ Object
117 118 119 |
# File 'lib/rirera.rb', line 117 def get_max_gain ((get_amount * @target) - @volume - get_total_commission).round(2) end |
#get_rrr ⇒ Object
85 86 87 88 89 |
# File 'lib/rirera.rb', line 85 def get_rrr chance = @target - @actual risk = @actual - @stop (chance/risk).round(1) end |
#get_total_commission ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rirera.rb', line 91 def get_total_commission # calculate order pricing basic_price = @conf['broker'][@broker]['basic_price'] commission_rate = @conf['broker'][@broker]['commission_rate'] volume_rate_buy = (get_amount * @actual * commission_rate).round(2) volume_rate_sell = (get_amount * @target * commission_rate).round(2) total_commission = 0.0 [volume_rate_buy, volume_rate_sell].each do |vr| if (vr + basic_price) > @conf['broker'][@broker]['min_rate'] if (vr + basic_price) > @conf['broker'][@broker]['max_rate'] total_commission += @conf['broker'][@broker]['max_rate'] else total_commission += (basic_price + vr) end else total_commission += @conf['broker'][@broker]['min_rate'] end end total_commission.round(2) end |
#is_numeric?(s) ⇒ Boolean
81 82 83 |
# File 'lib/rirera.rb', line 81 def is_numeric?(s) !!Float(s) rescue false end |
#load_config ⇒ Object
58 59 60 |
# File 'lib/rirera.rb', line 58 def load_config YAML.load_file(File.join(File.("..", File.dirname(__FILE__)),"conf/rirera.yml")) end |
#print_result ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rirera.rb', line 46 def print_result print_rrr puts "" puts "" puts "Volume: #{@volume}" puts "Amount: #{get_amount}" puts "Gain: #{get_max_gain}".green puts "Loss: #{get_loss}".red puts "Commission: #{get_total_commission}".magenta puts "Break Even: #{get_break_even}".blue end |
#print_rrr ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rirera.rb', line 38 def print_rrr decorate print "\n# RRR: " print "#{get_rrr}".yellow puts " #" decorate end |
#print_title ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rirera.rb', line 25 def print_title puts "€$€$€$€$€$€$€$€$€$€$€" puts "€ Risk Reward Ratio €" puts "€$€$€$€$€$€$€$€$€$€$€" puts "| / " puts "| _ /\\_ / " puts "| / \\/ \\/ " puts "| /\\/ " puts "|_/ " puts "L___________________ " puts "" end |
#sanity_check(num) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rirera.rb', line 70 def sanity_check(num) num.chomp!.gsub!(",",".") # only allow int and float unless is_numeric?(num) puts "Wrong input" abort else num.to_f end end |
#stop_loss(actual_price, stop_loss) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rirera.rb', line 62 def stop_loss(actual_price, stop_loss) if stop_loss >= actual_price nil else stop_loss end end |