I have been trying to use npv to calculate the net present value. The interest rate and cashflows are from a row of matrix, look like this:
npv(norm(IRR_adj[:,1]),nb,AssetsCF[:,1])
where IRR_add is 1×1185 Array{Float64,2} and I use norm to convert it to a float64; AssetsCF is 101×1185 Adjoint{Float64,Array{Float64,2}}. the expression above is to take Row 1 in Arrays
The error message says:
LoadError: MethodError: no method matching npv(::Float64, ::Int64, ::Array{Float64,1})
Closest candidates are:
npv(::Real, !Matched::AbstractArray{var"#s17",1} where var"#s17"<:Real) at C:\Users\XiaopingWang.julia\packages\NPFinancial\x1dsh\src\NPFinancial.jl:268
in expression starting at C:\Users\XiaopingWang\Desktop\Learning_Julia\Assets_IRR_3.jl:38
top-level scope at Assets_IRR_3.jl:38
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088
Could someone help to point out where is wrong in code please?
Thanks. well-spotted. although a different error appears after entering 2 arguments
for n in 1:3
d(n) = npv(norm(IRR_adj[:,n]),AssetsCF[:,n])
end
LoadError: ArgumentError: ‘Float64’ iterates ‘Float64’ values, which doesn’t satisfy the Tables.jl AbstractRow interface
in expression starting at C:\Users\XiaopingWang\Desktop\Learning_Julia\Assets_IRR_3.jl:41
invalidtable(::Float64, ::Float64) at tofromdatavalues.jl:42
iterate at tofromdatavalues.jl:48 [inlined]
buildcolumns at fallbacks.jl:185 [inlined]
columns at fallbacks.jl:237 [inlined]
DataFrame(::Float64; copycols::Bool) at tables.jl:43
DataFrame(::Float64) at tables.jl:34
top-level scope at Assets_IRR_3.jl:44
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088
I am new to Julia, it’s great to have Julia Forum to help out!
Yea, if this is what you ran to get that error, it is likely coming from d(n). Not sure what type d is but if it is just a Vector with length 3 then you should use
for n in 1:3
d[n] = npv(norm(IRR_adj[:,n]),AssetsCF[:,n])
end