//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Process the cds message described by cds. </summary> /// /// <param name="cds"> The cds. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public bool ProcessCDSMessage(CreditDefaultSwapRequestMessage cds) { CDS c = new CDS(); bool result = c.CalcCDS(ref cds, cds.fixedRate, cds.notional, cds.recoveryRate); // the message is populated with the fair rate and NPV now. CreditDefaultSwapResponseMessage cd = new CreditDefaultSwapResponseMessage(); cd.fixedRate = cds.fixedRate; cd.fairNPV = cds.fairNPV; cd.fairRate = cds.fairRate; cd.notional = cds.notional; cd.recoveryRate = cds.recoveryRate; PublishResponseMessage(cd, "CDSResponse"); return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Process the cds message described by msg. </summary> /// /// <param name="msg"> The message. This cannot be null. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// bool ProcessCDSMessage([NotNull] CreditDefaultSwapResponseMessage msg) { WriteLineInColor("Received Credit Default Swap Response Message", ConsoleColor.Yellow); RILogManager.Default?.SendInformation("Received Credit Default Swap Response Message"); WriteLineInColor("calculated spread: " + msg.fairRate, ConsoleColor.Yellow); WriteLineInColor("calculated NPV: " + msg.fairNPV, ConsoleColor.Yellow); msg.ID = new Random().Next(3000001, 4000000); using (var _db = new LiteDatabase(connectionString)) { Thread.Sleep(5); _db.Shrink(); var collection = _db.GetCollection <CreditDefaultSwapResponseMessage>(); collection.EnsureIndex(x => x.ID); collection.Insert(msg); } return(true); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Publish response message. </summary> /// /// <param name="msg"> The message. </param> /// <param name="topic"> The topic. </param> /// <param name="routingID"> (Optional) Identifier for the routing. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public void PublishResponseMessage(CreditDefaultSwapResponseMessage msg, string topic, string routingID = "") { Bus.Publish(msg, topic); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Process the cds response described by cds. </summary> /// /// <param name="cds"> The cds. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public bool ProcessCDSResponse(CreditDefaultSwapResponseMessage cds) { Console.WriteLine("calculated spread: " + cds.fairRate); Console.WriteLine("calculated NPV: " + cds.fairNPV); return(true); }