This video shows how we can use Algorithms written in matlab 'M' code can be used in .Net applications. (View the video in 'double size' resolution).
Matlab Code snippet
--------------------
function [ Price,AccruedInt ] = MyBndPrice(Yield, CouponRate, Settle,...
Maturity, Period, Basis)
[Price, AccruedInt] = bndprice(Yield, CouponRate, Settle,...
Maturity, Period, Basis);
end
.Net Code snippet
-------------------
private void btnBndPrice_Click(object sender, EventArgs e)
{
MWNumericArray yields = GetYields();
MWNumericArray coupon = new MWNumericArray(Convert.ToDouble(txtCoupon.Text) ) ;
MWNumericArray period = new MWNumericArray(cmbPeriod.SelectedIndex + 1 ) ;
MWNumericArray basis = new MWNumericArray(cmbBasis.SelectedIndex);
MWCharArray settlement = new MWCharArray(txtSettlement.Text);
MWCharArray maturity = new MWCharArray(txtMaturity.Text);
MyFinLib.MyFinLibclass finLib = new MyFinLib.MyFinLibclass();
MWArray[] result = finLib.MyBndPrice(2, yields, coupon, settlement, maturity, period, basis);
Display(result);
}
private double[] GetYields()
{
string[] yieldStr = txtYield.Text.Split(',');
double[] yields = new double[ yieldStr.Length ];
for (int i = 0; i < yieldStr.Length; i++)
yields[i] = Convert.ToDouble(yieldStr[i]);
return yields ;
}
private void Display(MWArray[] result)
{
DataTable dt = new DataTable();
dt.Columns.Add("Price");
dt.Columns.Add("Accrued Interest");
string[] price = result[0].ToString().Split('\n');
string[] accuredInt = result[1].ToString().Split('\n');
for (int i = 0; i < price.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = price[i];
row[1] = accuredInt[i];
dt.Rows.Add(row);
}
dataGridView1.DataSource = dt;
}