【C#】17. STIR (short interest rate futures)

设置属性的时候想了一下: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);
}
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值