Class: Rirera::Record
- Inherits:
-
Object
- Object
- Rirera::Record
- 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
- #get_amount ⇒ Object
- #get_break_even ⇒ Object
- #get_loss ⇒ Object
- #get_max_gain ⇒ Object
- #get_rrr ⇒ Object
- #get_total_commission ⇒ Object
-
#initialize(broker, volume, target, actual, stop) ⇒ Record
constructor
A new instance of Record.
- #print_result ⇒ Object
Constructor Details
#initialize(broker, volume, target, actual, stop) ⇒ Record
Returns a new instance of Record.
10 11 12 13 14 15 16 |
# File 'lib/rirera.rb', line 10 def initialize(broker, volume, target, actual, stop) @broker = Rirera.get_broker(broker) @volume = volume @target = target @actual = actual @stop = stop end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
8 9 10 |
# File 'lib/rirera.rb', line 8 def actual @actual end |
#broker ⇒ Object
Returns the value of attribute broker.
8 9 10 |
# File 'lib/rirera.rb', line 8 def broker @broker end |
#stop ⇒ Object
Returns the value of attribute stop.
8 9 10 |
# File 'lib/rirera.rb', line 8 def stop @stop end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/rirera.rb', line 8 def target @target end |
#volume ⇒ Object
Returns the value of attribute volume.
8 9 10 |
# File 'lib/rirera.rb', line 8 def volume @volume end |
Instance Method Details
#get_amount ⇒ Object
46 47 48 |
# File 'lib/rirera.rb', line 46 def get_amount (@volume/@actual).round end |
#get_break_even ⇒ Object
58 59 60 |
# File 'lib/rirera.rb', line 58 def get_break_even ((@volume + get_total_commission) / get_amount).round(2) end |
#get_loss ⇒ Object
54 55 56 |
# File 'lib/rirera.rb', line 54 def get_loss ((@volume-(get_amount*@stop)) + get_total_commission).round(2) end |
#get_max_gain ⇒ Object
50 51 52 |
# File 'lib/rirera.rb', line 50 def get_max_gain ((get_amount * @target) - @volume - get_total_commission).round(2) end |
#get_rrr ⇒ Object
18 19 20 21 22 |
# File 'lib/rirera.rb', line 18 def get_rrr chance = @target - @actual risk = @actual - @stop (chance/risk).round(1) end |
#get_total_commission ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rirera.rb', line 24 def get_total_commission # calculate order pricing basic_price = Rirera::CONFIG['broker'][@broker]['basic_price'] commission_rate = Rirera::CONFIG['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) > Rirera::CONFIG['broker'][@broker]['min_rate'] if (vr + basic_price) > Rirera::CONFIG['broker'][@broker]['max_rate'] total_commission += Rirera::CONFIG['broker'][@broker]['max_rate'] else total_commission += (basic_price + vr) end else total_commission += Rirera::CONFIG['broker'][@broker]['min_rate'] end end total_commission.round(2) end |
#print_result ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rirera.rb', line 62 def print_result 12.times { print "#" } print "\n# RRR: " print "#{get_rrr}".yellow puts " #" 12.times { print "#" } 2.times { 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 |