rirera 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +1 -0
  3. data/bin/rirera +16 -15
  4. data/lib/rirera.rb +76 -97
  5. data/rirera.gemspec +10 -10
  6. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc634ff48092a4b274b8109a507496d6ceb901e2
4
- data.tar.gz: 07120b6a6c0508961557d6869f24a51e7479ce2b
3
+ metadata.gz: d91562e734a4fe07401d9108022647b8d07beca7
4
+ data.tar.gz: 1c7e9cbe92fa0a6265159b930e9183dae67b92bb
5
5
  SHA512:
6
- metadata.gz: 8109aa7e63f1a402d552a5ec0f1e4de718d1faf92fb2c4b9e5ff43a7b21622a1c3171e5aeaea056169911650de7aa4e0b542e6a374caf96d65cc02486fa9aed3
7
- data.tar.gz: e66eb730e439c1ad799df47ea03266699cdc4618537436661b78d431891a72bba02972ba01f805af86676654ce7bf783d551332bfc83c459ae4bceaa07a37986
6
+ metadata.gz: a44403f07e6c0d168e3ac2ffe8529b05c709e5fb56a584316b74a3cff47155acb7a854e1d7e529898d5d17cf49907f18f8b942debb46d798a9e5f01ff49c1818
7
+ data.tar.gz: 024ebe3a80b5d0af4dcf181b55ce0e081413ad99b5969a413daf74db93f19147f04f9f386fbb28f8fdc21acf88d6e072be7024de5ee70417a7770f697bf1537a
data/CHANGELOG CHANGED
@@ -4,3 +4,4 @@ Version 0.1.2: added screenshot to README.rdoc
4
4
  Version 0.1.3: class refactoring/encapsulation
5
5
  Version 0.1.4: adding proper cli
6
6
  Version 0.1.5: adding dependencies
7
+ Version 0.2.0: modularize rirera
data/bin/rirera CHANGED
@@ -7,20 +7,21 @@ def input
7
7
  begin
8
8
  while true do
9
9
  system "clear"
10
- rrr = Rirera.new
11
- rrr.broker = rrr.get_broker(@opts[:broker])
10
+ broker = Rirera.get_broker(@opts[:broker])
12
11
  print "volume: "
13
- rrr.volume = rrr.sanity_check($stdin.gets)
12
+ volume = Rirera.sanity_check($stdin.gets)
14
13
  print "target price: "
15
- rrr.target = rrr.sanity_check($stdin.gets)
14
+ target = Rirera.sanity_check($stdin.gets)
16
15
  print "actual price: "
17
- rrr.actual = rrr.sanity_check($stdin.gets)
16
+ actual = Rirera.sanity_check($stdin.gets)
17
+ stop = nil
18
18
  loop do
19
19
  print "stop loss: "
20
- rrr.stop = rrr.stop_loss(rrr.actual, rrr.sanity_check($stdin.gets))
21
- puts "stop loss has to be lower than actual price" if rrr.stop.nil?
22
- break unless rrr.stop.nil?
20
+ stop = Rirera.stop_loss(actual, Rirera.sanity_check($stdin.gets))
21
+ puts "stop loss has to be lower than actual price" if stop.nil?
22
+ break unless stop.nil?
23
23
  end
24
+ rrr = Rirera::Record.new(broker, volume, target, actual, stop)
24
25
  rrr.print_result
25
26
  puts ""
26
27
  puts "Again? (y/n)"
@@ -46,13 +47,13 @@ def main
46
47
  if @opts[:loop_given]
47
48
  input
48
49
  else
49
- rrr = Rirera.new
50
- rrr.broker = rrr.get_broker(@opts[:broker])
51
- rrr.volume = @opts[:volume_given] ? @opts[:volume] : abort("missing volume")
52
- rrr.target = @opts[:target_given] ? @opts[:target] : abort("missing target")
53
- rrr.actual = @opts[:actual_given] ? @opts[:actual] : abort("missing actual")
54
- rrr.stop = @opts[:stop_given] ? rrr.stop_loss(rrr.actual,@opts[:stop]) : abort("missing stop")
55
- abort("stop loss has to be lower than actual price") if rrr.stop.nil?
50
+ broker = Rirera.get_broker(@opts[:broker])
51
+ volume = @opts[:volume_given] ? @opts[:volume] : abort("missing volume")
52
+ target = @opts[:target_given] ? @opts[:target] : abort("missing target")
53
+ actual = @opts[:actual_given] ? @opts[:actual] : abort("missing actual")
54
+ stop = @opts[:stop_given] ? Rirera.stop_loss(actual,@opts[:stop]) : abort("missing stop")
55
+ abort("stop loss has to be lower than actual price") if stop.nil?
56
+ rrr = Rirera::Record.new(broker, volume, target, actual, stop)
56
57
  rrr.print_result
57
58
  end
58
59
  end
data/lib/rirera.rb CHANGED
@@ -1,65 +1,90 @@
1
1
  require 'colorize'
2
2
  require 'yaml'
3
3
 
4
- class Rirera
5
- attr_accessor :broker, :volume, :target, :actual, :stop
4
+ module Rirera
5
+ CONFIG = YAML.load_file(File.join(File.expand_path("..", File.dirname(__FILE__)),"conf/rirera.yml"))
6
+
7
+ class Record
8
+ attr_accessor :broker, :volume, :target, :actual, :stop
9
+
10
+ def initialize(broker, volume, target, actual, stop)
11
+ @broker = Rirera.get_broker(broker)
12
+ @volume = volume
13
+ @target = target
14
+ @actual = actual
15
+ @stop = stop
16
+ end
6
17
 
7
- def initialize
8
- @conf = load_config
9
- end
18
+ def get_rrr
19
+ chance = @target - @actual
20
+ risk = @actual - @stop
21
+ (chance/risk).round(1)
22
+ end
10
23
 
11
- def get_broker(broker)
12
- unless @conf['broker'][broker].nil?
13
- broker
14
- else
15
- abort "Not a valid broker"
24
+ def get_total_commission
25
+ # calculate order pricing
26
+ basic_price = Rirera::CONFIG['broker'][@broker]['basic_price']
27
+ commission_rate = Rirera::CONFIG['broker'][@broker]['commission_rate']
28
+ volume_rate_buy = (get_amount * @actual * commission_rate).round(2)
29
+ volume_rate_sell = (get_amount * @target * commission_rate).round(2)
30
+ total_commission = 0.0
31
+
32
+ [volume_rate_buy, volume_rate_sell].each do |vr|
33
+ if (vr + basic_price) > Rirera::CONFIG['broker'][@broker]['min_rate']
34
+ if (vr + basic_price) > Rirera::CONFIG['broker'][@broker]['max_rate']
35
+ total_commission += Rirera::CONFIG['broker'][@broker]['max_rate']
36
+ else
37
+ total_commission += (basic_price + vr)
38
+ end
39
+ else
40
+ total_commission += Rirera::CONFIG['broker'][@broker]['min_rate']
41
+ end
42
+ end
43
+ total_commission.round(2)
16
44
  end
17
- end
18
45
 
19
- def decorate
20
- 12.times do
21
- print "#"
46
+ def get_amount
47
+ (@volume/@actual).round
22
48
  end
23
- end
24
49
 
25
- def print_title
26
- puts "€$€$€$€$€$€$€$€$€$€$€"
27
- puts "€ Risk Reward Ratio €"
28
- puts "€$€$€$€$€$€$€$€$€$€$€"
29
- puts "| / "
30
- puts "| _ /\\_ / "
31
- puts "| / \\/ \\/ "
32
- puts "| /\\/ "
33
- puts "|_/ "
34
- puts "L___________________ "
35
- puts ""
36
- end
50
+ def get_max_gain
51
+ ((get_amount * @target) - @volume - get_total_commission).round(2)
52
+ end
37
53
 
38
- def print_rrr
39
- decorate
40
- print "\n# RRR: "
41
- print "#{get_rrr}".yellow
42
- puts " #"
43
- decorate
44
- end
54
+ def get_loss
55
+ ((@volume-(get_amount*@stop)) + get_total_commission).round(2)
56
+ end
45
57
 
46
- def print_result
47
- print_rrr
48
- puts ""
49
- puts ""
50
- puts "Volume: #{@volume}"
51
- puts "Amount: #{get_amount}"
52
- puts "Gain: #{get_max_gain}".green
53
- puts "Loss: #{get_loss}".red
54
- puts "Commission: #{get_total_commission}".magenta
55
- puts "Break Even: #{get_break_even}".blue
58
+ def get_break_even
59
+ ((@volume + get_total_commission) / get_amount).round(2)
60
+ end
61
+
62
+ def print_result
63
+ 12.times { print "#" }
64
+ print "\n# RRR: "
65
+ print "#{get_rrr}".yellow
66
+ puts " #"
67
+ 12.times { print "#" }
68
+ 2.times { puts "" }
69
+ puts "Volume: #{@volume}"
70
+ puts "Amount: #{get_amount}"
71
+ puts "Gain: #{get_max_gain}".green
72
+ puts "Loss: #{get_loss}".red
73
+ puts "Commission: #{get_total_commission}".magenta
74
+ puts "Break Even: #{get_break_even}".blue
75
+ end
56
76
  end
57
77
 
58
- def load_config
59
- YAML.load_file(File.join(File.expand_path("..", File.dirname(__FILE__)),"conf/rirera.yml"))
78
+ def Rirera.get_broker(broker)
79
+ unless Rirera::CONFIG['broker'][broker].nil?
80
+ broker
81
+ else
82
+ abort "Not a valid broker"
83
+ end
60
84
  end
61
85
 
62
- def stop_loss(actual_price, stop_loss)
86
+
87
+ def Rirera.stop_loss(actual_price, stop_loss)
63
88
  if stop_loss >= actual_price
64
89
  nil
65
90
  else
@@ -67,63 +92,17 @@ class Rirera
67
92
  end
68
93
  end
69
94
 
70
- def sanity_check(num)
95
+ def Rirera.sanity_check(num)
71
96
  num.chomp!.gsub!(",",".")
72
97
  # only allow int and float
73
- unless is_numeric?(num)
74
- puts "Wrong input"
75
- abort
98
+ unless Rirera.is_numeric?(num)
99
+ abort "Wrong input"
76
100
  else
77
101
  num.to_f
78
102
  end
79
103
  end
80
104
 
81
- def is_numeric?(s)
105
+ def Rirera.is_numeric?(s)
82
106
  !!Float(s) rescue false
83
107
  end
84
-
85
- def get_rrr
86
- chance = @target - @actual
87
- risk = @actual - @stop
88
- (chance/risk).round(1)
89
- end
90
-
91
- def get_total_commission
92
- # calculate order pricing
93
- basic_price = @conf['broker'][@broker]['basic_price']
94
- commission_rate = @conf['broker'][@broker]['commission_rate']
95
- volume_rate_buy = (get_amount * @actual * commission_rate).round(2)
96
- volume_rate_sell = (get_amount * @target * commission_rate).round(2)
97
- total_commission = 0.0
98
-
99
- [volume_rate_buy, volume_rate_sell].each do |vr|
100
- if (vr + basic_price) > @conf['broker'][@broker]['min_rate']
101
- if (vr + basic_price) > @conf['broker'][@broker]['max_rate']
102
- total_commission += @conf['broker'][@broker]['max_rate']
103
- else
104
- total_commission += (basic_price + vr)
105
- end
106
- else
107
- total_commission += @conf['broker'][@broker]['min_rate']
108
- end
109
- end
110
- total_commission.round(2)
111
- end
112
-
113
- def get_amount
114
- (@volume/@actual).round
115
- end
116
-
117
- def get_max_gain
118
- ((get_amount * @target) - @volume - get_total_commission).round(2)
119
- end
120
-
121
- def get_loss
122
- ((@volume-(get_amount*@stop)) + get_total_commission).round(2)
123
- end
124
-
125
- def get_break_even
126
- ((@volume + get_total_commission) / get_amount).round(2)
127
- end
128
-
129
108
  end
data/rirera.gemspec CHANGED
@@ -1,19 +1,19 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'rirera'
3
- s.version = '0.1.5'
4
- s.date = Time.now.strftime('%Y-%m-%d')
2
+ s.name = "rirera"
3
+ s.version = "0.2.0"
4
+ s.date = Time.now.strftime("%Y-%m-%d")
5
5
  s.summary = "Risk Reward Ratio"
6
6
  s.description = "A simple Risk Reward Ratio calculator"
7
7
  s.authors = ["Maximilian Meister"]
8
- s.email = 'mmeister@suse.de'
9
- s.rubyforge_project = 'rirera'
8
+ s.email = "mmeister@suse.de"
9
+ s.rubyforge_project = "rirera"
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- s.bindir = 'bin'
12
+ s.bindir = "bin"
13
13
  s.require_paths = ["lib"]
14
- s.homepage = 'http://github.com/MaximilianMeister/rirera'
15
- s.license = 'MIT'
16
- s.add_dependency("colorize", ["~> 0.7.3"])
14
+ s.homepage = "http://github.com/MaximilianMeister/rirera"
15
+ s.license = "MIT"
16
+ s.add_dependency("colorize", ["~> 0.7", ">= 0.7.3"])
17
17
  s.add_dependency("trollop", ["2.0"])
18
- s.post_install_message = 'Happy trading!'
18
+ s.post_install_message = "Happy trading!"
19
19
  end
metadata CHANGED
@@ -1,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rirera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximilian Meister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-20 00:00:00.000000000 Z
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.7.3
20
23
  type: :runtime
@@ -22,6 +25,9 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.7'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.7.3
27
33
  - !ruby/object:Gem::Dependency