设置属性的时候想了一下:GetSetRate,GetSetPrice。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UserDefinedDataEXP
{
public class STFut
{
//data member
private double mktPrice; //STIR的市场价格
private double implRate;
private Date IMMDate; //STIR结算日期
private Date NotionalRepayDate; //结束日期
private int year, month;
private Date dt;
//构造器1
public STFut(double MktPrice, double Month, double Year)
{
this.mktPrice = MktPrice;
this.year = (int)Year;
this.month =(int)Month;
dt = new Date( year,month, 1);
IMMDate = dt.IMMDate();
NotionalRepayDate = dt.IMM_Date_Nth(2);
implRate = (100 - mktPrice)/100.0;
}
//Forward Discount Factor
public double fwDFq()
{
double yf = IMMDate.YF_AA(NotionalRepayDate);
return 1.0/(1+implRate*yf);
}
//返回futures的有效天数
public int Term()
{
return IMMDate.D_MM(NotionalRepayDate);
}
//下个MMDate属性
public Date GetIMMDate
{
get { return IMMDate; }
}
//implied rate属性
public double GetSetRate
{
get
{
return implRate;
}
set {
implRate = value;
mktPrice = 100 - 100 * implRate;
}
}
//mktPrice属性
public double GetSetPrice
{
get
{
return mktPrice;
}
set
{
mktPrice = value;
implRate = (100 - mktPrice) / 100;
}
}
//到期日期属性
public Date GetNotionalRepayDate
{
get { return NotionalRepayDate; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Globalization;
namespace UserDefinedDataEXP
{
class test
{
static void Main(string[] args)
{
Example1();
Console.Read();
}
public static void Example1()
{
// Create Future
double price = 99.0;
double month = 12;
double year = 2013;
STFut myFut = new STFut(99.00, 12, 2013);
//Method
Console.WriteLine("fwdDF: {0}", myFut.fwDFq());
Console.WriteLine("IMMDate: {0}", myFut.GetIMMDate);
Console.WriteLine("Term: {0}", myFut.Term());
// Property
Console.WriteLine("NotionalRepayDate: {0}", myFut.GetNotionalRepayDate);
Console.WriteLine();
// Get/Set
Console.WriteLine("Price: {0}, Rate: {1:P2}", myFut.GetSetPrice, myFut.GetSetRate);
// Changing price
double newPrice = 99.50;
myFut.GetSetPrice = newPrice;
Console.WriteLine("New price {0}", newPrice);
Console.WriteLine("Price: {0}, Rate: {1:P2}", myFut.GetSetPrice, myFut.GetSetRate);
Console.WriteLine();
// Changing rate
double newRate = 0.015;
myFut.GetSetRate = newRate;
Console.WriteLine("New Rate {0:P2}", newRate);
Console.WriteLine("Price: {0}, Rate: {1:P2}", myFut.GetSetPrice, myFut.GetSetRate);
}
}
}