iron_warbler 2.0.7.36 → 2.0.7.38

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e02502f06973a985d527d3680e497c074e092c5fe65ec30b0bf83343b3678234
4
- data.tar.gz: d0007bb285275c621e4d07ce2628a3aa7ecc5d1965bdc532c9a27ea2efbaabb0
3
+ metadata.gz: c3d26b42528adce8dcac715a0dc3296c6a7dfe8aa69deae868baa38f207d9140
4
+ data.tar.gz: c947418c85ee93024ff05d64207ae159b852db6746b3104d5b14174d83dfd575
5
5
  SHA512:
6
- metadata.gz: a2f370d2954d01f2aea2cefd07d87b8d298fca8216d2f4b4f7ceb1de6de03d4af453ed0c0eb3fe10451360f9691f76e25a152e12a1314de2b77064b40ad5e4e3
7
- data.tar.gz: e00471b9403ad26c509d4eb6e761f6967e121892269514b89aa147e81ab1c9dbdc46661cd28b1b5108e001cba7db602bcda7b168dca8d47a3d0efc9242d92f73
6
+ metadata.gz: b5b4e030572f6781add522f5fb1b8bebdfdeffdc871153b8b408882f998de6be0069544eecfa58e14b4e8357877fd5a84ab2d153ffa8a463bda86fdab2783633
7
+ data.tar.gz: 707028e50d3b1aa4a5522765226ea09b5e5e81e397c1b1541432d46231355ab462569295d5375db958d8c41e6bf475340b073591a18b5a547a5488b0db1039b5
@@ -1,5 +1,9 @@
1
1
 
2
2
  //= require ./gameui
3
+ //= require ./stock
3
4
 
4
5
  // console.log('Loaded iron_warbler/application.js')
5
6
 
7
+ const appRouter = {
8
+ showStockPath: (symbol) => `/trading/stocks/${symbol}`,
9
+ }
@@ -0,0 +1,9 @@
1
+
2
+ $(document).ready(() => {
3
+
4
+ $('select[name="stock_selector"]').on('change', (ev) => {
5
+ // logg(ev, 'ev')
6
+ window.location = appRouter.showStockPath(ev.target.value)
7
+ })
8
+
9
+ })
@@ -1,4 +1,7 @@
1
1
 
2
+ ##
3
+ ## https://www.macrotrends.net/stocks/charts/META/meta-platforms/stock-price-history
4
+ ##
2
5
  class Iro::StocksController < Iro::ApplicationController
3
6
  before_action :set_stock, only: [:show, :edit, :update, :destroy]
4
7
 
@@ -57,6 +60,9 @@ class Iro::StocksController < Iro::ApplicationController
57
60
  @priceitems = ::Iro::Priceitem.where({
58
61
  ticker: @stock.ticker,
59
62
  })
63
+ @datapoints = Iro::Datapoint.where({
64
+ symbol: @stock.ticker,
65
+ }).order_by({ date: :desc }).limit(100)
60
66
 
61
67
  respond_to do |format|
62
68
  format.html
@@ -84,7 +90,12 @@ class Iro::StocksController < Iro::ApplicationController
84
90
  private
85
91
 
86
92
  def set_stock
87
- @stock = Iro::Stock.find(params[:id])
93
+ begin
94
+ @stock = Iro::Stock.find(params[:id])
95
+ rescue Mongoid::Errors::DocumentNotFound => e
96
+ @stock = Iro::Stock.find_by ticker: params[:id]
97
+ end
98
+ @stocks_list = Iro::Stock.tickers_list
88
99
  end
89
100
 
90
101
  def stock_params
@@ -1,5 +1,8 @@
1
1
 
2
-
2
+ ##
3
+ ## Datapoints are at most daily!
4
+ ## See Priceitem for intra-day data
5
+ ##
3
6
  class Iro::Datapoint
4
7
  include Mongoid::Document
5
8
  include Mongoid::Timestamps
@@ -31,25 +34,23 @@ class Iro::Datapoint
31
34
  SYMBOL_T20YR = 'T20YR'
32
35
  SYMBOL_T30YR = 'T30YR'
33
36
 
34
- field :date, type: Date ## @obsolete, use quote_at
37
+ field :date, type: Date
35
38
  index({ kind: -1, date: -1 })
39
+ validates :date, uniqueness: { scope: [ :symbol ] }
36
40
 
37
41
  field :quote_at, type: DateTime
38
42
  index({ kind: -1, quote_at: -1 })
39
- validates :quote_at, uniqueness: { scope: [ :kind, :symbol ] }
43
+ validates :quote_at, uniqueness: { scope: [ :kind, :symbol ] } ## scope-by-kind is unnecessary here? _vp_ 2024-08-08
40
44
 
41
45
  field :open, type: Float
42
46
  field :high, type: Float
43
47
  field :low, type: Float
48
+ def close; value; end
49
+ def close= a; value= a; end
44
50
 
45
51
  field :value, type: Float
46
52
  validates :value, presence: true
47
- def close
48
- value
49
- end
50
- def close= a
51
- value= a
52
- end
53
+
53
54
 
54
55
  field :volume, type: Integer
55
56
 
@@ -156,7 +157,7 @@ class Iro::Datapoint
156
157
  csv = CSV.read(path, headers: true)
157
158
  csv.each do |row|
158
159
  flag = create({
159
- kind: KIND_STOCK,
160
+ kind: KIND_STOCK,
160
161
  symbol: symbol,
161
162
  date: row['Date'],
162
163
  quote_at: row['Date'],
@@ -168,7 +169,11 @@ class Iro::Datapoint
168
169
  low: row['Low'],
169
170
  value: row['Close'],
170
171
  })
171
- print '.' if flag.persisted?
172
+ if flag.persisted?
173
+ print '^'
174
+ else
175
+ puts flag.errors.messages
176
+ end
172
177
  end
173
178
  puts 'ok'
174
179
  end
@@ -1,6 +1,7 @@
1
1
 
2
2
  ##
3
- ## specifically Option or Stock priceitem?
3
+ ## Specifically Option or Stock priceitem?
4
+ ## Priceitems are intra-day! See Datapoint for daily data
4
5
  ##
5
6
  class Iro::Priceitem
6
7
  include Mongoid::Document
@@ -8,7 +9,7 @@ class Iro::Priceitem
8
9
  store_in collection: 'iro_price_items'
9
10
 
10
11
  ## PUT, CALL, STOCK
11
- field :putCall, type: String
12
+ field :putCall, type: String ## kind
12
13
  field :symbol, type: String
13
14
  field :ticker, type: String
14
15
  # belongs_to :stock, inverse_of: :priceitems
@@ -24,6 +25,7 @@ class Iro::Priceitem
24
25
  field :highPrice, type: Float
25
26
  field :closePrice, type: Float
26
27
 
28
+ field :quote_at, type: DateTime
27
29
  field :quoteTimeInLong, type: Integer
28
30
  field :timestamp, type: Integer
29
31
  field :totalVolume, type: Integer
@@ -1,6 +1,9 @@
1
1
  include Math
2
2
  require 'business_time'
3
3
 
4
+ ##
5
+ ## https://www.macrotrends.net/stocks/charts/META/meta-platforms/stock-price-history
6
+ ##
4
7
  class Iro::Stock
5
8
  include Mongoid::Document
6
9
  include Mongoid::Timestamps
@@ -18,6 +21,8 @@ class Iro::Stock
18
21
  field :ticker
19
22
  validates :ticker, uniqueness: true, presence: true
20
23
  index({ ticker: -1 }, { unique: true })
24
+ def symbol; ticker; end
25
+ def symbol= a; ticker = a; end
21
26
 
22
27
  field :last, type: :float
23
28
  field :options_price_increment, type: :float
@@ -30,6 +35,8 @@ class Iro::Stock
30
35
  has_many :options, class_name: 'Iro::Option', inverse_of: :stock
31
36
  has_many :priceitems, inverse_of: :stock
32
37
 
38
+ default_scope { order_by({ ticker: :asc }) }
39
+
33
40
  ## my_find
34
41
  def self.f ticker
35
42
  self.find_by ticker: ticker
@@ -55,7 +62,14 @@ class Iro::Stock
55
62
  stock.volatility_from_yr
56
63
 
57
64
  =end
58
- def volatility duration:
65
+ field :volatility, type: :float
66
+ def volatility duration: 1.year, recompute: false
67
+ if self[:volatility]
68
+ if !recompute
69
+ return self[:volatility]
70
+ end
71
+ end
72
+
59
73
  stock = self
60
74
  begin_on = Time.now - duration - 1.day
61
75
  points = Iro::Datapoint.where( kind: 'STOCK', symbol: stock.ticker,
@@ -86,6 +100,7 @@ class Iro::Stock
86
100
  adjustment = 2.0
87
101
  out = out * adjustment
88
102
  puts! out, 'volatility (adjusted)'
103
+ self.update volatility: out
89
104
  return out
90
105
  end
91
106
 
@@ -9,17 +9,20 @@
9
9
  %td Ticker
10
10
  %td last price
11
11
  %td n priceitems
12
+ %td volatility
12
13
  %tbody
13
14
  - @stocks.each do |stock|
14
15
  %tr
15
16
  %td
16
17
  = link_to '[~]', edit_stock_path(stock)
17
18
  = link_to '[api]', stock_path(stock, format: :json)
18
- <b>#{stock.ticker}</b>
19
+ <b>#{link_to stock.ticker, stock_path(stock)}</b>
19
20
  %td
20
21
  #{pp_amount stock.last}
21
22
  %td
22
23
  = stock.priceitems.length
24
+ %td
25
+ = stock.volatility rescue nil
23
26
 
24
27
  %hr
25
28
  = render 'iro/stocks/form', stock: Iro::Stock.new
@@ -1,5 +1,27 @@
1
1
 
2
2
  .stocks-show.maxwidth
3
- %h4= @stock
3
+ .header
4
+ %h3.title
5
+ = select_tag :stock_selector, options_for_select( @stocks_list, selected: @stock.ticker ), class: 'select2'
4
6
 
5
- %h5 Max Pain
7
+ .row
8
+ .col-md-3
9
+ %h4 Datapoints
10
+ %table.bordered
11
+ %thead
12
+ %td Date
13
+ %td Value
14
+ %tbody
15
+ - @datapoints.each do |pt|
16
+ %tr
17
+ %td= pt.date
18
+ %td= pt.value
19
+
20
+
21
+ .col-md-9
22
+ %ul
23
+ %li
24
+ %b 1 yr volatility <br />
25
+ = @stock.volatility
26
+
27
+ %h4 Max Pain
@@ -32,6 +32,27 @@ namespace :iro do
32
32
  print '^'
33
33
  end
34
34
 
35
+ desc 'get treasuries'
36
+ task :get_treasuries => :environment do
37
+ ::Iro::Iro.get_treasuries
38
+ print '^'
39
+ end
40
+
41
+ ## Expected headers: Date, Open, High, Low, Close
42
+ desc 'import_stock stock=<stock> path=<path>'
43
+ task :import_stock => :environment do
44
+ # puts! ARGV, 'ARGV'
45
+ # puts! ENV, 'ENV'
46
+ if ARGV.length != 3
47
+ puts! ''
48
+ puts! "Usage: import_stock <stock> <path>"
49
+ puts! 'Expected headers: Date, Open, High, Low, Close'
50
+ puts! ''
51
+ exit 0
52
+ end
53
+ Iro::Datapoint.import_stock symbol: ENV['stock'], path: ENV['path']
54
+ end
55
+
35
56
  desc 'import historic treasuries'
36
57
  task :import_1990_2023_treasuries => :environment do
37
58
  ::Iro::Iro.import_1990_2023_treasuries
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_warbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7.36
4
+ version: 2.0.7.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pudeyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: business_time
@@ -217,6 +217,7 @@ files:
217
217
  - app/assets/config/iron_warbler_manifest.js
218
218
  - app/assets/javascript/iron_warbler/application.js
219
219
  - app/assets/javascript/iron_warbler/gameui.js
220
+ - app/assets/javascript/iron_warbler/stock.js
220
221
  - app/assets/stylesheets/iron_warbler/Card.scss
221
222
  - app/assets/stylesheets/iron_warbler/alerts.scss
222
223
  - app/assets/stylesheets/iron_warbler/application.css