예제 #1
0
 public EuropeanCallOption(string name, object stockP, object strike, object riskFree, object maturity,
                           object sigma = null, object price = null) : base(name, maturity)
 {
     this.StockPrice = Input(stockP);
     this.Strike     = Input(strike);
     this.RiskFree   = Input(riskFree);
     if (sigma != null)
     {
         this.Sigma = Input(sigma);
         this.Price = GenericOption.PriceFunc(
             () => Math.Exp(-this.StockDivd() * this.Maturity()) * this.StockPrice(),
             () => Math.Exp(-this.RiskFree() * this.Maturity()) * this.Strike(),
             this.Sigma, this.Maturity);
     }
     else if (price != null)
     {
         this.Price = Input(price);
         this.Sigma = () => {
             var t = new EuropeanCallOption(string.Empty, this.StockPrice, this.Strike,
                                            this.RiskFree, this.Maturity, sigma: 0);
             return(Bisection.Search(t.RemoteLink(nameof(t.Sigma), nameof(t.Price)), this.Price(), (0, 1)));
         };
     }
     else
     {
         throw new ArgumentNullException(nameof(sigma), "sigma and price can't be both null");
     }
 }
예제 #2
0
 /// <summary>
 /// Initial instance of <see cref="ExchangeOption"/> from two <see cref="Stock"/>s. Use Margrabe Formula to price.
 /// </summary>
 /// <param name="name">Name of the deferred exchange option</param>
 /// <param name="s1">Asset to be received</param>
 /// <param name="s2">Asset to be delivered</param>
 /// <param name="rho">Correlation between two assets</param>
 /// <param name="maturity">Time to maturity of option</param>
 public ExchangeOption(string name, Stock s1, Stock s2, object rho, object maturity) : base(name, maturity)
 {
     this.Rho   = Input(rho);
     this.Price = GenericOption.PriceFunc(() => Math.Exp(-s1.Divd() * this.Maturity()) * s1.Price(),
                                          () => Math.Exp(-s2.Divd() * this.Maturity()) * s2.Price(),
                                          () => Math.Sqrt(
                                              Math.Pow(s1.Sigma(), 2) + Math.Pow(s2.Sigma(), 2) -
                                              2 * this.Rho() * s1.Sigma() * s2.Sigma()), this.Maturity);
 }
예제 #3
0
 /// <summary>
 /// Initial instance of <see cref="DeferredExchangeOption"/> from two <see cref="Stock"/>s. Use Margrabe Formula to price.
 /// </summary>
 /// <param name="name">Name of the deferred exchange option</param>
 /// <param name="s1">Asset to be received</param>
 /// <param name="s2">Asset to be delivered</param>
 /// <param name="rho">Correlation between two assets</param>
 /// <param name="optionMaturity">Time to maturity of option</param>
 /// <param name="exchangeMaturity">Time until exchange >= TOption</param>
 public DeferredExchangeOption(string name, Stock s1, Stock s2, object rho, object optionMaturity,
                               object exchangeMaturity) : base(name, s1, s2, rho, optionMaturity)
 {
     this.ExchangeMaturity = Input(exchangeMaturity);
     this.Price            = GenericOption.PriceFunc(() => Math.Exp(-s1.Divd() * this.ExchangeMaturity()) * s1.Price(),
                                                     () => Math.Exp(-s2.Divd() * this.ExchangeMaturity()) * s2.Price(),
                                                     () => Math.Sqrt(
                                                         Math.Pow(s1.Sigma(), 2) + Math.Pow(s2.Sigma(), 2) -
                                                         2 * this.Rho() * s1.Sigma() * s2.Sigma()), this.Maturity);
 }
예제 #4
0
 /// <summary>
 /// Initial instance of <see cref="GenericOption"/>
 /// </summary>
 /// <param name="name">Name of the option</param>
 /// <param name="pv1">Present value of asset to be received</param>
 /// <param name="pv2">Present value of asset to be delivered</param>
 /// <param name="maturity">Time to maturity</param>
 /// <param name="sigma">Volatility of the option (Pricing mode)</param>
 /// <param name="price">Price of the option (Imp_vol mode)</param>
 public GenericOption(string name, object pv1, object pv2, object maturity,
                      object sigma = null, object price = null) : base(name, maturity)
 {
     this.Pv1 = Input(pv1);
     this.Pv2 = Input(pv2);
     if (sigma != null)
     {
         this.Sigma = Input(sigma);
         this.Price = PriceFunc(this.Pv1, this.Pv2, this.Sigma, this.Maturity);
     }
     else if (price != null)
     {
         this.Price = Input(price);
         this.Sigma = () => {
             var t = new GenericOption(string.Empty, this.Pv1, this.Pv2, this.Maturity, sigma: 0);
             return(Bisection.Search(updateFunc: t.RemoteLink(xName: "Sigma", yName: "Price"), target: this.Price(), range: (0, 1)));
         };
     }
     else
     {
         throw new ArgumentNullException(nameof(sigma), "sigma and price can't be both null");
     }
 }