//We test that the price method of the Pricer Class we have to implement //is working well. It is the answer to the question 4. public void TestThePriceMethodOfPricerClass() { IPricer pricer = new Pricer(); Shape square = new Square("Square1", 12); Assert.AreEqual(24, pricer.Price(square.Area)); }
public void DivSlopingZero() { DivList mydiv = new DivList(); mydiv.divpoints = 1; mydiv.makeArrays(); mydiv.set_d(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.ratepoints = 2; myZero.makeArrays(); myZero.set_r(0, 0.075, 0.5); myZero.set_r(1, 0.05, 2); //create the tree DiscreteTree myTree = new DiscreteTree(); myTree.Gridsteps = 100; myTree.tau = 1.0; myTree.sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.Greater(prc, 10.37); //Orc pr = 10.38 Assert.Less(prc, 10.39); Assert.Greater(prp, 9.42); //Orc pr = 9.43 Assert.Less(prp, 9.44); }
public void ADivSlopingZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 2; myZero.MakeArrays(); myZero.SetR(0, 0.075, 0.5); myZero.SetR(1, 0.05, 2); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 10.37); //Orc pr = 10.38 Assert.IsTrue(prc < 10.39); Assert.IsTrue(prp > 9.42); //Orc pr = 9.43 Assert.IsTrue(prp < 9.44); }
public void NoDivFlatZero() { DivList mydiv = new DivList(); mydiv.divpoints = 1; mydiv.makeArrays(); mydiv.set_d(0, 0.0, 1.0); ZeroCurve myZero = new ZeroCurve(); myZero.ratepoints = 1; myZero.makeArrays(); myZero.set_r(0, 0.05, 1.0); //create the tree DiscreteTree myTree = new DiscreteTree(); myTree.Gridsteps = 100; myTree.tau = 1.0; myTree.sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.Greater(prc, 12.33); //Orc pr = 12.34 Assert.Less(prc, 12.35); Assert.Greater(prp, 7.98); //Orc pr = 7.99 Assert.Less(prp, 8.00); }
public void EDivFlatZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 1; myZero.MakeArrays(); myZero.SetR(0, 0.05, 1.0); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "e"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 9.455); //BS pr = 9.46277 Assert.IsTrue(prc < 9.475); Assert.IsTrue(prp > 9.462); //BS pr = 9.46226 Assert.IsTrue(prp < 9.475); }
public void ANoDivFlatZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 0.0, 1.0); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 1; myZero.MakeArrays(); myZero.SetR(0, 0.05, 1.0); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 12.33); //Orc pr = 12.34 Assert.IsTrue(prc < 12.35); Assert.IsTrue(prp > 7.98); //Orc pr = 7.99 Assert.IsTrue(prp < 8.00); }
public void DivFlatZero() { DivList mydiv = new DivList(); mydiv.divpoints = 1; mydiv.makeArrays(); mydiv.set_d(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.ratepoints = 1; myZero.makeArrays(); myZero.set_r(0, 0.05, 1.0); //create the tree DiscreteTree myTree = new DiscreteTree(); myTree.Gridsteps = 100; myTree.tau = 1.0; myTree.sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "e"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.Greater(prc, 9.455); //BS pr = 9.46277 Assert.Less(prc, 9.475); Assert.Greater(prp, 9.462); //BS pr = 9.46226 Assert.Less(prp, 9.475); }
public override CompletePricingResults getPricingResults(List <DataFeed> pricingData) { double[,] underlyingSpots = ConvertDecimalArray.listDataFeedToDoubleArray(pricingData); double[] volatility = StatComputing.volatilitiesComputing(underlyingSpots); Pricer pricer = new Pricer(); double spot = underlyingSpots[underlyingSpots.GetLength(0) - 1, 0]; PricingResults pricingResults = pricer.Price((VanillaCall)opt, pricingData.Last().Date, 365, spot, volatility.First()); CompletePricingResults completePricingResults = new CompletePricingResults(pricingResults, new double[] { spot }); return(completePricingResults); }
public ViewModel() { _instrumentRepository = new MyInstrumentRepository(); _instrumentRepository.Init(50); Instruments = new ObservableCollection <InstrumentViewModel>( _instrumentRepository.GetInstruments().Select(instrument => new InstrumentViewModel(instrument))); _pricer = new Pricer(_instrumentRepository, 1); StartCommand = new RelayCommand(o => { _pricer.Price(); }, o => true); StopCommand = new RelayCommand(o => { _pricer.StopPrice(); }, o => true); RestartCommand = new RelayCommand(o => { _pricer.Restart(); }, o => true); }
public void TestPrice() { _repository = Substitute.For <IInstrumentRepository>(); _repository.GetInstruments() .Returns(new List <Instrument> { new Instrument("Toto", InstrumentType.Bond) }); _pricer = new Pricer(_repository, 500); _pricer.Price(); Thread.Sleep(800); _repository.Received(1).PriceUpdate("Toto", Arg.Any <double>()); }
// Valeur de référence obtenue depuis : http://www.danielsoper.com/fincalc/calc.aspx?id=37 [TestMethod] public void TestPricer() { // Le test était en erreur à cause de deux problèmes : // Le premier est juste une erreur de saisie, le prix de // référence (12.8405) correspond à une maturité de 90 jours = 0.246 année // c'est corrigé en utilisant la bonne maturité dans le test // Le deuxième venait de la loi normale. On a utilisé involontairement // la même loi uniforme deux fois (u1=u2), pour plus de détails, voir // les commentaires de la classe UniformGenerator Pricer pricer = new Pricer(); CallPayoff payoff = new CallPayoff("s", 0.246, 95); BSSimulator simulator = new BSSimulator(); double price = pricer.Price(payoff, simulator, 10e5); Assert.AreEqual(12.8405, price, 0.1); }
public override CompletePricingResults getPricingResults(List <DataFeed> pricingData) { double[,] underlyingSpots = ConvertDecimalArray.listDataFeedToDoubleArray(pricingData); double[,] myCorrelationMatrix = StatComputing.correlationMatrix(underlyingSpots); double[] volatility = StatComputing.volatilitiesComputing(underlyingSpots); Pricer pricer = new Pricer(); int nShares = underlyingSpots.GetLength(1); double[] spots = new double[nShares]; for (int i = 0; i < nShares; i++) { spots[i] = underlyingSpots[nShares - 1, i]; } PricingResults pricingResults = pricer.Price((BasketOption)opt, pricingData.Last().Date, 365, spots, volatility, myCorrelationMatrix);; CompletePricingResults completePricingResults = new CompletePricingResults(pricingResults, spots); return(completePricingResults); }
public void GetItemDisplayListTest_WithPricer() { var collection = new List <Item> { new Item { Type = "Cercle", Name = "Nom1", Superficy = 12 }, new Item { Type = "Cercle", Name = "Nom2", Superficy = 15 }, new Item { Type = "Triangle", Name = "Nom3", Superficy = 16 } }; var displayService = new DisplayService(); IPricer pricer = new Pricer(); var i = 0; foreach (var itemDisplay in displayService.GetItemDisplayList(collection, pricer)) { var item = collection[i]; Assert.AreEqual($"{item.Type} - {item.Name} - {item.Superficy} cm² - Estimation cout : {pricer.Price(item.Superficy)}{DisplayService.Euro}", itemDisplay); i++; } pricer = new OtherPricer(); i = 0; foreach (var itemDisplay in displayService.GetItemDisplayList(collection, pricer)) { var item = collection[i]; Assert.AreEqual($"{item.Type} - {item.Name} - {item.Superficy} cm² - Estimation cout : {pricer.Price(item.Superficy)}{DisplayService.Euro}", itemDisplay); i++; } }
private void Start(object sender, EventArgs e) { _pricer.Price(); dataGridView1.DataSource = _instruments; }
public Rental(string imdbId, string member) { ImdbID = imdbId; Member = member; _movie = Pricer.Price(imdbId); }
static int Main(string[] args) { string inputFilePath = null; var culture = Thread.CurrentThread.CurrentCulture; #if DEBUG Console.Write("Input file path: "); inputFilePath = Console.ReadLine(); Console.Write("Culture (leave blank for system default): "); var cultureInput = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(cultureInput)) { culture = new CultureInfo(cultureInput); } #else for (var offset = 0; offset < args.Length; offset += 2) { switch (args[offset]) { case "-l": case "--culture": culture = new CultureInfo(args[offset + 1]); break; case "-i": case "--input": inputFilePath = args[offset + 1]; break; default: Console.WriteLine($"'{args[offset]}' is not a known switch, supported values are: '-l', '--culture', '-i', '--input'"); break; } } #endif if (string.IsNullOrWhiteSpace(inputFilePath)) { Console.WriteLine("The input file path is required: -i <file-path>"); return(-1); } if (inputFilePath.StartsWith('"')) { inputFilePath = inputFilePath.Replace("\"", ""); } var inputFile = new FileInfo(inputFilePath); if (!inputFile.Exists) { Console.WriteLine($"The file '{inputFile.FullName}' is not accessible"); return(-1); } if (!".csv".Equals(inputFile.Extension, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine($"The file '{inputFile.FullName}' doesn't have a '.csv' extension"); return(-1); } var inputVms = new InputVmParser().Parse(inputFile, culture); var pricer = new Pricer(PricingDirectory); pricer.EnsurePricingExists(inputVms); var pricings = new VmPricingParser(PricingDirectory).Parse(); var pricedVms = pricer.Price(inputVms, pricings); new PricedVmWriter().Write(inputFile.Name, pricedVms, culture); return(0); }