90 likes | 94 Views
Ass 2/3 – One Solution. Holding amount double value(Scenario). FinancialEntity name double value(Scenario). Instrument currency. Bond …. Option …. Equity …. Instruments & Portfolios. sax.DocumentHandler. FinancialEntityFactory FinancialEntity make(String)
E N D
Ass 2/3 – One Solution CSC407
Holding amount double value(Scenario) FinancialEntity name double value(Scenario) Instrument currency Bond … Option … Equity … Instruments & Portfolios sax.DocumentHandler FinancialEntityFactory FinancialEntity make(String) register(FinancialEntity) * prototypes * Portfolio CSC407
FinancialEntity name double value(Scenario) PricingFunction double value(FinancialEntity, Scenario) boolean canPrice(FinancialEntity) PricingFunctionFactory PricingFunction getDefault(FinancialEntity) register(PricingFunction) Pricing Functions prototypes * 1 1 BondPricingFunction EquityPricingFunction FXFuturesPricingFunction 2 1..2 IRCurve EquityIndex FXRate CSC407
Pricing Function Code public class EquityPricingFunction extends PricingFunction { public boolean canPrice(FinancialEntity fe) { return fe instanceof Equity; } public double value(FinancialEntity fe, Scenario s) { Equity e = (Equity)fe; … } public initialize(FinancialEntity fe) { Equity e = (Equity)fe; equityIndex = MarketData.getEquityIndex(fe.currency()); } private EquityIndex equityIndex; } CSC407
IRCurve double get(Scenario, double yrs) EquityIndex double get(Scenario) FXRate double get(Scenario); IRCurveImpl double yrs[], rates[] MarketData MarketData name currency static getEquityIndex(currency) … activate(Scenario, Shift) deactivate(Scenario) returns IRCurveShift IRCurveSwitch * Shift indexed by active scenario CSC407
Shift percentage activate(Scenario) deactivate() Scenario name activate(int tid) deactivate() Scenarios ScenarioSet * 1 * MarketData activate(Scenario, Shift) on CSC407
Shift Scenario Scenario Shift IRCurveShift IRCurveSwitch Shift IRCurveShift Scenario Shift IRCurveShift Shift Holding = 1 Holding = 1 Portfolio Portfolio Holding = 10 Holding = 23 BondPF Equity Bond EquityPF Object Diagram ScenarioSet IRCurveImpl Potfolio CSC407
Scenario Activation Thread.run() { int tid = ThreadSet.getNextId(); while(ScenarioSet.stillMore()) { Scenario s = ScenarioSet.getNextScenarioToProcess(); s.activate(tid); s.saveResult(Portfolio.getRoot().value(s)); s.deactivate(); } } Scenario.activate(tid) { for each Shift s { shift.activate(this); } } Shift.activate(Scenario s) { marketData.activate(s, this) } EquityIndexSwitch.activate(Scenario s, Shift shift) { activeScenarios[s.getId()] = new EquityIndexShift(shift); } CSC407
MarketData Pricing Code public class EquityIndexImpl extends EquityIndex { public double get(Scenario s) { return level; } double level; } public class EquityIndexShift extends EquityIndex { public double get(Scenario s) { return e.get(s) * (1+shift.getPercentage()); } EquityIndex e; Shift shift; } public class EquityIndexSwitch extends EquityIndex { public double get(Scenario s) { if(s == null) return eq.get(s); else return activeScenarios[s.getId()].get(s); } EquityIndex activeScenarios[] = new EquityIndex[MAX_THREADS]; EqutyIndex eq; } CSC407