FinanceEngine
Finance Engine (Fe) is a hopefully growing open source library to assist in financial calculations and demonstrations.
Installation
Add this line to your application's Gemfile:
gem 'finance_engine'
And then execute:
$ bundle
Or install it yourself as:
$ gem install finance_engine
Usage
At the moment there are only five limited modules. Here we will try to demonstrate the basic argument inputs, it is advisable to check the tests for further details.
-
FA = FinanceEngine::Annuity
FA.present_value_perpetuity(annuity payment in dollars, rate of return, growth rate) - Will return the present value of a perpetuity.
FA.present_value_annuity(annuity payment in dollars, rate of return, n periods in payment, growth rate) - Will return the present value of an annuity with n periods remaining.
-
FEE = FinanceEngine::EAY_EAR
FEE.calculate_effective_annual_yield(annual interest rate, compounding periods) - returns the effective annual yield given the effective annual rate and compounding periods.
FEE.calculate_effective_annual_rate(effective annual yield, compounding periods) - returns the annual rate of return given the effective annual yeld and compounding periods.
FEE.calculate_EAY_payment(payment amount, effecive annual rate, periods compounded, periods per year) - Calculates the dollar value of a payment in the future with compounding.
FEE.calculate_EAR_payment(payment amount, effecive annual rate, periods compounded, periods per year) - Calculates the dollar value of a payment in the future without compounding.
FEE.compare_EAR_EAY(payment amount, effecive annual rate, periods compounded, periods per year) - Calculates the dollar value difference between a payment calculated with effective yield and without.
-
FE = FinanceEngine::Equity
FE.gordon_growth_model({ :rate => 0.05, :dividend => 100, :growth => 0.02, :value => 3333.33 }) - Using 3 of the 4 input values the Gordon Growth Model method will calculate the 4th input.
FE.gordon_growth_model({ :rate => 0.05, :dividend => 100, :growth => 0.02 }) - Will return a value of 3333.33.
-
FBS = FinanceEngine::Black_Scholes
FBS.new({ :current_stock_price => 100, :time => 5, :strike_price => 95, :risk_free_rate => 0.05, :volatility => 0.25 }) - After initializing a new instance of Black_Scholes run the build options method. This will create and store the put call and price data on the instance of Black Scholes. This is different from the other modules in that it will store the variables in the instance.
-
FTVM = FinanceEngine::Time_Value_Money
FTVM.present_value_cash_flows(years, cashflows, rates) - Years, cashflows and rates are all arrays matching in length. This method will return the present value of a series of cash flows when given the time, amount and effective interest rates.
FTVM.future_value_cash_flows(years, cashflows, rates) - Years, cashflows and rates are all arrays matching in length. This method will return the future value of a series of cash flows when given the time, amount and effective interest rates.
-
AO = FinanceEngine::American_Options
AO.new(Price, Volatility, Risk Free Rate, Strike Price) - Initializes a new instance of the american options storing the price, volatility, rf rate and strike price. AO.build_american_options(years to expiration, number of periods within that year to exercise options) - this method will build out a binary tree to calculate the current option prices based on the future stock value and strike price. AO.current_call_price - returns the calculated current call price. AO.current_put_price - returns the calculated current put price.
Contributing
- Fork it ( https://github.com/penkar/finance_engine/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
What would be useful? Methods in Time value of money to calculate the rate, and nper.