// remember: 'virtual' can be overwritten, 'abstract' must be overwritten public virtual void PriceTradelet(Tradelet tradelet, Exposure _expo, DateTime marketDate) { if (tradelet.DelEnd < marketDate) return; Trade trade = tradelet.MyTrade; Product prod = tradelet.MyTrade.MyProduct; CurveSeries curves = prod.ReturnCurveSeries(); TradingCenter tc = prod.TC; List<DateTime> delDates, expoDates; double nrDays = (tradelet.DelEnd - tradelet.DelStart).TotalDays; double dailyDelta; delDates = TradingCenter.TCEachDay(tradelet.DelStart, tradelet.DelEnd).ToList(); double priceUL = 0; foreach (DateTime day in delDates) { if (day > marketDate) priceUL = curves.GetValue(TENOR_TYPE.DAY, day, marketDate); dailyDelta = prod.UnitSet.ToFullSize(trade.Volume, 1); _expo.AddExpo(EXPOSURE_TYPE.DELTA, TENOR_TYPE.DAY, day, dailyDelta); if(day > marketDate) _expo.AddExpo(EXPOSURE_TYPE.PNL, TENOR_TYPE.DAY, day, dailyDelta * (priceUL - trade.Price)); } }
/// <summary> /// Creates a new ExposureItem that has accumulated every expoType in every tenorType over one MarketDate. @@@ slow? /// [Note CF is accumulated on delivery date?? @@@ check // plus how to accumulate monthly?] /// </summary> public static Exposure CumulateExposures(DateTime marketDate, IEnumerable<Exposure> items, string targetUnit, string targetCCY) { var totalExpo = new Exposure(marketDate, DynamicData.GetUnit(targetUnit), targetCCY); // @@@ all total Exposures are in therms/EUR - create a new Exposure Constructor and add this to the backtest as setting. foreach(Exposure expo in items) // exposure of different items, e.g. different trades or portfolios { foreach (int tenor in TENOR_TYPE.ToStringMapper.Keys) // @@ why loop this way / { foreach (int expoType in expo.DataContainer.Keys) { foreach (DateTime day in expo.DataContainer[tenor][expoType].Keys) totalExpo.AddExpo(expoType, tenor, day, expo.GetExpoValue(expoType, day, tenor) * 1); //Unit.ConvertVolume(expo.UnitSet, totalExpo.UnitSet)); } } } return totalExpo; }
private void SplitExpoToDaily_tofix(Exposure expo, int expoType, IEnumerable<DateTime> expoDates, double expoValue) { foreach (DateTime day in expoDates) { expo.AddExpo(EXPOSURE_TYPE.DELTA, TENOR_TYPE.DAY, day, expoValue); } }