Class: SchwabRb::DataObjects::OptionChain
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::OptionChain
- Defined in:
- lib/schwab_rb/data_objects/option_chain.rb
Instance Attribute Summary collapse
-
#asset_main_type ⇒ Object
readonly
Returns the value of attribute asset_main_type.
-
#asset_sub_type ⇒ Object
readonly
Returns the value of attribute asset_sub_type.
-
#call_dates ⇒ Object
readonly
Returns the value of attribute call_dates.
-
#call_opts ⇒ Object
readonly
Returns the value of attribute call_opts.
-
#days_to_expiration ⇒ Object
readonly
Returns the value of attribute days_to_expiration.
-
#interest_rate ⇒ Object
readonly
Returns the value of attribute interest_rate.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#is_chain_truncated ⇒ Object
readonly
Returns the value of attribute is_chain_truncated.
-
#is_delayed ⇒ Object
readonly
Returns the value of attribute is_delayed.
-
#is_index ⇒ Object
readonly
Returns the value of attribute is_index.
-
#put_dates ⇒ Object
readonly
Returns the value of attribute put_dates.
-
#put_opts ⇒ Object
readonly
Returns the value of attribute put_opts.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#underlying_price ⇒ Object
readonly
Returns the value of attribute underlying_price.
-
#volatility ⇒ Object
readonly
Returns the value of attribute volatility.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(symbol:, status:, strategy:, interval:, is_delayed:, is_index:, interest_rate:, underlying_price:, volatility:, days_to_expiration:, asset_main_type:, asset_sub_type:, is_chain_truncated:, call_dates: [], call_opts: [], put_dates: [], put_opts: []) ⇒ OptionChain
constructor
A new instance of OptionChain.
- #to_a(_date = nil) ⇒ Object
Constructor Details
#initialize(symbol:, status:, strategy:, interval:, is_delayed:, is_index:, interest_rate:, underlying_price:, volatility:, days_to_expiration:, asset_main_type:, asset_sub_type:, is_chain_truncated:, call_dates: [], call_opts: [], put_dates: [], put_opts: []) ⇒ OptionChain
Returns a new instance of OptionChain.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 59 def initialize( symbol:, status:, strategy:, interval:, is_delayed:, is_index:, interest_rate:, underlying_price:, volatility:, days_to_expiration:, asset_main_type:, asset_sub_type:, is_chain_truncated:, call_dates: [], call_opts: [], put_dates: [], put_opts: [] ) @symbol = symbol @status = status @strategy = strategy @interval = interval @is_delayed = is_delayed @is_index = is_index @interest_rate = interest_rate @underlying_price = @volatility = volatility @days_to_expiration = days_to_expiration @asset_main_type = asset_main_type @asset_sub_type = asset_sub_type @is_chain_truncated = is_chain_truncated @call_dates = call_dates @call_opts = call_opts @put_dates = put_dates @put_opts = put_opts end |
Instance Attribute Details
#asset_main_type ⇒ Object (readonly)
Returns the value of attribute asset_main_type.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def asset_main_type @asset_main_type end |
#asset_sub_type ⇒ Object (readonly)
Returns the value of attribute asset_sub_type.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def asset_sub_type @asset_sub_type end |
#call_dates ⇒ Object (readonly)
Returns the value of attribute call_dates.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def call_dates @call_dates end |
#call_opts ⇒ Object (readonly)
Returns the value of attribute call_opts.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def call_opts @call_opts end |
#days_to_expiration ⇒ Object (readonly)
Returns the value of attribute days_to_expiration.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def days_to_expiration @days_to_expiration end |
#interest_rate ⇒ Object (readonly)
Returns the value of attribute interest_rate.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def interest_rate @interest_rate end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def interval @interval end |
#is_chain_truncated ⇒ Object (readonly)
Returns the value of attribute is_chain_truncated.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def is_chain_truncated @is_chain_truncated end |
#is_delayed ⇒ Object (readonly)
Returns the value of attribute is_delayed.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def is_delayed @is_delayed end |
#is_index ⇒ Object (readonly)
Returns the value of attribute is_index.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def is_index @is_index end |
#put_dates ⇒ Object (readonly)
Returns the value of attribute put_dates.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def put_dates @put_dates end |
#put_opts ⇒ Object (readonly)
Returns the value of attribute put_opts.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def put_opts @put_opts end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def status @status end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def strategy @strategy end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def symbol @symbol end |
#underlying_price ⇒ Object (readonly)
Returns the value of attribute underlying_price.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def @underlying_price end |
#volatility ⇒ Object (readonly)
Returns the value of attribute volatility.
81 82 83 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 81 def volatility @volatility end |
Class Method Details
.build(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 11 def build(data) = data.fetch(:symbol) call_dates = [] call_opts = [] data.fetch(:callExpDateMap).each do |exp_date, | call_dates << Date.strptime(exp_date.to_s.split(":").first, "%Y-%m-%d") .each_value do |opts| opts.each do |option_data| call_opts << Option.build(, option_data) end end end put_dates = [] put_opts = [] data.fetch(:putExpDateMap).each do |exp_date, | put_dates << Date.strptime(exp_date.to_s.split(":").first, "%Y-%m-%d") .each_value do |opts| opts.each do |option_data| put_opts << Option.build(, option_data) end end end new( symbol: data.fetch(:symbol), status: data.fetch(:status), strategy: data.fetch(:strategy), interval: data.fetch(:interval, nil), is_delayed: data.fetch(:isDelayed, nil), is_index: data.fetch(:isIndex, nil), interest_rate: data.fetch(:interestRate, nil), underlying_price: data.fetch(:underlyingPrice), volatility: data.fetch(:volatility, nil), days_to_expiration: data.fetch(:daysToExpiration), asset_main_type: data.fetch(:assetMainType, nil), asset_sub_type: data.fetch(:assetSubType, nil), is_chain_truncated: data.fetch(:isChainTruncated, false), call_dates: call_dates, call_opts: call_opts, put_dates: put_dates, put_opts: put_opts ) end |
Instance Method Details
#to_a(_date = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/schwab_rb/data_objects/option_chain.rb', line 84 def to_a(_date = nil) call_opts.map do |copt| [copt.expiration_date.strftime("%Y-%m-%d"), copt.put_call, copt.strike, copt.delta, copt.bid, copt.ask, copt.mark] end + put_opts.map do |popt| [popt.expiration_date.strftime("%Y-%m-%d"), popt.put_call, popt.strike, popt.delta, popt.bid, popt.ask, popt.mark] end end |