org.unizone.finance.interest

Type YieldSwapData

org.unizone.0.6380
Instance of Type
Inheriting from YieldData

Type dataValue
org.uninode.Type.displayPatterna {att:org.uninode.Node.type}

Attribute summaryDefined inUninode® IdPropertiesDefault
StringtoString
This is the display string.
Nodeorg.uninode.0.102
Typetype
The type of an object determines the behaviour and attributes of the object.
Nodeorg.uninode.0.101
StringuriNodeorg.uninode.0.103

Script summary
org.unizone.0.8543
/*
instance Array[Real] pYears;
instance Array[Real] pRates;
instance Collection[TimeData] overnights;
instance Collection[TimeData] stibors;
instance Collection[TimeData] fras;
instance Collection[TimeData] swaps;
instance Collection[TimeData] allData;

constructor(Source source, Time time) {
  TimeFunction:(source, time);
}
Real rateAt(Real years) {
  if (years < instance pYears.at(0)) {
    if (years < 1 / 366) return null;
    Real years0 = instance pYears.at(0);
    Real df0 = 1/((instance pRates.at(0)/100+1)^years0);
    Real df = 1 - (1 - df0) * years / years0;
    return ((1/df)^(1/years)-1) * 100;
  }
  Int left = 0;
  Int right = instance pYears.size - 1;
  while(right - left > 1) {
    Int test = ((left + right) / 2).round;
    if (years > instance pYears.at(test))
      left = test;
    else
      right = test;
  }
  Real leftYears = instance pYears.at(left);
  Real leftRate = instance pRates.at(left);
  Real rightYears = instance pYears.at(right);
  Real rightRate = instance pRates.at(right);
  leftRate + (rightRate - leftRate) * (years - leftYears) / (rightYears - leftYears);
}
Real discountFactorAt(Real years) {
  if (years < instance pYears.at(0)) {
    if (years < 0) return null;
    if (years == 0) return 1;
    Real years0 = instance pYears.at(0);
    Real df0 = 1/((instance pRates.at(0)/100+1)^years0);
    return 1 - (1 - df0) * years / years0;
  }
  1/((rateAt(years)/100 + 1) ^ years);
}
Void prepareOvernight(TimeData td, Int index, Time t) {
  Int maturityDay = 365)) ^ (365/dt1) - 1) * 100;
  instance pYears.set(index, dt1 / 365);
  instance pRates.set(index, rate);
}
Void prepareStibor(TimeData td, Int index, Time t) {
  Int dt0 = td.maturity.subtractDate(t);
  Int dt2 = td.maturity.subtractDate(t.settlement(2));
  Real rate = (((1 + td.value * dt2 / 36000) / discountFactorAt((dt0 - dt2)/ 365)) ^ (365/dt0) - 1) * 100;
  instance pYears.set(index, dt0 / 365);
  instance pRates.set(index, rate);
}
Void prepareFRA(TimeData td, Int index, Time t) {
  Real val = td.value / 100;
  Time maturityDate = td.maturity;
  Real maturityT = maturityDate.subtractDate(t) / 365;
  if (maturityT > 1) maturityT = maturityDate.subtractDate360(t) / 360;
  Time endDate = maturityT);
  Real df2 = 1 / (dt * val + 1);
  Real rate = ((1 / (df1 * df2)) ^ (1 / endT) - 1) * 100;
  instance pYears.set(index, endT);
  instance pRates.set(index, rate);
}
Void prepareSwap(TimeData td, Int index, Time t) {
  Real val = td.value / ((rateAt(time) / 100 + 1) ^ time);
    year = year - 1;
  }
  time = mat.subtractDate360(t) / 360;
  Real df = (discountFactorAt(t2.subtractDate(t) / 365) - x * val) / (val + 1);
  Real rate = ((1 / df) ^ (1 / time) - 1) * 100;
  instance pYears.set(index, time);
  instance pRates.set(index, rate);
}
Boolean iterate() {
  Array[Real] oldYears = instance pYears;
  Array[Real] oldRates = instance pRates;
  instance pYears = new Array(Real, instance allData.size);
  instance pRates = new Array(Real, instance allData.size);
  0 .to(instance pYears.size - 1, Void(Int i) {
    if (oldYears == null) {
      instance pYears.set(i, i * 2);
      instance pRates.set(i, 4);
    } else {
      instance pYears.set(i, oldYears.at(i));
      instance pRates.set(i, oldRates.at(i));
    }
  });
  Int index = 0;
  Time t = time();
  instance overnights.do(Void(TimeData td) {
    prepareOvernight(td, index, t);
    index = index + 1;
  });
  instance stibors.do(Void(TimeData td) {
    prepareStibor(td, index, t);
    index = index + 1;
  });
  instance fras.do(Void(TimeData td) {
    prepareFRA(td, index, t);
    index = index + 1;
  });
  instance swaps.do(Void(TimeData td) {
    prepareSwap(td, index, t);
    index = index + 1;
  });
  if (oldYears == null) return false;
  0 .to(oldYears.size - 1, Void(Int i) {
    if ((oldRates.at(i) - instance pRates.at(i)).abs > 0.00001) return false;
  });
  return true;
}
Boolean formatCurve(
    Collection[TimeData] overnights,
    Collection[TimeData] stibors,
    Collection[TimeData] fras,
    Collection[TimeData] swaps) {
  Time lastDate = Time{fras.last.aspectValue(#end)};
  swaps = swaps.select(Boolean(TimeData swap) {swap.maturity > lastDate});
  List[TimeData] allData = new List(TimeData);
  allData.addAll(overnights);
  allData.addAll(stibors);
  allData.addAll(fras);
  allData.addAll(swaps);
  if (allData.size < 1) return false;
  instance allData = allData;
  instance overnights = overnights;
  instance stibors = stibors;
  instance fras = fras;
  instance swaps = swaps;
  while(!iterate());
  return true;
}
Object aspectValue(Symbol aspect) {
  if (aspect == #components)
    return instance allData;
  if (aspect == #discountFactor)
    return discountFactorAt(Real{external cond_maturity});
  if (aspect == #value) 
    return rateAt(Real{external cond_maturity});
  return null;
}

*/