rirera 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 214285bfd9c1c0a70bfc56ffd8b9abf67134187c
4
+ data.tar.gz: e16936a720fc8c7918fd0b5ce3e80c5dc5040bcb
5
+ SHA512:
6
+ metadata.gz: 09961019489e7fab80f0f492cd89099601ccc1e873277fca98bef3fa8980bc8c7bc606215758f6c59266ab7fe99c34933f29a911336581d93ff174b081dabad7
7
+ data.tar.gz: ba552717db07623db0aa18601cda364d71e49349aa6b773db067c15a3f091d876bbe5db49360e2a88c5627df01e01f1c6c45fcc280d9fb678f1108cb0990041e
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem "colorize", "~> 0.7.3"
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # rirera
2
+
3
+ http://github.com/MaximilianMeister/rirera
4
+
5
+ ## What is rirera?
6
+
7
+ A small command line tool to calculate a risk reward ratio.
8
+
9
+ ## Configuration
10
+
11
+ Add your broker, and its specific commision rates to `conf/rirera.yml`
12
+
13
+ ## Installation
14
+
15
+ `gem install 'rirera'`
16
+
17
+ ## Run
18
+
19
+ `rirera <broker_name>`
data/bin/rirera ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rirera'
4
+ require 'yaml'
5
+
6
+ obj = RRR.new(ARGV[0])
7
+ conf = YAML.load_file(File.join(File.expand_path("..", File.dirname(__FILE__)),"conf/rirera.yml"))
8
+ broker = obj.get_broker(ARGV[0], conf) || usage
9
+
10
+ system "clear"
11
+ print "Volume: "
12
+ volume = $stdin.gets.chomp.to_f
13
+
14
+ while true do
15
+ print "Target price: "
16
+ target_price = $stdin.gets.chomp.gsub(",",".").to_f
17
+ print "Price: "
18
+ actual_price = $stdin.gets.chomp.gsub(",",".").to_f
19
+ print "Stop Loss: "
20
+ stop_loss = $stdin.gets.chomp.gsub(",",".").to_f
21
+
22
+ obj.test_input(actual_price, stop_loss)
23
+
24
+ chance = target_price - actual_price
25
+ risk = actual_price - stop_loss
26
+ rrr = (chance/risk).round(1)
27
+ amount = (volume/actual_price).round
28
+
29
+ total_commission = obj.get_total_commission(amount, actual_price, target_price, conf, broker)
30
+ max_gain = ((amount*target_price) - volume - total_commission).round(2)
31
+ loss = ((volume-(amount*stop_loss)) + total_commission).round(2)
32
+ break_even_price = obj.get_break_even(total_commission, volume, amount)
33
+
34
+ obj.print_rrr(rrr)
35
+
36
+ obj.print_result(volume, amount, max_gain, loss, total_commission, break_even_price)
37
+
38
+ exit if $stdin.gets.chomp == "n"
39
+ system "clear"
40
+ end
data/conf/rirera.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ broker:
3
+ consors:
4
+ name: Cortal Consors
5
+ basic_price: 4.95
6
+ commission_rate: 0.0025
7
+ min_rate: 9.95
8
+ max_rate: 69.00
data/lib/rirera.rb ADDED
@@ -0,0 +1,81 @@
1
+ # # # # # # #
2
+ # Class RRR #
3
+ # # # # # # #
4
+ require 'colorize'
5
+
6
+ class RRR
7
+ def initialize(broker)
8
+ @broker = broker
9
+ end
10
+
11
+ def usage
12
+ puts "Usage:"
13
+ puts "./rirera broker_name"
14
+ exit
15
+ end
16
+
17
+ def get_broker(broker, conf)
18
+ unless conf['broker'][@broker].nil?
19
+ @broker
20
+ else
21
+ abort "Not a valid broker"
22
+ end
23
+ end
24
+
25
+ def decorate
26
+ 12.times do
27
+ print "#"
28
+ end
29
+ end
30
+
31
+ def print_rrr(rrr)
32
+ decorate
33
+ print "\n# RRR: "
34
+ print "#{rrr}".yellow
35
+ puts " #"
36
+ decorate
37
+ end
38
+
39
+ def print_result(volume, amount, max_gain, loss, total_commission, break_even_price)
40
+ puts ""
41
+ puts ""
42
+ puts "Volume: #{volume}"
43
+ puts "Amount: #{amount}"
44
+ puts "Gain: #{max_gain}".green
45
+ puts "Loss: #{loss}".red
46
+ puts "Commission: #{total_commission}".magenta
47
+ puts "Break Even: #{break_even_price}".blue
48
+ puts ""
49
+ puts "Again? (y/n)"
50
+ end
51
+
52
+ def test_input(actual_price, stop_loss)
53
+ abort "Stop Loss has to be lower than Price" unless stop_loss < actual_price
54
+ end
55
+
56
+ def get_total_commission(amount, actual_price, target_price, conf, broker)
57
+ # calculate order pricing
58
+ basic_price = conf['broker'][broker]['basic_price']
59
+ commission_rate = conf['broker'][broker]['commission_rate']
60
+ volume_rate_buy = (amount * actual_price * commission_rate).round(2)
61
+ volume_rate_sell = (amount * target_price * commission_rate).round(2)
62
+ total_commission = 0.0
63
+
64
+ [volume_rate_buy, volume_rate_sell].each do |vr|
65
+ if (vr + basic_price) > conf['broker'][broker]['min_rate']
66
+ if (vr + basic_price) > conf['broker'][broker]['max_rate']
67
+ total_commission += conf['broker'][broker]['max_rate']
68
+ else
69
+ total_commission += (basic_price + vr)
70
+ end
71
+ else
72
+ total_commission += conf['broker'][broker]['min_rate']
73
+ end
74
+ end
75
+ total_commission.round(2)
76
+ end
77
+
78
+ def get_break_even(total_commission, volume, amount)
79
+ ((volume + total_commission) / amount).round(2)
80
+ end
81
+ end
data/rirera.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rirera'
3
+ s.version = '0.1.0'
4
+ s.date = Time.now.strftime('%Y-%m-%d')
5
+ s.summary = "Risk Reward Ratio"
6
+ s.description = "A simple Risk Reward Ratio calculator"
7
+ s.authors = ["Maximilian Meister"]
8
+ s.email = 'mmeister@suse.de'
9
+ s.rubyforge_project = 'rirera'
10
+ s.files = `git ls-files`.split("\n")
11
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ s.require_paths = ["lib"]
13
+ s.homepage ='http://github.com/MaximilianMeister/rirera'
14
+ s.license = 'MIT'
15
+ s.add_dependency('colorize',['~> 0.7.3', '>= 0.7.3'])
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rirera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maximilian Meister
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.3
33
+ description: A simple Risk Reward Ratio calculator
34
+ email: mmeister@suse.de
35
+ executables:
36
+ - rirera
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - Gemfile
42
+ - README.md
43
+ - bin/rirera
44
+ - conf/rirera.yml
45
+ - lib/rirera.rb
46
+ - rirera.gemspec
47
+ homepage: http://github.com/MaximilianMeister/rirera
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project: rirera
67
+ rubygems_version: 2.2.0
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Risk Reward Ratio
71
+ test_files: []