Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get examples to work #8

Open
derekyau opened this issue Apr 22, 2012 · 12 comments
Open

can't get examples to work #8

derekyau opened this issue Apr 22, 2012 · 12 comments

Comments

@derekyau
Copy link

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
Copy link
Collaborator

wkranec commented Apr 23, 2012

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
Copy link
Author

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
Copy link
Author

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

@derekyau derekyau reopened this Apr 23, 2012
@wkranec
Copy link
Collaborator

wkranec commented Apr 25, 2012

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
Copy link
Author

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
Copy link

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
Copy link

+1

@wQwRtaufxJw7UFLCXzXz
Copy link

I get

#Class:0x000000063a0ba0 can't be coerced into BigDecimal

@suan
Copy link

suan commented Feb 5, 2014

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
Copy link

suan commented Feb 6, 2014

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
Copy link
Owner

@derekyau @MoustafaEid @wmilesn @suan

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants