示例#1
0
        public void TestAnnuity()
        {
            // single payment upfront, get FV.
            var    n        = 6;
            double notional = 10e7;
            double r        = 0.092;
            var    t1       = TimeValues.ComputeFutureValueOfOneTimeInvestment(notional, n, r);

            // same but paying semiannually
            var m  = 2;
            var t2 = TimeValues.ComputeFutureValueOfOneTimeInvestment(notional, n, m, r);

            // FV of annuity
            var pmt = 2 * 10e6;

            r = 0.08;
            n = 15;
            var t3 = TimeValues.ComputeFutureValueOfCashFlows(pmt, n, r);

            // PV of annuity
            var fv = 5 * 10e6;

            r = 0.1;
            n = 7;
            var t4 = TimeValues.ComputePresentValue(fv, n, r);

            // PV of CFs
            var pmts = new List <double> {
                100, 100, 100, 100, 1100
            };

            r = .0625;
            var t5 = TimeValues.ComputePresentValueOfCashFlows(pmts, r);

            pmt = 100;
            r   = .09;
            n   = 8;
            var t6 = TimeValues.ComputePresentValueOfCashFlows(100, n, r);

            var couponRate = 0.05;
            var faceValue  = 1000;
            var years      = 20;

            r = .11;
            m = 2;
            var bond = new Bond(faceValue, years, m, couponRate);

            BondPricer.Compute(bond, r);
            var t7 = bond.FairPrice;
        }
示例#2
0
    public static void BondSample()
    {
        // Create Bond
        Console.Write("Create a specific bond..");
        Bond myBond = CreateMyBond();

        Console.WriteLine("Bond created!");

        // Inizialize a bond price
        Console.Write("Create a specific bond pricer...");
        Date       td       = new Date(2011, 02, 8);
        BondPricer myPricer = new BondPricer(myBond, td);

        Console.WriteLine("BondPricer created!");
        Console.WriteLine();

        Console.WriteLine("Calculate Dirty Price from Clean Price");
        double cleanPrice = 99;

        Console.WriteLine("CleanPrice {0} DirtyPrice {1}", cleanPrice, myPricer.DirtyPrice(cleanPrice));
        Console.WriteLine();

        // Parameters to calculate yield, can be modified
        int         freq = 1;
        Dc          dc   = Dc._30_360;
        Compounding c    = Compounding.Compounded;

        Console.WriteLine("Parameters used for yield: freq {1}, DayCount {2}, Compounding", freq, dc.ToString(), c.ToString());
        Console.WriteLine("Calculate Clean Price From Yield");
        double yield = 0.05;

        Console.WriteLine("given a yield% of {0},  the clean price is: {1}", yield, myPricer.CleanPriceFromYield(yield, 1, dc, c));
        Console.WriteLine();

        Console.WriteLine("Calculate Yield From Clean Price");
        double cleanpx = 99.05;

        Console.WriteLine("given a clean price of {0},  the yield is: {1}", cleanpx, myPricer.YieldFromCleanPrice(cleanpx, 1, dc, c));

        Console.WriteLine();
        Console.WriteLine("Accrued Interest is");
        Console.WriteLine(myPricer.AccruedInterest());
    }
示例#3
0
        public static List <Tuple <Bond, int> > GreedyStrategy(List <Bond> bonds, BondPricer calculator)
        {
            var sortedBonds = new List <Bond>(bonds);

            sortedBonds.Sort(timeComparison);
            foreach (var bond in sortedBonds)
            {
                if (calculator.Local.EstimedTime(bond) <= calculator.Grid.EstimedTime(bond))
                {
                    calculator.Local.Send(bond);
                }
                else
                {
                    calculator.Grid.Send(bond);
                }
            }

            var task = calculator.Compute();

            task.Wait();
            return(bonds.Select(bond => Tuple.Create(bond, bond.Price())).ToList());
        }
示例#4
0
        static void Main(string[] args)
        {
            var b1 = new Bond(BondType.Fast);
            var b2 = new Bond(BondType.Long);
            var b3 = new Bond(BondType.SemiFast);

            var bonds = new List <Bond> {
                b1, b2, b3
            };

            var local = new NodePricer();
            var grid  = new GridPricer();

            var calculator = new BondPricer(local, grid);

            b1.ResultComputed += (obj, e) => { Console.WriteLine("Price available for : " + obj.ToString()); };

            var result = PricingStratey.GreedyStrategy(bonds, calculator);

            // shoud be equal 13
            Console.WriteLine(calculator.ComputingTime);
        }
 static public Quote SaveAndLoadQuote(Trade trade, Market market, SimpleDate date, double mp, IList<Exception> exceptions)
 {            
     if (market == null) return null;
     var setup = market.Setup;
     if (setup == null) return null;
     IList<Trade> trades = new List<Trade>();
     Quote theQuote = null;
     trades.Add(trade);
     var time = new DateTime(date.Year, date.Month, date.Day);
     market.Time = time;
     //TradeBlotter.Check(null, trades, market, time, true, false, false, false, null, false);
     var mnames = new List<string> { Measure.Pv };
     var optional = new Set<QuoteId>();
     var quotes = new Set<QuoteId>();
     var toSave = new List<Quote>();
     try 
     {                
         IPricer pricer = setup.Pricer(trade.Product);
         if (pricer == null) return null;
         pricer.Quotes(trade, time, market, pricer.MakeMeasures(mnames), quotes, optional);
         var bond = trade.Product as Bond;
         if (bond != null && bond.IsIlliquid)
         {
             var q = new BondPricer().FindQuote(bond, bond.QuoteName.Name, market, date);
             if (q != null) quotes.Add(q.QuoteId);
         }
         foreach (QuoteId qId in quotes)
         {
             var q = new Quote(setup.ClosingName, qId.Name, date, mp, mp, trade.PriceType);
             toSave.Add(q);
             theQuote = q;
             break;
         }
         Env.Current.MarketData.SaveQuotes(toSave);
         return theQuote;
     }
     catch (Exception x)
     {
         exceptions.Add(x);
         return null;
     }
     
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datastore"></param>
        /// <param name="keys">les parametres utilisés dans la requete</param>
        /// <param name="values"></param>
        /// <param name="superParamKey">mot cle utilise dans les parametres de nom de fichiers etc...</param>
        /// <param name="superParamValue">la valeur du mot cle</param>
        private void output(string datastore, string[] keys = null, string[] values        = null,
                            string superParamKey            = null, string superParamValue = null)
        {
            BP2SText bp2stext = null;
            string   sql      = CommandLine["sql"];
            DataSet  DS       = new DataSet();

            // fichier de la requete SQL utilisée pour extraire les données
            if (sql != null)
            {
                // formater les paramètres:
                SQLrequest p = null;
                try
                {
                    // tester si il y a des pararametres personnalise
                    if (keys != null && keys.Length > 0)
                    {
                        IntegratorBatch.InfoLogger.Debug("Lecture d une requete avec parametres : " + keys);
                        p = new SQLrequest(sql, datastore, keys, values);
                    }
                    else
                    {
                        p = new SQLrequest(sql, datastore);
                    }
                    p.Execute(out DS);
                }
                catch (Exception e)
                {
                    IntegratorBatch.ExceptionLogger.Fatal("Impossible d executer la requete " + sql, e);
                    throw e;
                }
            }
            else
            {
                Console.WriteLine(usage());
                IntegratorBatch.ExceptionLogger.Fatal("Parametre obligatoire -sql inexistant");
                // sortie car aucune requete à jouer
                return;
            }
            //------------------------------------------------------------------------------------------

            // declencher un calcul de BondPricer
            string bondPricer = CommandLine["bondPricer"];

            if (bondPricer != null)
            {
                BondPricer.OPTION opt;
                switch (bondPricer)
                {
                case "DURATION": opt = BondPricer.OPTION.DURATION; break;

                case "ACCRUEDINTEREST": opt = BondPricer.OPTION.ACCRUEDINTEREST; break;

                case "CLEANPRICE": opt = BondPricer.OPTION.CLEANPRICE; break;

                case "DIRTYPRICE": opt = BondPricer.OPTION.DIRTYPRICE; break;

                default: opt = BondPricer.OPTION.ALL; break;
                }

                BondPricer bp = new BondPricer();
                DS = bp.Execute(DS, opt);
            }

            //------------------------------------------------------------------------------------------
            if (CommandLine["bp2s"] != null)
            {
                bp2stext = new BP2SText();
                string bp2sValid = (CommandLine["bp2sregex"] == null ? @"Resources/Consumer/BP2StextValidation.txt" : CommandLine["bp2sregex"]);
                IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de validation des champs (regex) " + bp2sValid);

                string bp2s = CommandLine["bp2s"];
                bp2stext.ValidationPath = bp2sValid;

                IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie BP2S " + bp2s);
                bp2s = bp2s.Replace("YYYYMMDD", now.ToString("yyyyMMdd"));
                // remplacer le mot cle par sa valeur
                if (superParamKey != null)
                {
                    bp2s = bp2s.Replace(superParamKey, superParamValue);
                }

                bp2stext.CreateFile(DS, bp2s, now);
            }

            //------------------------------------------------------------------------------------------
            string excel = CommandLine["xls"];

            if (excel != null)
            {
                excel = excel.Replace("YYYYMMDD", now.ToString("yyyyMMdd"));
                // remplacer le mot cle par sa valeur
                if (superParamKey != null)
                {
                    excel = excel.Replace(superParamKey, superParamValue);
                }

                IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie Excel " + excel);

                ExcelFile.CreateWorkbook(DS, excel);
            }
            //------------------------------------------------------------------------------------------
            string openXMLExcel = CommandLine["oxlsx"];

            if (openXMLExcel != null)
            {
                openXMLExcel = openXMLExcel.Replace("YYYYMMDD", now.ToString("yyyyMMdd"));
                // remplacer le mot cle par sa valeur
                if (superParamKey != null)
                {
                    openXMLExcel = openXMLExcel.Replace(superParamKey, superParamValue);
                }

                IntegratorBatch.InfoLogger.Debug("Configuration pour une sortie Open XML Excel " + openXMLExcel);

                // tester si il y a des pararametres personnalise
                string date = CommandLine["#date"] == null?now.ToString("yyyyMMdd") : CommandLine["#date"];

                string sheetNames    = CommandLine["#names"];
                string style         = CommandLine["#style"];
                string template      = CommandLine["#template"];
                string graph         = CommandLine["#graph"];
                bool   monoSheetFlag = ((CommandLine["#monoSheetFlag"] == null || CommandLine["#monoSheetFlag"] == "F" || CommandLine["#monoSheetFlag"] == "N") ? false : true);

                OpenXMLFile.CreateExcelWorkbook(DS, openXMLExcel, style, template, graph, date, sheetNames.Split(';'), monoSheetFlag);
            }
            //------------------------------------------------------------------------------------------
            string csv = CommandLine["csv"];

            if (csv != null)
            {
                string fileNames = CommandLine["#names"];
                if (fileNames != null)
                {
                    fileNames = fileNames.Replace("YYYYMMDD", now.ToString("yyyyMMdd"));
                }
                else
                {
                    fileNames = "";
                }
                // remplacer le mot cle par sa valeur
                if (superParamKey != null)
                {
                    fileNames = fileNames.Replace(superParamKey, superParamValue);
                }

                CSVFile.WriteToCSV(DS, csv, fileNames);
            }
            //------------------------------------------------------------------------------------------
            //Si include et exclude sont vide : copie la BDD en entier
            //Si include et exclude non vide : aucune table ne sera copiée
            //Si include est vide : copie tout sauf les tables comprises dans exclude
            //Si exclude est vide : copie uniquement les tables dans include
            string bdd = CommandLine["dbCopy"];

            if (bdd != null)
            {
                MSDBIntegration.InfoLogger      = IntegratorBatch.InfoLogger;
                MSDBIntegration.ExceptionLogger = IntegratorBatch.ExceptionLogger;

                string connection1 = CommandLine["#connectionSource"];
                string connection2 = CommandLine["#connectionDest"];
                // une seule liste autorisée
                List <string> liste = null;
                ListeMode     mode;
                if (CommandLine["#include"] != null)
                {
                    liste = CommandLine["#include"].Split(';').ToList();
                    mode  = ListeMode.Include;
                }
                else if (CommandLine["#include"] != null)
                {
                    liste = CommandLine["#exclude"].Split(';').ToList();
                    mode  = ListeMode.Exclude;
                }
                else
                {
                    mode = ListeMode.Aucune;
                }

                List <string> nomTable = null;
                // si il y a une option -sql , le resultat de la requete sera mis dans la ou les tables nommées nomtable
                if (sql != null)
                {
                    nomTable = CommandLine["#nomTable"].Split(';').ToList();
                    DBCopy.DataBaseCopy(connection1, connection2, DS, nomTable);
                }
                else
                {
                    //TODO
                }
            }

            //------------------------------------------------------------------------------------------
        }