Пример #1
0
        public static object LocalVolDenominator(object mktObj, object[] dates, double[] strikes, string assetName)
        {
            return(FunctionRunnerUtils.Run("LocalVolSurface", () =>
            {
                Market market = MarketManager.Instance.GetMarket(mktObj);
                AssetMarket assetMarket = market.AssetMarketFromName(assetName);
                VolatilitySurface volSurface = assetMarket.VolSurface();

                var localVariance = volSurface.LocalVariance;
                var moneyness = volSurface.Moneyness;
                var time = volSurface.Time;

                var result = new double[dates.Length, strikes.Length];
                for (int i = 0; i < dates.Length; i++)
                {
                    var date = ObjectConverters.ConvertDate(dates[i], assetMarket.RefDate);
                    double t = time[date];
                    var denomFunc = localVariance.Denominator(t);
                    var denoms = strikes.Map(k =>
                    {
                        var y = moneyness.Moneyness(t, k);
                        return denomFunc.Eval(y);
                    });
                    ArrayUtils.SetRow(ref result, i, denoms);
                }
                return result;
            }));
        }
Пример #2
0
        public override IModelDescription Calibrate(BlackScholesModelCalibDesc bsDesc, Market market)
        {
            AssetMarket assetMkt     = market.AssetMarketFromName(bsDesc.Asset);
            var         volSurface   = assetMkt.VolSurface();
            var         forwardCurve = assetMkt.Forward();
            var         optionPricer = BlackScholesWithDividendOption.Build(assetMkt.Spot, assetMkt.Dividends, assetMkt.RiskFreeDiscount, assetMkt.Time);

            var calibMaturities = bsDesc.CalibrationMaturities.Map(d => d.ToDate(assetMkt.RefDate));
            var calibStrikes    = bsDesc.CalibrationStrikes;
            var calibDates      = assetMkt.Time[calibMaturities];

            double[] targetPrices = new double[calibDates.Length];
            double[] optionTypes  = new double[calibDates.Length];
            for (int i = 0; i < calibMaturities.Length; i++)
            {
                var targetVol  = volSurface.Volatility(calibDates[i], calibStrikes[i]);
                var optionType = (calibStrikes[i] > forwardCurve.Fwd(calibMaturities[i])) ? 1.0 : -1.0;
                targetPrices[i] = optionPricer.Price(calibDates[i], calibStrikes[i], targetVol, optionType);
                optionTypes[i]  = optionType;
            }

            var calibratedVols = optionPricer.CalibrateVol(calibDates, targetPrices, bsDesc.CalibrationStrikes, optionTypes);
            var sigma          = new MapRawDatas <DateOrDuration, double>(bsDesc.CalibrationMaturities, calibratedVols);

            return(new BlackScholesModelDescription(bsDesc.Asset, sigma, bsDesc.WithDivs));
        }
Пример #3
0
 public void ModifyCcy(FXMarket mkt, AssetMarket aMkt, string v, ICcyAsset valueCcy, bool isLastRow)
 {
     if (isLastRow)
     {
         _Ccy = valueCcy.Ccy;
     }
 }
Пример #4
0
        public void CheckZeroVolForward(AssetMarket assetMkt)
        {
            var zcCurve = assetMkt.RiskFreeDiscount;
            var market  = new Market(new[] { zcCurve }, new[] { assetMkt });

            var zeroVol           = new MapRawDatas <DateOrDuration, double>(new[] { new DateOrDuration(assetMkt.RefDate) }, new[] { 0.0 });
            var blackScholesDesc  = new BlackScholesModelDescription(assetMkt.Asset.Name, zeroVol, true);
            var mcConfig          = new MonteCarloConfig(1, RandomGenerators.GaussianSobol(SobolDirection.Kuo3));
            var blackScholesModel = ModelFactory.Instance.Build(blackScholesDesc, market);

            var fwdDates = new[] { Duration.Month, 6 * Duration.Month, Duration.Year, 2 * Duration.Year, 5 * Duration.Year }
            .Map(d => assetMkt.RefDate + d);

            IProduct    fwdLeg      = ForwardLeg(fwdDates);
            PriceResult priceResult = (PriceResult)McPricer.WithDetails(mcConfig).Price(fwdLeg, blackScholesModel, market);

            double[] fwds = priceResult.Details.Map(kv => kv.Item3.Value);

            var assetFwdCurve = assetMkt.Forward();

            double[] refFwds = fwdDates.Map(d => assetFwdCurve.Fwd(d) * zcCurve.Zc(d));

            foreach (var i  in Enumerable.Range(0, fwdDates.Length))
            {
                var err = Math.Abs(fwds[i] / refFwds[i] - 1.0);
                Assert.LessOrEqual(err, 20.0 * DoubleUtils.MachineEpsilon);
            }
        }
Пример #5
0
        public static object EquityImpliedVol(object mktObj, string assetName, object maturity, double strike, double price, string optionType)
        {
            return(FunctionRunnerUtils.Run("EquityImpliedVol", () =>
            {
                Market market = MarketManager.Instance.GetMarket(mktObj);
                AssetMarket assetMkt = market.AssetMarketFromName(assetName);
                var pricer = BlackScholesWithDividendOption.Build(assetMkt.Spot,
                                                                  assetMkt.Dividends,
                                                                  assetMkt.RiskFreeDiscount,
                                                                  assetMkt.Time);
                double q;
                switch (optionType.Trim().ToLower())
                {
                case "call":
                    q = 1.0;
                    break;

                case "put":
                    q = -1.0;
                    break;

                default:
                    throw new Exception(string.Format("Unknow option type : {0}", optionType));
                }

                var matAsDate = ObjectConverters.ConvertDate(maturity, assetMkt.RefDate);
                return pricer.ImpliedVol(assetMkt.Time[matAsDate], strike, price, q);
            }));
        }
Пример #6
0
 public void SetUpMarkets(CurrencyAssetStaticsDataBase ccyDB, FXMarket mkt, AssetMarket aMkt)
 {
     _DataHistory.SetCcyDB(ccyDB);
     dataGridViewAccounting.SetUpMarkets(ccyDB, mkt, aMkt);
     dataGridViewFXMarket.ShowMarket(mkt, ccyDB);
     dataGridViewAssetMarket.ShowMarket(aMkt, ccyDB);
 }
Пример #7
0
        public void AssetMarket()
        {
            AssetMarket aMkt     = Init.CreateAssetMarket();
            string      fileName = SerializeObject(aMkt, "AssetMarket");
            AssetMarket desAMkt  = DeserializeObject <AssetMarket>(fileName);

            Assert.IsTrue(aMkt == desAMkt);
        }
 internal void SetUpMarkets(CurrencyAssetStaticsDataBase ccyDB, FXMarket mkt, AssetMarket aMkt)
 {
     _CcyDB          = ccyDB;
     FXMarketUsed    = mkt;
     AssetMarketUsed = aMkt;
     //Ccies = mkt.GetAvailableCurrencies();
     //Assets = aMkt.GetAvailableAssets();
 }
Пример #9
0
 public AccountingData(List <Category> input, FXMarket mkt, AssetMarket aMkt)
 {
     _Ccy         = new Currency("USD");
     _Data        = input;
     _FXMarket    = mkt;
     _AssetMarket = aMkt;
     _Map         = new TreeViewMapping(_Data);
 }
Пример #10
0
 public void ModifyTotalCcy(FXMarket mkt, AssetMarket aMkt, Currency ccy)
 {
     if (_TotalCcy != ccy)
     {
         _TotalCcy = ccy;
         RefreshTotal(mkt, aMkt, ccy);
     }
 }
Пример #11
0
 internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket)
 {
     _TotalAmount = 0;
     foreach (Account item in Accounts)
     {
         item.RefreshTotalAmount(fXMarket, assetMarket);
         _TotalAmount += item.TotalAmount;
     }
 }
Пример #12
0
        public void TotalAccount_CcyTest()
        {
            Account     acc    = Init.CreateAccountCurrency1();
            FXMarket    FXMkt  = Init.CreateFXMarket();
            AssetMarket aMkt   = Init.CreateAssetMarket();
            IAccount    totAcc = acc.GetTotalAccount(FXMkt, aMkt, acc.Ccy);

            Assert.IsTrue(totAcc.Equals(acc));
        }
Пример #13
0
 public void RefreshTotal(FXMarket fxMkt, AssetMarket aMkt, Currency ccy)
 {
     _TotalAmount = 0;
     foreach (Account acc in Accounts)
     {
         acc.ModifyTotalCcy(fxMkt, aMkt, ccy);
         _TotalAmount += acc.TotalAmount;
     }
 }
Пример #14
0
 public void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket)
 {
     _TotalValue = 0;
     foreach (Category item in Categories)
     {
         item.RefreshTotalAmount(fXMarket, assetMarket);
         _TotalValue += item.TotalAmount;
     }
 }
Пример #15
0
        public void ModifyAmount_CcyTest()
        {
            Account     acc   = Init.CreateAccountCurrency1();
            FXMarket    FXMkt = Init.CreateFXMarket();
            AssetMarket aMkt  = Init.CreateAssetMarket();

            acc.ModifyAmount(FXMkt, aMkt, "TEST", "10,000");
            Assert.IsTrue(acc.Amount == 10000);
        }
Пример #16
0
        public void TotalAccount_AssetTest()
        {
            Account     acc    = Init.CreateAccountAsset1();
            FXMarket    FXMkt  = Init.CreateFXMarket();
            AssetMarket aMkt   = Init.CreateAssetMarket(FXMkt);
            IAccount    totAcc = acc.GetTotalAccount(FXMkt, aMkt, FXMkt.CcyRef);

            Assert.IsTrue(totAcc.Equals(acc));
        }
Пример #17
0
 internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket)
 {
     _TotalAmount = 0;
     foreach (Institution item in Institutions)
     {
         item.RefreshTotalAmount(fXMarket, assetMarket);
         _TotalAmount += item.TotalAmount;
     }
 }
Пример #18
0
 public AccountingData(SerializationInfo info, StreamingContext context)
 {
     _Ccy = (Currency)info.GetValue("Currency", typeof(Currency));
     //_CcyDB = (CurrencyAssetStaticsDataBase)info.GetValue("CcyDB", typeof(CurrencyAssetStaticsDataBase));
     _Data        = (List <Category>)info.GetValue("Categories", typeof(List <Category>));
     _FXMarket    = (FXMarket)info.GetValue("FXMarket", typeof(FXMarket));
     _AssetMarket = (AssetMarket)info.GetValue("AssetMarket", typeof(AssetMarket));
     //_Map = (TreeViewMapping)info.GetValue("Map", typeof(TreeViewMapping));
     _Map = new TreeViewMapping(_Data);
 }
Пример #19
0
        internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket)
        {
            IMarket iMkt = fXMarket;

            if (!Ccy.IsCcy())
            {
                iMkt = assetMarket;
            }
            _TotalAmount = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_TotalCcy));
        }
Пример #20
0
        public void ModifyAmount(FXMarket mkt, AssetMarket aMkt, string accountName, object value)
        {
            Account acc = GetAccount(accountName);

            acc.ModifyAmount(mkt, aMkt, "", value);
            RefreshTotal(mkt, aMkt, _TotalCcy);
            ModifyAmountEventArgs e = new ModifyAmountEventArgs();

            ModifyAmountEventHandler?.Invoke(this, e);
        }
Пример #21
0
 internal void PrepareForLoading(Currency ccy, FXMarket fXMarket, AssetMarket assetMarket)
 {
     _TotalCcy    = ccy;
     _TotalAmount = 0;
     foreach (Account item in Accounts)
     {
         item.ModifyTotalCcy(fXMarket, assetMarket, ccy);
         _TotalAmount += item.TotalAmount;
     }
 }
Пример #22
0
 public AccountingData(CurrencyAssetStaticsDataBase ccyDB)
 {
     _CcyDB       = ccyDB;
     _Ccy         = ccyDB.RefCcy;
     _Data        = new List <Category> {
     };
     _FXMarket    = new FXMarket(Ccy);
     _AssetMarket = new AssetMarket();
     AddNewCategory();
     _Map = new TreeViewMapping(_Data);
 }
Пример #23
0
        internal void RecalculateConvertedAmount(Currency ccy, FXMarket mkt, AssetMarket aMkt)
        {
            _ConvertedCcy = ccy;
            IMarket iMkt = mkt;

            if (!_Ccy.IsCcy())
            {
                iMkt = aMkt;
            }
            _ConvertedAmount = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_ConvertedCcy));
        }
Пример #24
0
 internal void PrepareForLoading(Currency ccy, FXMarket fXMarket, AssetMarket assetMarket)
 {
     _TotalCcy    = ccy;
     _TotalAmount = 0;
     foreach (Institution item in Institutions)
     {
         item.PrepareForLoading(_TotalCcy, fXMarket, assetMarket);
         item.ModifyAmountEventHandler += this.UpdateTotalAmount;
         _TotalAmount += item.TotalAmount;
     }
 }
Пример #25
0
 public void RecalculateAmount(Account acc, FXMarket mkt, AssetMarket aMkt, bool forceRecalc = true)
 {
     if (acc.Ccy.IsCcy())
     {
         acc.RecalculateAmount(mkt, Ccy, forceRecalc);
     }
     else
     {
         acc.RecalculateAmount(aMkt, Ccy, forceRecalc);
     }
 }
Пример #26
0
        public void GetTotalAmount()
        {
            Account     acc   = Init.CreateAccountCurrency1();
            FXMarket    fxMkt = Init.CreateFXMarket();
            AssetMarket aMkt  = Init.CreateAssetMarket();

            acc.ModifyTotalCcy(fxMkt, aMkt, Init.Ccy2());
            double tot = acc.GetTotalAmount(Init.Ccy1(), fxMkt);

            Assert.IsTrue(tot == acc.Amount);
        }
Пример #27
0
 public double GetQuote(ICcyAsset item, Currency ccy)
 {
     if (item.IsCcy())
     {
         return(FXMarket.GetQuote(new CurrencyPair(item.Ccy, ccy)));
     }
     else
     {
         return(AssetMarket.GetQuote(new AssetCcyPair(item.Asset, Ccy)));
     }
 }
Пример #28
0
        public void ModifyAmount(FXMarket mkt, AssetMarket aMkt, string v, object valueAmount)
        {
            _Amount = Convert.ToDouble(valueAmount);
            IMarket iMkt = mkt;

            if (!_Ccy.IsCcy())
            {
                iMkt = aMkt;
            }
            _ConvertedAmount = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_ConvertedCcy));
            _TotalAmount     = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_TotalCcy));
        }
Пример #29
0
        public static AssetMarket CreateAssetMarket(FXMarket populate_fx = null)
        {
            AssetMarket aMkt = new AssetMarket();

            aMkt.AddQuote(new AssetCcyPair(Asset3(), Ccy1()), 48.5);
            aMkt.AddQuote(new AssetCcyPair(Asset1(), Ccy1()), 15000.0);
            if (populate_fx != null)
            {
                aMkt.PopulateWithFXMarket(populate_fx);
            }
            return(aMkt);
        }
Пример #30
0
        public void ModifyCcy(FXMarket mkt, AssetMarket aMkt, string v, ICcyAsset valueCcy, bool isLastRow)
        {
            _Ccy = valueCcy;
            IMarket iMkt = mkt;

            if (!_Ccy.IsCcy())
            {
                iMkt = aMkt;
            }
            _ConvertedAmount = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_ConvertedCcy));
            _TotalAmount     = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_TotalCcy));
        }