Coder Social home page Coder Social logo

greeks's Introduction

greeks

Calculate greeks for options trading (Implied Volatility, Delta, Gamma, Vega, Rho, and Theta)

Examples

What are the Greeks for Calls & Puts for AMD ($4.07 @ 35days)?

AMD stock = $4.07 Option Strike = $4.50 Option Expires = 35 days

Fed Rate = 0.01% Dividend Rate = 0%

Call Bid = $0.16 Put Bid = $0.59

# Calculate the Greeks for the Stock & Option Contract
calc = Math::Greeks::Calculator.new(
	:stock_price                   => 4.07,
	:stock_dividend_rate           => 0.00,
	:federal_reserve_interest_rate => 0.01,
	:option_expires_in_days        => 35.0,
	:option_strike                 => 4.50,
	:option_type                   => :call,
	:option_price                  => 0.16,
)

# What are the display values?
hash = calc.to_hash # Convert the values for display/consumption
hash[:iv]         # => 61.93 (Implied Volatility %)
hash[:delta]      # => -4.57 (Delta %/%)
hash[:gamma]      # => -2.84 (Gamma pp/pp)
hash[:vega]       # =>  0.49 (Vega %/pp)
hash[:rho]        # => -0.55 (Rho %/pp)
hash[:theta]      # => -0.68 (Theta %/day)
hash[:break_even] # => 45.66 (Chance of Breakeven)

# What are the raw values?
calc.break_even # What is the raw Break Even odds (0.000 to 1.000)
calc.iv         # What is the raw IV value (0.000 to 1.000)
calc.delta      # What is the raw Delta $/$?
calc.gamma      # What is the raw Gamma $/$?
calc.vega       # What is the raw Vega $/pp?
calc.rho        # What is the raw Rho $/pp?
calc.theta      # What is the raw Theta $/day?

greeks's People

Contributors

georgeu2000 avatar gnagel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

greeks's Issues

Not getting the greeks other than IV

Hi,

I am using Math::Greeks::Calculator.new(...) to calculate the greeks, as in your example, but I am not getting any greeks in the result object (delta, gamma, etc...), I am only getting IV.
Could you explain how to retrieve the rest of the greeks.

Thank you in advance,
Didier

Specs with Rantly

Specs seem to be working and the output is:

Finished in 0.2302 seconds
344 examples, 0 failures, 4 pending

I commented out the following in the spec helper.

require 'rantly/property'
require 'rantly/rspec_extensions'

Is Rantly being used?

I was able to run the specs under Ruby 2.1.0. Is that the latest that it runs under?

Readme has strange values

The values I get from the example in the Readme are different, with the exception of IV:

irb(main):003:0* calc = Math::Greeks::Calculator.new(
irb(main):004:1* :stock_price                   => 4.07,
irb(main):005:1* :stock_dividend_rate           => 0.00,
irb(main):006:1* :federal_reserve_interest_rate => 0.01,
irb(main):007:1* :option_expires_in_days        => 35.0,
irb(main):008:1* :option_strike                 => 4.50,
irb(main):009:1* :option_type                   => :call,
irb(main):010:1* :option_price                  => 0.16,
irb(main):011:1* )
=> #<Math::Greeks::Calculator:0x007fc7d28c33a8 @stock_price=4.07, @stock_dividend_rate=0.0, @option_type=:call, @option_price=0.16, @option_strike=4.5, @option_expires_in_days=35.0, @federal_reserve_interest_rate=0.01, @federal_reserve_interest_rate_f=0.0001, @stock_dividend_rate_f=0.0, @option_expires_pct_year=0.09863013698630137, @option_expires_pct_year_sqrt=0.3140543535541282, @option_volume=nil, @option_open_interest=nil, @price_vs_rate_vs_expires=4.07, @rate_vs_expires=1.0, @strike_vs_fed_vs_expires=4.499955616657234, @price_ratio_log_less_rates=-0.10042453430807177>
irb(main):014:0* hash = calc.to_hash # Convert the values for display/consumption
=> {:federal_reserve_interest_rate=>0.01, :stock_dividend_rate=>0.0, :stock_price=>4.07, :option_expires_in_days=>35.0, :option_type=>:call, :option_strike=>4.5, :option_price=>0.16, :option_volume=>nil, :option_open_interest=>nil, :premium_value=>0.0, :time_value=>0.16, :annualized_premium_value=>35.42, :annualized_time_value=>35.42, :iv=>61.92, :delta=>8.59, :gamma=>5.57, :vega=>1.81, :rho=>0.75, :theta=>-2.51, :delta_vs_theta=>-3.42, :break_even=>21.38}
irb(main):015:0> hash[:iv]         # => 61.93 (Implied Volatility %)
=> 61.92
irb(main):016:0> hash[:delta]      # => -4.57 (Delta %/%)
=> 8.59
irb(main):017:0> hash[:gamma]      # => -2.84 (Gamma pp/pp)
=> 5.57
irb(main):018:0> hash[:vega]       # =>  0.49 (Vega %/pp)
=> 1.81
irb(main):019:0> hash[:rho]        # => -0.55 (Rho %/pp)
=> 0.75
irb(main):020:0> hash[:theta]      # => -0.68 (Theta %/day)
=> -2.51
irb(main):021:0> hash[:break_even] # => 45.66 (Chance of Breakeven)
=> 21.38

Not sure if this is due to upgrading to Ruby 2.4.0. However, I get the same results on Ruby 2.2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.