stock_price_imitation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2dd73be18d3ae23f78d5327b396c9d7e28d18a02
4
+ data.tar.gz: e135ffb89f066a4517318e95babf04c273f1c8b9
5
+ SHA512:
6
+ metadata.gz: f064bacd89117334e14dd8bdbd46e675ba03d32951558cd578806b227ba63f75a296284dc745a0003b54968925182685c05e8ee87b9892cdbb47fe2dfea6770d
7
+ data.tar.gz: a60b70e65c427ea6c27691d9ba0ad6ee44c60ff8b0ae46e35761e181bb88b5dbe24baea879e42aa170b3984e7ec6c76a69f4ed6e4d2fb9375cb3e14bd9606c12
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stock_price_imitation.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Shinya131
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # StockPriceImitation
2
+
3
+ Stock price movement imitation generator. It is generate by random number.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'stock_price_imitation'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install stock_price_imitation
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ step = 100
25
+ first_step_price_range = 10..10000
26
+ volatility = 0.2
27
+
28
+ StockPriceImitation::Generator.new(step, first_step_price_range, volatility).execute
29
+ #=>
30
+ # [
31
+ # {opening_price: 5558, closing_price: 5191, low_price: 4483, high_price: 6725},
32
+ # {opening_price: 5404, closing_price: 7439, low_price: 5170, high_price: 7756},
33
+ # {opening_price: 5260, closing_price: 5581, low_price: 4463, high_price: 6695},
34
+ # {opening_price: 6840, closing_price: 6310, low_price: 4632, high_price: 6948},
35
+ # ....
36
+ # ]
37
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
data/bin/price-imi ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'stock_price_imitation'
5
+
6
+ step = ARGV.pop || 100
7
+ first_step_price_range = 10..10000
8
+ volatility = 0.2
9
+
10
+ prices = StockPriceImitation::Generator.new(step, first_step_price_range, volatility).execute
11
+
12
+ header = prices.first.keys.join("\t")
13
+ puts header
14
+
15
+ prices.each do |price|
16
+ puts price.values.join("\t")
17
+ end
@@ -0,0 +1,65 @@
1
+ class StockPriceImitation::Generator
2
+ def initialize(step_count, first_step_price_range=100..1000, volatility=0.1)
3
+ @step_count = step_count
4
+ @first_step_price_range = first_step_price_range
5
+ @volatility = volatility
6
+
7
+ @steps = []
8
+ end
9
+
10
+ def execute
11
+ generate_steps!
12
+ @steps.map{|s| to_hash(s) }
13
+ end
14
+
15
+ private
16
+
17
+ def generate_steps!
18
+ @step_count.times.each.with_index do |i|
19
+ seed_price = rand seed_price_range(i)
20
+ @steps << Step.new(seed_price, @volatility)
21
+ end
22
+ end
23
+
24
+ def seed_price_range(index)
25
+ case index
26
+ when 0
27
+ @first_step_price_range
28
+ else
29
+ previous_step = @steps[index - 1]
30
+ previous_step.low_price..previous_step.high_price
31
+ end
32
+ end
33
+
34
+ def to_hash(step)
35
+ {
36
+ opening_price: step.opening_price,
37
+ closing_price: step.closing_price,
38
+ low_price: step.low_price,
39
+ high_price: step.high_price,
40
+ }
41
+ end
42
+
43
+ class Step
44
+ def initialize(seed_price, volatility)
45
+ @low_price = (seed_price - (seed_price * volatility)).round
46
+ @high_price = (seed_price + (seed_price * volatility)).round
47
+ end
48
+
49
+ def low_price
50
+ @low_price
51
+ end
52
+
53
+ def high_price
54
+ @high_price
55
+ end
56
+
57
+ def opening_price
58
+ rand low_price..high_price
59
+ end
60
+
61
+ def closing_price
62
+ rand low_price..high_price
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module StockPriceImitation
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "stock_price_imitation/version"
2
+
3
+ module StockPriceImitation
4
+ require 'stock_price_imitation/generator'
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stock_price_imitation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stock_price_imitation"
8
+ spec.version = StockPriceImitation::VERSION
9
+ spec.authors = ["Shinya131"]
10
+ spec.email = ["nagai3mt5b@gmail.com"]
11
+ spec.summary = "Stock price movement imitation generator."
12
+ spec.description = "Stock price movement imitation generator. It is generate by random number."
13
+ spec.homepage = "https://github.com/Shinya131/stock_price_imitation"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'stock_price_imitation'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,70 @@
1
+ require 'minitest_helper'
2
+
3
+ describe StockPriceImitation::Generator do
4
+ describe '#initialize' do
5
+ it 'new instance' do
6
+ generator = StockPriceImitation::Generator
7
+ step_count = 10
8
+
9
+ assert generator.new(step_count).class == generator
10
+ end
11
+ end
12
+
13
+ describe '#execute' do
14
+ before do
15
+ @step_count = 100
16
+ @first_price_range = 100..10000
17
+ @volatility = 0.1
18
+
19
+ @generator = StockPriceImitation::Generator.new(@step_count, @first_price_range, @volatility)
20
+ @price_movement = @generator.execute
21
+ end
22
+
23
+ it 'is a Array' do
24
+ assert @price_movement.is_a? Array
25
+ end
26
+
27
+ it 'length is step_count' do
28
+ assert @price_movement.size == @step_count
29
+ end
30
+
31
+ it 'a step is a hash' do
32
+ @price_movement.each do |step|
33
+ assert step.is_a? Hash
34
+ end
35
+ end
36
+
37
+ it 'high price is bigger than low price' do
38
+ @price_movement.each do |step|
39
+ assert step[:high_price] >= step[:low_price]
40
+ end
41
+ end
42
+
43
+ it 'opening_price between low_price and high_price' do
44
+ @price_movement.each do |step|
45
+ expect_price_range = (step[:low_price]..step[:high_price])
46
+ assert expect_price_range.include? step[:opening_price]
47
+ end
48
+ end
49
+
50
+ it 'first step between first_price_range' do
51
+ first_step = @price_movement.first
52
+ assert @first_price_range.include? first_step[:low_price]
53
+ assert @first_price_range.include? first_step[:high_price]
54
+ end
55
+
56
+ it 'step between (previous * volatility)' do
57
+ @price_movement.each.with_index do |step, i|
58
+ next if i == 0
59
+
60
+ previous_low_price = @price_movement[i - 1][:low_price]
61
+ current_low_price = step[:low_price]
62
+
63
+ min = previous_low_price - (previous_low_price * @volatility)
64
+ max = previous_low_price + (previous_low_price * @volatility)
65
+
66
+ assert (min..max).include? current_low_price
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestStockPriceImitation < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::StockPriceImitation::VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stock_price_imitation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shinya131
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Stock price movement imitation generator. It is generate by random number.
56
+ email:
57
+ - nagai3mt5b@gmail.com
58
+ executables:
59
+ - price-imi
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/price-imi
70
+ - lib/stock_price_imitation.rb
71
+ - lib/stock_price_imitation/generator.rb
72
+ - lib/stock_price_imitation/version.rb
73
+ - stock_price_imitation.gemspec
74
+ - test/minitest_helper.rb
75
+ - test/test_generator.rb
76
+ - test/test_stock_price_imitation.rb
77
+ homepage: https://github.com/Shinya131/stock_price_imitation
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Stock price movement imitation generator.
101
+ test_files:
102
+ - test/minitest_helper.rb
103
+ - test/test_generator.rb
104
+ - test/test_stock_price_imitation.rb
105
+ has_rdoc: