timevalue 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/lib/timevalue.rb +46 -0
 - metadata +45 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 346d890bb91004fb4dcfa42ec89c730579c0318e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 80b1781803404e90ec83b11c911b0b50c9afa42a
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7cc08da36ba7515936822d9b82820f02fbbbcc3c284c05c2e1d19cded426514a8e53fd97e849d4c9ad5465dd0492706a1e149e33c69cf9b51c0ecbe1fc2a48a8
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 9a80fd090fd2f33a75eb90acd5627f72342d2085cc5dd6d5705909be504ba5cc2c72961bea0610476f66381fdb51f60bd0a42bc9571afd10933d9f3f515823f5
         
     | 
    
        data/lib/timevalue.rb
    ADDED
    
    | 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class TimeValue
         
     | 
| 
      
 2 
     | 
    
         
            +
                
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :n, :i, :pv, :pmt, :fv
         
     | 
| 
      
 4 
     | 
    
         
            +
                
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(n = 0, i = 0, pv = 0.0, pmt = 0.0, fv = 0.0)
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @n = n
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @i = i.to_f
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @pv = pv.to_f
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @pmt = pmt.to_f
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @fv = fv.to_f
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
      
 13 
     | 
    
         
            +
              #Base formula, ordinary annuity: -PV = [FV/((1+i)^n)] + (PMT/i)*[1-(1/(1+i)^n)]
         
     | 
| 
      
 14 
     | 
    
         
            +
                def calc_pv()
         
     | 
| 
      
 15 
     | 
    
         
            +
                    i = @i / 100.0
         
     | 
| 
      
 16 
     | 
    
         
            +
                    #Initial contribution
         
     | 
| 
      
 17 
     | 
    
         
            +
                    pvf = @fv / ((1 + i) ** @n)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    #Present value of annuity
         
     | 
| 
      
 19 
     | 
    
         
            +
                    pva = (@pmt/i) * (1-(1/((1+i)**@n)))
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @pv = (pvf + pva) * (-1)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    #Round
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @pv = (@pv*100).round / 100.0
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                def calc_fv()
         
     | 
| 
      
 26 
     | 
    
         
            +
                    i = @i / 100.0
         
     | 
| 
      
 27 
     | 
    
         
            +
                    #Growth of initial contribution
         
     | 
| 
      
 28 
     | 
    
         
            +
                    fvp = @pv * ((1 + i) ** @n)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    #Growth of payments
         
     | 
| 
      
 30 
     | 
    
         
            +
                    fva = @pmt * (((1 + i) ** @n)-1) / i
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @fv = (fvp + fva) * (-1)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    #Round
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @fv = (@fv*100).round / 100.0
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
                
         
     | 
| 
      
 36 
     | 
    
         
            +
                def calc_n()
         
     | 
| 
      
 37 
     | 
    
         
            +
                    i = @i / 100.0
         
     | 
| 
      
 38 
     | 
    
         
            +
                    @n = (Math.log((@pmt - (i * @fv))/(@pmt + (i * @pv)))/Math.log(1 + i)).round(0)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def calc_pmt()
         
     | 
| 
      
 42 
     | 
    
         
            +
                    i = @i / 100.0
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @pmt = (-i*(@fv+(@pv*((1+i)**n))))/(((1+i)**n)-1)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    @pmt = (@pmt*100).round / 100.0
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: timevalue
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Randall Reed, Jr.
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-06-13 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Perform time value of money calculations using financial calculator variables
         
     | 
| 
      
 14 
     | 
    
         
            +
              n, i, PV, PMT, and FV
         
     | 
| 
      
 15 
     | 
    
         
            +
            email: randallreedjr@gmail.com
         
     | 
| 
      
 16 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/timevalue.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            homepage: http://rubygems.org/gems/timevalue
         
     | 
| 
      
 22 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 23 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 24 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 25 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 26 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 27 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 29 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 36 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 37 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 39 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 40 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 41 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
      
 42 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 43 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 44 
     | 
    
         
            +
            summary: Time value of money calculations
         
     | 
| 
      
 45 
     | 
    
         
            +
            test_files: []
         
     |