jpx 0.1.0

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
+ SHA256:
3
+ metadata.gz: 6dd86a0579aee4d0daf6b2ce7e20f09f1b48c16794b7f66d3510388964e33875
4
+ data.tar.gz: 61c98e8f3e5889f7680bca62184dd08a3d651a249b2cfd59da8aed3d612fff30
5
+ SHA512:
6
+ metadata.gz: f5c6d597c799e6530f94fba2fb942bff269057bb943b7227756de779086c13dd26d01d1b45a631b29be97504efbc48ec10ca7e36bd749eed59fe23df0a44a149
7
+ data.tar.gz: e88a5b84c210f2ed2630ed496c50706683e407c0bb5a55ceb4a1ff095e61934b62fc227ceebcf79f95b2b0d84b16f48c9d1607dfb256cc25c90f73985718efb0
@@ -0,0 +1,43 @@
1
+ # https://circleci.com/docs/2.0/language-ruby/
2
+ version: 2
3
+ jobs:
4
+ build:
5
+ working_directory: ~/app
6
+ docker:
7
+ - image: circleci/ruby:2.6
8
+ environment:
9
+ TZ: Asia/Tokyo
10
+ steps:
11
+ - checkout
12
+
13
+ # Restore bundle cache
14
+ - restore_cache:
15
+ keys:
16
+ - jpx-bundle-{{ checksum "Gemfile.lock" }}
17
+ - run:
18
+ name: install bundler
19
+ command: gem install bundler:2.1.4
20
+
21
+ - run:
22
+ name: bundle install
23
+ command: bundle install --jobs=4 --retry=3 --path vendor/bundle
24
+
25
+ # Store bundle cache
26
+ - save_cache:
27
+ key: jpx-bundle-{{ checksum "Gemfile.lock" }}
28
+ paths:
29
+ - vendor/bundle
30
+
31
+ - run:
32
+ name: Run rspec
33
+ command: |
34
+ bundle exec rspec --format progress \
35
+ --format RspecJunitFormatter \
36
+ --out test_results/rspec.xml
37
+
38
+ # collect reports
39
+ - store_test_results:
40
+ path: test_results
41
+ - store_artifacts:
42
+ path: test_results
43
+ destination: test_results
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /.rspec_status
13
+ Gemfile.lock
14
+ .DS_Store
15
+
16
+ # Used by dotenv library to load environment variables.
17
+ # .env
18
+
19
+ # Ignore Byebug command history file.
20
+ .byebug_history
21
+
22
+ ## Specific to RubyMotion:
23
+ .dat*
24
+ .repl_history
25
+ build/
26
+ *.bridgesupport
27
+ build-iPhoneOS/
28
+ build-iPhoneSimulator/
29
+
30
+ ## Specific to RubyMotion (use of CocoaPods):
31
+ #
32
+ # We recommend against adding the Pods directory to your .gitignore. However
33
+ # you should judge for yourself, the pros and cons are mentioned at:
34
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35
+ #
36
+ # vendor/Pods/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalization:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ # .ruby-version
53
+ # .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+
58
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
59
+ # .rubocop-https?--*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jpx.gemspec
4
+ gemspec
5
+
6
+ gem "pry-byebug"
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rspec_junit_formatter"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Takehiko Shinkura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # jpx
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jpx"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jpx.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/jpx/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "jpx"
5
+ spec.version = Jpx::VERSION
6
+ spec.authors = ["Takehiko Shinkura"]
7
+ spec.email = ["tynmarket@gmail.com"]
8
+
9
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
10
+ spec.description = %q{Write a longer description or delete this line.}
11
+ spec.homepage = "https://github.com/tynmarket/jpx"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "trading_day_jp"
25
+ end
data/lib/jpx.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "jpx/version"
2
+ require "jpx/price"
3
+
4
+ module Jpx
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
data/lib/jpx/price.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "csv"
2
+ require "time"
3
+ require "trading_day_jp"
4
+
5
+ module Jpx
6
+ module Price
7
+ SESSION_ID_DAY = "999"
8
+ SESSION_DAY = 0
9
+ SESSION_NIGHT = 1
10
+
11
+ class << self
12
+ def parse(path)
13
+ data = CSV.read(path)[1..-1].map do |row|
14
+ next if row.empty?
15
+
16
+ # 取引日, _, 識別コード, セッション区分, 時刻, 始値, 高値, 安値, 終値, 出来高, VWAP, 約定回数, _, 限月(i = 13)
17
+ datetime = Time.parse(row[0] + row[4])
18
+ session = to_session(row[3])
19
+
20
+ # 期近のみ取得
21
+ next unless near_term?(datetime, row[13])
22
+
23
+ # 大引けの場合15:15になるので、15:10として扱う
24
+ datetime -= 60 * 5 if row[4] == "1515"
25
+
26
+ if session == SESSION_NIGHT
27
+ prev_date = TradingDayJp.prev(datetime.to_date)
28
+ prev_datetime = Time.new(prev_date.year, prev_date.month, prev_date.day, datetime.hour, datetime.min)
29
+
30
+ # ナイトセッションの場合、実際に取引が行われた日時に変換する
31
+ datetime =
32
+ if datetime.hour >= 16
33
+ prev_datetime
34
+ else
35
+ prev_datetime + 60 * 60 * 24
36
+ end
37
+ end
38
+
39
+ {
40
+ datetime: datetime,
41
+ session: session,
42
+ open: row[5].to_i,
43
+ high: row[6].to_i,
44
+ low: row[7].to_i,
45
+ close: row[8].to_i,
46
+ volume: row[9].to_i,
47
+ }
48
+ end
49
+
50
+ data.compact
51
+ end
52
+
53
+ def to_session(session)
54
+ session == SESSION_ID_DAY ? SESSION_DAY : SESSION_NIGHT
55
+ end
56
+
57
+ def near_term?(time, contract_month)
58
+ date = time.to_date
59
+ @sq_dates ||= sq_dates
60
+ sq_date = @sq_dates.find { |sq_date| sq_date > date }
61
+ near_contract_month = sprintf("%d%02d", sq_date.year, sq_date.month)
62
+
63
+ contract_month == near_contract_month
64
+ end
65
+
66
+ # MSQ祝日は今のところない
67
+ def sq_dates
68
+ from = Date.new(2006, 1, 1)
69
+ to = Date.today + 120
70
+
71
+ (from.year..to.year).map do |year|
72
+ [3, 6, 9, 12].map do |month|
73
+ start = Date.new(year, month, 1)
74
+ dates = (start..(start + 14))
75
+ first_firday = dates.find { |date| date.wday == 5 }
76
+ second_friday = dates.find { |date| date > first_firday && date.wday == 5 }
77
+
78
+ second_friday
79
+ end
80
+ end.flatten
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Jpx
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jpx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takehiko Shinkura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trading_day_jp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Write a longer description or delete this line.
28
+ email:
29
+ - tynmarket@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".circleci/config.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - jpx.gemspec
44
+ - lib/jpx.rb
45
+ - lib/jpx/price.rb
46
+ - lib/jpx/version.rb
47
+ homepage: https://github.com/tynmarket/jpx
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: 2.3.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.0.6
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Write a short summary, because RubyGems requires one.
70
+ test_files: []