Question about classes package
- To: mathgroup at smc.vnet.net
- Subject: [mg114488] Question about classes package
- From: "tarpanelli at libero.it" <tarpanelli at libero.it>
- Date: Sun, 5 Dec 2010 21:55:02 -0500 (EST)
- Reply-to: "tarpanelli at libero.it" <tarpanelli at libero.it>
Hello, I am trying to understand how works the classes package but I am get some error. I use the following packages: Needs["Classes`"] Needs["Calendar`"] This is the class that I use to store some simple data Class[ YieldCurveData, Object, {dfact, now}, { {new, (new[super]; dfact = #1; now = #2) &}, {DiscountFactors, dfact &}, {NowDate, now &} } ] This is a module that I would like to use as method inside the subclass YieldCurveTermStructure: P[df_, t0_, t_] := Module[{n, dftable, B}, n = Length[df]; dftable = Table[{DaysBetween[t0, df[[i, 1]]]/365, df[[i, 2]]}, {i, 3, n}]; B = Interpolation[dftable]; B[t] ]; This is the subclass YieldCurveTermStructure Class[YieldCurveTermStructure, YieldCurveData, {}, { {new, new[super] &}, {B, P[dfact, now, #] &} } ] dfact -> discfactors := ( { {Dates, DiscountFactors}, {{2010, 12, 2}, 1}, {{2010, 12, 9}, 0.9998531}, {{2011, 1, 3}, 0.999336}, {{2011, 2, 2}, 0.9985969}, {{2011, 3, 2}, 0.9973797}, {{2011, 6, 2}, 0.9938465}, {{2011, 9, 2}, 0.9907724}, {{2011, 12, 2}, 0.9875571}, {{2012, 12, 3}, 0.9691823}, {{2013, 12, 2}, 0.9463441}, {{2014, 12, 2}, 0.9181686}, {{2015, 12, 2}, 0.8864135}, {{2022, 12, 2}, 0.6633433}, {{2030, 12, 2}, 0.4846045}, {{2035, 12, 3}, 0.4212485} } now ->nowdate = {2010, 12, 2}; I can create correctly the first class as: ycdata = new[YieldCurveData, discfactors, nowdate] but when I go to create the subclass yc = new[YieldCurveTermStructure, dfact, now] I get this error: Function::slotn: Slot number 1 in (new[Classes`Private`raise[- YieldCurveTermStructure-,Object]];dfact$743=#1;now$743=#2)& cannot be filled from ((new[Classes`Private`raise[-YieldCurveTermStructure-,Object]]; dfact$743=#1;now$743=#2)&)[]. >> Function::slotn: Slot number 2 in (new[Classes`Private`raise[- YieldCurveTermStructure-,Object]];dfact$743=#1;now$743=#2)& cannot be filled from ((new[Classes`Private`raise[-YieldCurveTermStructure-,Object]]; dfact$743=#1;now$743=#2)&)[]. >> Any suggestion and correctlion it would be great, thank you P