abstract TermStructure
type Bond
rate::Float64
ts::TermStructure
mat_date::Date
end
function Bond(rate::Float64, mat_date::Date)
ts = NullTermStructure()
return Bond(rate, ts, mat_date)
end
type NullTermStructure <: TermStructure end
type PiecewiseYieldCurve <: TermStructure
settlement::Date
bonds::Vector{Bond}
end
function PiecewiseYieldCurve(settlement::Date, sched::Schedule, rate::Float64)
bonds = Vector{Bond}(length(sched))
for (i, d) in enumerate(sched)
new_bond = Bond(rate, d)
bonds[i] = new_bond
end
pyc = PiecewiseYieldCurve(settlement, bonds)
for b in bonds
b.ts = pyc
end
return pyc
endabstract AbstractA
type A <: AbstractA end
type B{T <: AbstractA}
a::T
B() = new()
end
ERROR: MethodError: `convert` has no method matching convert(::Type{B{T<:AbstractA}})
This may have arisen from a call to the constructor B{T<:AbstractA}(...),
since type constructors fall back to convert methods.
Closest candidates are:
convert{T}(::Type{T}, ::T)
call{T}(::Type{T}, ::Any)
in call at essentials.jl:57
B{AbstractA}()
type DiscountingBondEngine{Y <: YieldTermStructure} <: PricingEngine{Y} yts::Y
function call(::Type{DiscountingBondEngine}) new{YieldTermStructure}() end
function call{Y}(::Type{DiscountingBondEngine}, yts::Y) new{Y}(yts) endendpricing_engine = DiscountingBondEngine()