コード例 #1
0
 public static Product CreateEquityCall([QuantSAExcelArgument(Description = "A share.  This needs to match a share in the model that will be used to value this.")] Share share,
                                        [QuantSAExcelArgument(Description = "Exercise date.")] Date exerciseDate,
                                        [QuantSAExcelArgument(Description = "Strike")] double strike,
                                        [QuantSAExcelArgument(Description = "PutOrCall")] PutOrCall putOrCall)
 {
     return(new EuropeanOption(share, putOrCall, strike, exerciseDate));
 }
コード例 #2
0
ファイル: AsianOption.cs プロジェクト: riskworx/QuantSA
 public AsianOption(Share share, PutOrCall putOrCall, double strike, Date exerciseDate)
 {
     _share        = share;
     _putOrCall    = putOrCall;
     _strike       = strike;
     _exerciseDate = exerciseDate;
 }
コード例 #3
0
        /// <summary>
        /// The Black formula
        /// </summary>
        /// <param name="putOrCall">put or call.</param>
        /// <param name="strike">The strike.</param>
        /// <param name="T">The time to maturity in years from the value date to the exercise date.</param>
        /// <param name="forward">The forward at the option exercise date.</param>
        /// <param name="vol">The lognormal volatility of the underlying price.</param>
        /// <param name="discountFactor">The discount factor from the value date to the settlement date of the option.</param>
        /// <returns></returns>
        public static double Black(PutOrCall putOrCall, double strike, double T, double forward, double vol, double discountFactor)
        {
            var dist       = new Normal();
            var sigmaSqrtT = vol * Math.Sqrt(T);
            var d1         = 1 / sigmaSqrtT * (Math.Log(forward / strike) + 0.5 * vol * vol);
            var d2         = d1 - sigmaSqrtT;

            return(discountFactor * (forward * dist.CumulativeDistribution(d1) - strike * dist.CumulativeDistribution(d2)));
        }
コード例 #4
0
ファイル: BlackEtc.cs プロジェクト: sandboxorg/QuantSA
        /// <summary>
        /// The Black the scholes formula
        /// </summary>
        /// <param name="putOrCall">put or call.</param>
        /// <param name="K">The strike.</param>
        /// <param name="T">The time to maturity in years.</param>
        /// <param name="S">The underlying spot price.</param>
        /// <param name="vol">The lognormal volatility of the underlying price.</param>
        /// <param name="rate">The continuous rate used for drifting the underlying and discounting the payoff.</param>
        /// <param name="div">The contiuous dividend yield that decreased the drift on the underlying.</param>
        /// <returns></returns>
        public static double BlackScholes(PutOrCall putOrCall, double K, double T, double S, double vol, double rate, double div)
        {
            Normal dist       = new Normal();
            double sigmaSqrtT = vol * Math.Sqrt(T);
            double d1         = (1 / sigmaSqrtT) * (Math.Log(S / K) + rate - div + 0.5 * vol * vol);
            double d2         = d1 - sigmaSqrtT;
            double F          = S * Math.Exp((rate - div) * T);

            return(Math.Exp(-rate * T) * (F * dist.CumulativeDistribution(d1) - K * dist.CumulativeDistribution(d2)));
        }
コード例 #5
0
        /// <summary>
        /// The Black the scholes formula
        /// </summary>
        /// <param name="putOrCall">put or call.</param>
        /// <param name="strike">The strike.</param>
        /// <param name="T">The time to maturity in years.</param>
        /// <param name="spot">The underlying spot price.</param>
        /// <param name="vol">The lognormal volatility of the underlying price.</param>
        /// <param name="rate">The continuous rate used for drifting the underlying and discounting the payoff.</param>
        /// <param name="div">The continuous dividend yield that decreased the drift on the underlying.</param>
        /// <returns></returns>
        public static double BlackScholes(PutOrCall putOrCall, double strike, double T, double spot, double vol, double rate,
                                          double div)
        {
            var dist       = new Normal();
            var sigmaSqrtT = vol * Math.Sqrt(T);
            var d1         = 1 / sigmaSqrtT * (Math.Log(spot / strike) + rate - div + 0.5 * vol * vol);
            var d2         = d1 - sigmaSqrtT;
            var forward    = spot * Math.Exp((rate - div) * T);

            return(Math.Exp(-rate * T) * (forward * dist.CumulativeDistribution(d1) - strike * dist.CumulativeDistribution(d2)));
        }
コード例 #6
0
ファイル: JSEBondOption.cs プロジェクト: riskworx/QuantSA
        public JSEBondOption(Date forwardDate, Date maturityDate, PutOrCall putOrCall, Date settleDate)
        {
            if (forwardDate > maturityDate)
            {
                throw new ArgumentException("forward date must be before maturity date.");
            }

            this.forwardDate = forwardDate;
            this.putOrCall   = putOrCall;
            this.settleDate  = settleDate;
            timeToMaturity   = (double)(forwardDate - settleDate) / 365;
        }
コード例 #7
0
 public static JSEBondOption CreateBesaJseBondOption(
     [ExcelArgument(Description = "The forward date of the bond.")]
     Date forwardDate,
     [ExcelArgument(Description = "The maturity date of the contract.")]
     Date maturityDate,
     [ExcelArgument(Description = "put or call.")]
     PutOrCall putOrCall,
     [ExcelArgument(Description = "The settlement date of the bond.")]
     Date settleDate)
 {
     return(new JSEBondOption(forwardDate, maturityDate, putOrCall, settleDate));
 }
コード例 #8
0
ファイル: FIXPutOrCall.cs プロジェクト: heber/FreeOQ
 public static int ToFIX(PutOrCall value)
 {
     switch (value)
     {
         case PutOrCall.Put:
             return 0;
         case PutOrCall.Call:
             return 1;
         default:
             throw new ArgumentException(string.Format("err: ", value));
     }
 }
コード例 #9
0
 /// <summary>
 /// Constructor from expiration date, strike price, and put/call
 /// indicator.
 /// </summary>
 /// <param name="symbol"></param>
 /// <param name="exchange"></param>
 /// <param name="expireDate"></param>
 /// <param name="strikePrice"></param>
 /// <param name="putCall"></param>
 public MamdaOptionContract(
     string symbol,
     string exchange,
     DateTime expireDate,
     double strikePrice,
     PutOrCall putCall)
 {
     mSymbol      = symbol;
     mExchange    = exchange;
     mExpireDate  = expireDate;
     mStrikePrice = strikePrice;
     mPutCall     = putCall;
 }
コード例 #10
0
ファイル: MamdaOptionContract.cs プロジェクト: jacobraj/MAMA
        /// <summary>
        /// Constructor from expiration date, strike price, and put/call
        /// indicator.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="exchange"></param>
        /// <param name="expireDate"></param>
        /// <param name="strikePrice"></param>
        /// <param name="putCall"></param>
        public MamdaOptionContract(
			string		symbol,
			string		exchange,
			DateTime	expireDate,
			double		strikePrice,
			PutOrCall	putCall)
        {
            mSymbol        = symbol;
            mExchange      = exchange;
            mExpireDate    = expireDate;
            mStrikePrice   = strikePrice;
            mPutCall       = putCall;
        }
コード例 #11
0
        internal static PutCall Convert(PutOrCall value)
        {
            switch (value)
            {
            case PutOrCall.Put:
                return(PutCall.Put);

            case PutOrCall.Call:
                return(PutCall.Call);

            default:
                throw new ArgumentException(string.Format("Unsupported put or call: {0}", value));
            }
        }
コード例 #12
0
            public static OpenQuant.API.PutCall Convert(PutOrCall value)
            {
                switch ((int)value)
                {
                case 0:
                    return(OpenQuant.API.PutCall.Put);

                case 1:
                    return(OpenQuant.API.PutCall.Call);

                default:
                    throw new ArgumentException(string.Format("Unknown PutOrCall - {0}", value));
                }
            }
コード例 #13
0
        public static int ToFIX(PutOrCall value)
        {
            switch (value)
            {
            case PutOrCall.Put:
                return(0);

            case PutOrCall.Call:
                return(1);

            default:
                throw new ArgumentException(string.Format("err: ", value));
            }
        }
コード例 #14
0
 public static double FormulaBlack([ExcelArgument(Description = "put or call.")]
                                   PutOrCall putOrCall,
                                   [ExcelArgument(Description = "The strike")]
                                   double strike,
                                   [ExcelArgument(Description = "The time to maturity in years from the value date to the exercise date.")]
                                   double timeToExercise,
                                   [ExcelArgument(Description = "The forward at the option exercise date.")]
                                   double forward,
                                   [ExcelArgument(Description = "Annualized volatility.")]
                                   double vol,
                                   [ExcelArgument(Description = "The discount factor from the value date to the settlement date of the option.")]
                                   double discountFactor)
 {
     return(BlackEtc.Black(putOrCall, strike, timeToExercise, forward, vol, discountFactor));
 }
コード例 #15
0
 public static double FormulaBlackScholes([QuantSAExcelArgument(Description = "PutOrCall")] PutOrCall putOrCall, [ExcelArgument(Description = "Strike")]
                                          double strike,
                                          [ExcelArgument(Description = "The value date as and Excel date.")]
                                          Date valueDate,
                                          [ExcelArgument(Description = "The exercise date of the option.  Must be greater than the value date.")]
                                          Date exerciseDate,
                                          [ExcelArgument(Description = "The spot price of the underlying at the value date.")]
                                          double spotPrice,
                                          [ExcelArgument(Description = "Annualized volatility.")]
                                          double vol,
                                          [ExcelArgument(Description = "Continuously compounded risk free rate.")]
                                          double riskfreeRate,
                                          [QuantSAExcelArgument(Description = "Continuously compounded dividend yield.", Default = "0.0")]
                                          double divYield)
 {
     return(BlackEtc.BlackScholes(putOrCall, strike,
                                  Actual365Fixed.Instance.YearFraction(valueDate, exerciseDate),
                                  spotPrice, vol, riskfreeRate, divYield));
 }
コード例 #16
0
        private void ctxInstruments_AddNew_Click(object sender, EventArgs e)
        {
            NewInstrumentForm newInstrumentForm = new NewInstrumentForm();
            TreeNode          selectedNode      = this.trvInstruments.SelectedNode;
            string            str1 = (string)null;

            if (selectedNode is InstrumentNode)
            {
                str1 = ((FIXInstrument)(selectedNode as InstrumentNode).Instrument).SecurityType;
            }
            if (selectedNode is GroupNode)
            {
                SortedList <string, bool> sortedList = new SortedList <string, bool>();
                foreach (Instrument instrument in (selectedNode as GroupNode).Instruments)
                {
                    sortedList[((FIXInstrument)instrument).SecurityType] = true;
                }
                if (sortedList.Count == 1)
                {
                    str1 = sortedList.Keys[0];
                }
            }
            if (str1 != null)
            {
                newInstrumentForm.InstrumentType = APITypeConverter.InstrumentType.Convert(str1);
            }
            while (newInstrumentForm.ShowDialog((IWin32Window)this) == DialogResult.OK)
            {
                string    symbol    = newInstrumentForm.Symbol;
                string    str2      = APITypeConverter.InstrumentType.Convert(newInstrumentForm.InstrumentType);
                string    exchange  = newInstrumentForm.Exchange;
                string    currency  = newInstrumentForm.Currency;
                DateTime  maturity  = newInstrumentForm.Maturity;
                PutOrCall putOrCall = APITypeConverter.PutCall.Convert(newInstrumentForm.PutCall);
                double    strike    = newInstrumentForm.Strike;
                if (InstrumentManager.Instruments.Contains(symbol))
                {
                    int num = (int)MessageBox.Show((IWin32Window)this, string.Format("Instrument {0} already exists!", symbol), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    Instrument instrument = new Instrument(symbol, str2);
                    if (!string.IsNullOrEmpty(exchange))
                    {
                        ((FIXInstrument)instrument).SecurityExchange = exchange;
                    }
                    if (!string.IsNullOrEmpty(currency))
                    {
                        instrument.Currency = currency;
                    }
                    if (str2 == "FUT" || str2 == "OPT" || str2 == "FOP")
                    {
                        ((FIXInstrument)instrument).MaturityDate = maturity;
                        if (str2 == "OPT" || str2 == "FOP")
                        {
                            instrument.PutOrCall = putOrCall;
                            ((FIXInstrument)instrument).StrikePrice = strike;
                        }
                    }
                    instrument.Save();
                    break;
                }
            }
            newInstrumentForm.Dispose();
        }
コード例 #17
0
		internal static PutCall Convert(PutOrCall value)
		{
			switch (value)
			{
			case PutOrCall.Put:
				return PutCall.Put;
			case PutOrCall.Call:
				return PutCall.Call;
			default:
				throw new ArgumentException(string.Format("Unsupported put or call: {0}", value));
			}
		}
コード例 #18
0
ファイル: APITypeConverter.cs プロジェクト: smther/FreeOQ
			public static OpenQuant.API.PutCall Convert(PutOrCall value)
			{
				switch ((int)value)
				{
					case 0:
						return OpenQuant.API.PutCall.Put;
					case 1:
						return OpenQuant.API.PutCall.Call;
					default:
						throw new ArgumentException(string.Format("Unknown PutOrCall - {0}", value));
				}
			}