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; })); }
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)); }
public void ModifyCcy(FXMarket mkt, AssetMarket aMkt, string v, ICcyAsset valueCcy, bool isLastRow) { if (isLastRow) { _Ccy = valueCcy.Ccy; } }
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); } }
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); })); }
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); }
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(); }
public AccountingData(List <Category> input, FXMarket mkt, AssetMarket aMkt) { _Ccy = new Currency("USD"); _Data = input; _FXMarket = mkt; _AssetMarket = aMkt; _Map = new TreeViewMapping(_Data); }
public void ModifyTotalCcy(FXMarket mkt, AssetMarket aMkt, Currency ccy) { if (_TotalCcy != ccy) { _TotalCcy = ccy; RefreshTotal(mkt, aMkt, ccy); } }
internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket) { _TotalAmount = 0; foreach (Account item in Accounts) { item.RefreshTotalAmount(fXMarket, assetMarket); _TotalAmount += item.TotalAmount; } }
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)); }
public void RefreshTotal(FXMarket fxMkt, AssetMarket aMkt, Currency ccy) { _TotalAmount = 0; foreach (Account acc in Accounts) { acc.ModifyTotalCcy(fxMkt, aMkt, ccy); _TotalAmount += acc.TotalAmount; } }
public void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket) { _TotalValue = 0; foreach (Category item in Categories) { item.RefreshTotalAmount(fXMarket, assetMarket); _TotalValue += item.TotalAmount; } }
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); }
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)); }
internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket) { _TotalAmount = 0; foreach (Institution item in Institutions) { item.RefreshTotalAmount(fXMarket, assetMarket); _TotalAmount += item.TotalAmount; } }
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); }
internal void RefreshTotalAmount(FXMarket fXMarket, AssetMarket assetMarket) { IMarket iMkt = fXMarket; if (!Ccy.IsCcy()) { iMkt = assetMarket; } _TotalAmount = _Amount * iMkt.GetQuote(_Ccy.CreateMarketInput(_TotalCcy)); }
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); }
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; } }
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); }
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)); }
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; } }
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); } }
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); }
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))); } }
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)); }
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); }
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)); }