marksweston / finance

A library for financial calculations in Ruby
https://rubygems.org/gems/finance
Other
217 stars 93 forks source link

can't get examples to work #8

Open derekyau opened 12 years ago

derekyau commented 12 years ago

sorry, i may be missing something here (probably am :/) but I just installed the gem (which is awesome by the way thanks for starting this!)

I wasn't able to get the examples working, this is within the context of a rails stack.

when I try the IRR example [-4000,1200,1410,1875,1050].irr I seem to be getting the error Flt::DecNum can't be coerced into BigDecimal This seems to be working fine in the rails console though.

as for the xirr example

@transactions = [] @transactions << Transaction.new(-1000, :date => Time.new(1985,01,01)) @transactions << Transaction.new( 600, :date => Time.new(1990,01,01)) @transactions << Transaction.new( 600, :date => Time.new(1995,01,01)) @transactions.xirr(0.6)

I am getting this error wrong argument type Float (expected Fixnum)

not quite sure what I am doing wrong, anyone have an idea?

Thanks!

wkranec commented 12 years ago

Hi Derek,

Thanks for letting me know about this. It's always nice to hear from people that are using the gem!

First, I just want to confirm a few things: what version of ruby, rails, and the finance gem are you using? Right now, I am working with ruby 1.9.3-p0, no rails, and finance-1.1.1.gem. The examples you mentioned are currently in the unit tests, which pass on my machine. So I just want to make sure that we are starting from the same place.

Thanks, Bill

derekyau commented 12 years ago

hey bill,

I was overjoyed when I found a finance gem :P - I am envious of those python guys and their scipy numpy libs, this is a great start :).

The ticket above refers to rails version 3.0.9 and ruby 1.9.2p180 and p290

derekyau commented 12 years ago

in particular the code seems to have problems with this line in cashflows.rb

n = t.amount / ( (1 + rate) ** ((t.date-start) / 31536000.to_d)) # 365 * 86400

wkranec commented 12 years ago

Hi Derek,

I have verified the error (on the line you specified) on a fresh install of Ruby 1.9.2p180 with rails 3.2.3.

That said, I'm not sure why this is happening. Adding require 'rails' in the unit tests doesn't cause any failures, so I need to find a way to test the code inside the rails environment. I don't use rails very often, so I'll need to do some searching to find the best way to do this - here's what I found so far.

I should have more time to go through this during the weekend.

Thanks, Bill

derekyau commented 12 years ago

Thanks Bill! Very much appreciated. I've tried tinkering around with it for a few hours yesterday, I think it might have something to do with the fact that rails changes the Time class injecting its own methods in. I'm not 100% certain though, in the end I couldn't get it going :/. Thanks for your help on this :)

MoustafaEid commented 12 years ago

I can also confirm this bug happening while using ruby 1.9.3p194, Rails 3.2.5 and finance 1.1.2 The examples work fine while running as a standalone ruby file or in irb, but it doesn't work in rails console or in rails app, here is the error: Math::DomainError: Zero or negative argument for log thrown from cashflows.rb:118 This bug is also related to #7

willnathan commented 11 years ago

+1

wQwRtaufxJw7UFLCXzXz commented 11 years ago

I get

Class:0x000000063a0ba0 can't be coerced into BigDecimal

suan commented 10 years ago

So, interestingly, I see this problem as well, but using the 'flt' directly (rather than through the 'finance' gem) and only on Linux for some reason (on OSX it's fine)

Specifically, these values are an example of what triggers it:

DecNum('15.47928602931972642303350358') * BigDecimal('500.00000000000000000000')

And just like @MoustafaEid, I can't reproduce from within a Rails console

suan commented 10 years ago

So, for me at least it seems like a Ruby build version problem. Upgraded from 1.9.3-p125 to 1.9.3-p194 and it went away. Worth giving a shot.

marksweston commented 8 years ago

@derekyau @MoustafaEid @wmilesn @suan

This issue is now quite old :) Is it still a live problem for anyone, and does it require further investigation?

willnathan commented 8 years ago

Not on my end

On Wed, Nov 25, 2015 at 6:28 AM, Mark Weston notifications@github.com wrote:

@derekyau https://github.com/derekyau @MoustafaEid https://github.com/MoustafaEid @wmilesn https://github.com/wmilesn @suan https://github.com/suan

This issue is now quite old :) Is it still a live problem for anyone, and does it require further investigation?

— Reply to this email directly or view it on GitHub https://github.com/bcsgsvn/finance/issues/8#issuecomment-159577834.

Will Nathan http://www.linkedin.com/pub/will-nathan/1/285/16 Co-founder & Chairman, Homepolish https://www.homepolish.com/ Forbes http://www.forbes.com/sites/alextaub/2015/07/02/homepolish-is-here-to-help-you-design-your-home-or-office/ | Fox Business http://video.foxbusiness.com/v/3884693828001/interior-design-without-the-hefty-price-tag/?cmpid=fbvid_twitter#sp=show-clips | Nylon Guys http://bt.e-ditionsbyfry.com/article/space+cases/1828012/0/article.html

https://www.facebook.com/Homepolish http://www.pinterest.com/Homepolish/ http://instagram.com/homepolish https://twitter.com/Homepolish