Publishing our request message

The following is our OnStart method, and with it we are asking for both a CDS and a bond to be filled in with its relative information. The actual publish message lines are highlighted as follows. We first create each message, fill out the parameters of what we need to price our instruments, and publish the message to our queue. Please remember the actual financial instruments are for example only. You will need to fill in your specific information in order to achieve your results:

public bool OnStart([CanBeNull] HostControl host)
{
Start(host);
Subscribe();
CreditDefaultSwapRequestMessage msgT = new CreditDefaultSwapRequestMessage();
msgT.fixedRate = 0.001;
msgT.notional = 10000.0;
msgT.recoveryRate = 0.4;
PublishRequestMessage(msgT, "CDSRequest");
BondsRequestMessage r = new BondsRequestMessage();
PublishBondRequestMessage(r, "BondRequest");
return true;
}

Now that we have published our request message, since we subscribed to it, we will receive the notification, and when we do, we will fill in the information similar to how you see it here. We have highlighted the line to where we now publish the response message. Remember, in your world, you are not going to be calling the methods like I am for illustration. Please use time from one of the chapter exercises for you to complete this process as suits your needs:

public bool ProcessCDSMessage(CreditDefaultSwapRequestMessage cds)
{
Create a CDS object.
CDS c = new CDS();

Calculate the Credit Default Swap
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;

Publish the message
PublishResponseMessage(cd, "CDSResponse");

Return the result
return result;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset