Thanks Tim, this is very helpful!  Happy New Year!

- Chris

On Thursday, December 31, 2015 at 6:33:29 PM UTC-5, Tim Holy wrote:
>
> See 
> http://docs.julialang.org/en/stable/manual/faq/#how-do-abstract-or-ambiguous-fields-in-types-interact-with-the-compiler
>  
> and the section 
> afterwards. You'd be better off with 
>
> type Bond{T<:TermStructure} 
>     rate::Float64 
>     ts::T 
>     mat_dat::Date 
> end 
>
> --Tim 
>
> On Thursday, December 31, 2015 02:42:11 PM Christopher Alexander wrote: 
> > Hello all, 
> > 
> > I have a question about the usage of circular references in types.  In a 
> > project I am working on, I am running into several situations where this 
> > type of design appears to be the best issue.  For example, let's say I 
> have 
> > this (this is a massive simplification but illustrates my point): 
> > 
> > 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 
> > end 
> > 
> > 
> > Firstly, I guess, is this the best implementation?  There are situations 
> > where I need the bonds of the PiecewiseYieldCurve to be aware of the 
> > TermStructure to which they are connected.  Secondly, do I take a 
> > performance hit from this?  The PiecewiseYieldCurve instance will have 
> > parts of it updated as I run some of my pricer methods (not shown). 
> > 
> > Thanks! 
> > 
> > Chris 
>
>

Reply via email to