private Tranche getTranchesInfo(int rowNumber)
        {
            Tranche tranche     = new Tranche();
            string  trancheName = this.getCellText(rowNumber, this.trancheColumn);

            // filter if cell is blank;
            if (String.IsNullOrEmpty(trancheName))
            {
                return(null);
            }
            tranche.trancheName = trancheName;
            int[] trancheMinMax = this.getTranchesMinMax(tranche.trancheName);
            if (trancheMinMax.Count() == 2)
            {
                tranche.trancheMin = trancheMinMax[0];
                tranche.trancheMax = trancheMinMax[1];
            }
            else if (trancheMinMax.Count() == 1)
            {
                tranche.trancheMin = trancheMinMax[0];
            }
            tranche.nbFoyers           = this.getCellNumber(rowNumber, this.nbFoyersColumn);
            tranche.revenus            = this.getCellNumber(rowNumber, this.revFoyersColumn);
            tranche.impot              = this.getCellNumber(rowNumber, this.impotColumn);
            tranche.nbFoyersImposables = this.getCellNumber(rowNumber, this.nbFoyersImposColumn);
            tranche.revenusImposables  = this.getCellNumber(rowNumber, this.revFoyersImposColumn);
            tranche.nbFoyers_salaires  = this.getCellNumber(rowNumber, this.salairesColumn);
            tranche.revenus_salaires   = this.getCellNumber(rowNumber, this.salairesColumn + 1);
            tranche.nbFoyers_retraites = this.getCellNumber(rowNumber, this.retraitesColumns);
            tranche.revenus_retraites  = this.getCellNumber(rowNumber, this.retraitesColumns + 1);

            return(tranche);
        }
        //-------------------------Train Hors Périmètre-----------------------------//

        public List<Tranche> TanchesTrainHorsPerimetre()
        {
            donneesFichierExcel = new DonneesFichierExcelView(_filePath);

            int j = 0;
            int i = 0;

                while (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i].Cells[j + 5].Value.ToString() != string.Empty)
                    {
                        TTranche = new Tranche();

                        TTranche.Num_Train = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i].Cells[j]).Value.ToString();
                        TTranche.Type_Train = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i].Cells[j + 1]).Value.ToString();

                        TTranche.Gare_Depart = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i].Cells[j + 3]).Value.ToString();
                        TTranche.Heure_Depart = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i].Cells[j + 5]).Value.ToString();
                        TTranche.Gare_Arrivee = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i + 1].Cells[j + 3]).Value.ToString();
                        TTranche.Heure_Arrivee = (donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i + 1].Cells[j + 4]).Value.ToString();

                        if (((donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows[i + 1].Cells[j + 5])).Value.ToString() == string.Empty && donneesFichierExcel.GetDataGridViewTrainHorsPerimetre().Rows.Count - 5 > i)
                        {
                            i = i + 2;
                        }
                        else
                        {
                            i = i + 1;
                        }

                        TGare.Add(TTranche);                     
                    }

                return TGare;//.OrderBy(u => u.Heure_Depart).Distinct().ToList();
        }
        public static Tranche ReadConditionFromFile(string fileName)
        {
            Tranche tranche;

            using (var br = new BinaryReader(File.OpenRead(fileName + ".txt")))
            {
                decimal      capital = br.ReadDecimal();
                int          period  = br.ReadInt32();
                int          length  = br.ReadInt32();
                List <Asset> assets  = new List <Asset>();
                for (int i = 0; i < length; i++)
                {
                    assets.Add(
                        new Asset(
                            br.ReadDecimal(),
                            br.ReadDecimal()
                            )
                        );
                }

                tranche = new Tranche(capital, period, assets);
            }

            return(tranche);
        }
Example #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                Tranche tranche = readTranche();

                InvestmentPlan plan = DesktopLogic.planFromThread(tranche);

                //var plan = tranche.assets[0].profit.ToString() + " " + tranche.assets[0].prob.ToString();

                this.answerBox.Text = plan.GetFinalProfit().ToString(ci);

                this.answerGridView.Rows.Clear();
                foreach (var x in plan.Plan)
                {
                    this.answerGridView.Rows.Add(x.Item1.ToString(ci), x.Item2.ToString());
                }
                setRowNumber(this.answerGridView);
                this.answerGridView.Visible = true;

                this.answerBox.TabStop       = false;
                this.tabControl1.SelectedTab = this.tabPage2;
                this.tabPage2.Visible        = true;
            }
            catch (Exception ex)
            {
            }
        }
Example #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            MouseEventArgs eventargs = e as MouseEventArgs;
            Button         button1   = sender as Button;


            string filename = filenameBox.Text;

            if (filename != "")
            {
                Tranche tranche = ReadWriteTools.ReadConditionFromTextFile(filename);


                capitalTextBox.Text = tranche.capital.ToString(ci);
                periodTextBox.Text  = tranche.period.ToString(ci);

                assetsGrid.Rows.Clear();
                foreach (var asset in tranche.assets)
                {
                    assetsGrid.Rows.Add(/*this.assetsGrid.Rows.Count,*/ asset.profit.ToString(ci), asset.prob.ToString(ci));
                }
                setRowNumber(this.assetsGrid);
                assetsGrid.Visible = true;
            }
        }
        public static Tranche trancheFromForm(Form1 form1)
        {
            Tranche tranche = new Tranche();



            return(tranche);
        }
        public static void f()
        {
            Tranche tranche = ReadWriteTools.MakeSimpleTranche();

            ReadWriteTools.WriteConditionToTextFile("another_sample.txt", tranche);

            Tranche t = ReadWriteTools.ReadConditionFromTextFile("another_sample.txt");

            ReadWriteTools.WriteConditionToTextFile("just_sample.txt", t);
        }
Example #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            MouseEventArgs eventargs = e as MouseEventArgs;
            Button         button1   = sender as Button;

            // displays which mouse button I used
            //MessageBox.Show(eventargs.Button.ToString());
            // displays the name of the button I clicked
            //MessageBox.Show(button1.Name.ToString());
            // changes the text of the button
            //if (button1.Text == "I've changed")
            //{
            //    button1.Text = "Hey, I'm old right now!";
            //} else
            //button1.Text = "I've changed";

            try
            {
                Tranche tranche = readTranche();

                InvestmentPlan plan = EasySolve.solve(tranche);

                //var plan = tranche.assets[0].profit.ToString() + " " + tranche.assets[0].prob.ToString();

                this.answerBox.Text = plan.GetFinalProfit().ToString(ci);


                /*
                 * foreach (var asset in tranche.assets)
                 *  {
                 *      assetsGrid.Rows.Add(
                 * asset.profit.ToString(ci), asset.prob.ToString(ci));
                 * }
                 * assetsGrid.Visible = true;
                 */
                this.answerGridView.Rows.Clear();
                foreach (var x in plan.Plan)
                {
                    this.answerGridView.Rows.Add(x.Item1.ToString(ci), x.Item2.ToString());
                }
                setRowNumber(this.answerGridView);
                this.answerGridView.Visible = true;

                this.answerBox.TabStop       = false;
                this.tabControl1.SelectedTab = this.tabPage2;
                this.tabPage2.Visible        = true;
            }
            catch (Exception ex)
            {
            }
        }
 public static void WriteConditionToFile(string fileName, Tranche tranche)
 {
     using (var bw = new BinaryWriter(File.OpenWrite(fileName + ".txt")))
     {
         bw.Write(tranche.capital);
         bw.Write(tranche.period);
         bw.Write(tranche.assets.Count);
         foreach (Asset asset in tranche.assets)
         {
             bw.Write(asset.profit);
             bw.Write(asset.prob);
         }
     }
 }
        public static InvestmentPlan planFromThread(Tranche tranche)
        {
            object t      = null;
            var    thread = new Thread(
                () =>
            {
                t = EasySolve.solve(tranche);
            }
                );

            thread.Start();
            thread.Join();

            return((InvestmentPlan)t);
        }
Example #11
0
        static void Main(string[] args)
        {
            CultureInfo ci = CultureInfo.CreateSpecificCulture("en-US");

            if (args.Length > 0 && args[0] != "")
            {
                string filename = args[0]; //"another_sample.txt";
                                           //args[0];

                Tranche tranche = ReadWriteTools.ReadConditionFromTextFile(filename);

                InvestmentPlan plan = EasySolve.solve(tranche);

                //Console.WriteLine(answerToString(plan, ci));

                String s = answerToString(plan, ci);//.Split(new char[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries);

                /*foreach (String t in s)
                 * {
                 *  Console.WriteLine(t);
                 * }*/

                //Console.WriteLine(s.Count());

                Console.WriteLine(s);

                /*ReadWriteTools.WriteConditionToFile(
                 *  "sample",
                 *  ReadWriteTools.MakeSimpleTranche()
                 *  );
                 *
                 * Tranche tranche = ReadWriteTools.ReadConditionFromFile("sample");
                 *
                 *
                 * Investor investor = new Investor(tranche.period, tranche.capital, tranche.assets);
                 *
                 * InvestmentsSolver solver = new InvestmentsSolver(investor);
                 *
                 * InvestmentPlan plan = solver.TheoreticalProfitPlan();
                 *
                 * foreach (Tuple<decimal, decimal> x in plan.Plan)
                 * {
                 *  System.Console.WriteLine(x);
                 * }
                 *
                 * System.Console.WriteLine(plan.GetFinalProfit());*/
            }
        }
        /// <summary>
        ///     Generate a new instance of a Fixed Payment Facility.  This instance will need to
        ///     be sent to the API
        /// </summary>
        /// <returns>Facility</returns>
        public static Facility GetSampleFacility()
        {
            // Create Single Draw Rules
            var drawRules = new SingleDrawRules(
                CommitmentAmount,
                OriginationDate,
                "SINGLE_DRAW"
                );

            // Create Interest Rules
            var interestRules = new FixedPaymentInterestRules(
                InterestRate,
                FixedPaymentInterestRules.CompoundingEnum.SIMPLE,
                DayCount,
                60,
                paymentFrequency: FixedPaymentInterestRules.PaymentFrequencyEnum.MONTHLY,
                paymentAmount: FixedPaymentAmount,
                effectiveDate: OriginationDate,
                type: "FIXED_PAYMENT"
                );

            // Create a Single Draw, Fixed Payment Tranche
            var tranche = new Tranche(
                "Tranche A",
                drawRules,
                interestRules
                );

            // Create the Facility Instance
            var res = new Facility(
                Guid.NewGuid().ToString(),
                "America/New_York",
                new List <FacilityInstitutionDto>(),
                new List <Tranche>
            {
                tranche
            },
                new List <Borrowing>()
                );

            // API-Ready Facility instance, this will need to be sent to the API
            return(res);
        }
Example #13
0
        private Tranche readTranche()
        {
            Tranche tranche;// = new Tranche();

            decimal capital = Decimal.Parse(capitalTextBox.Text, ci);
            int     period  = int.Parse(periodTextBox.Text, ci);

            if (period < 1)
            {
                throw new ArgumentException();
            }


            var assets = new List <Asset>();

            for (int i = 0; i < assetsGrid.Rows.Count - 1; i++)
            {
                //var profit = Decimal.Parse(assetsGrid.Rows[i].Cells["Profit"].ToString(), ci);
                //var prob = Decimal.Parse(assetsGrid.Rows[i].Cells["Prob"].ToString(), ci);

                decimal profit = Decimal.Parse(
                    assetsGrid[0, i].Value.ToString(),
                    ci
                    );
                decimal prob = Decimal.Parse(
                    assetsGrid[1, i].Value.ToString(),
                    ci
                    );

                //System.Console.WriteLine(prob);

                assets.Add(new Asset(profit, prob));
            }

            tranche = new Tranche(capital, period, assets);

            return(tranche);
        }
        private Departement getDepartementInfos()
        {
            Departement dep = new Departement();

            // loop over rows until lastTableRow
            List <Tranche> listTranches = new List <Tranche>();

            for (int rowNum = this.depTitlesTableRowNum + 1; rowNum <= this.lastTableRow; rowNum++)
            {
                if (rowNum != this.lastTableRow)
                {
                    Tranche t = this.getTranchesInfo(rowNum);
                    if (t == null)
                    {
                        continue;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(dep.depName))
                        {
                            dep.depName   = this.getCellText(rowNum, this.depColumn).Trim();
                            dep.depNumber = this.getCellText(rowNum, this.depColumn - 2);
                        }
                        listTranches.Add(t);
                    }
                }
                else
                {
                    this.setDepartementTotals(dep, rowNum);
                }
            }

            dep.tranches = listTranches.ToArray();

            return(dep);
        }
Example #15
0
        public LorenzData cumulLorenz()
        {
            LorenzData ldata = new LorenzData();

            // calcul par tranche
            Dictionary <string, List <KeyValuePair <decimal, decimal> > > lorenzCurvesEachYear = new Dictionary <string, List <KeyValuePair <decimal, decimal> > >();

            foreach (Departement dep in everyYearsForCurrentDepartement)
            {
                List <KeyValuePair <decimal, decimal> > lorenzCurve = new List <KeyValuePair <decimal, decimal> >();
                lorenzCurve.Add(new KeyValuePair <decimal, decimal>(new decimal(0), new decimal(0)));
                decimal previousPopulationProp = new Decimal(0);
                decimal previousRevenuProp     = new Decimal(0);


                for (int i = 0; i < dep.tranches.Length; i++)
                {
                    Tranche tranche = dep.tranches[i];
                    if (tranche.revenus != new decimal(-1))
                    {
                        previousRevenuProp     = Math.Round((decimal)tranche.revenus / (decimal)dep.revenus + previousRevenuProp, 5, MidpointRounding.ToEven);
                        previousPopulationProp = Math.Round((decimal)tranche.nbFoyers / (decimal)dep.nbFoyers + previousPopulationProp, 5, MidpointRounding.ToEven);

                        // correction arronds
                        if (Math.Abs(1 - previousPopulationProp) <= new decimal(0.001))
                        {
                            previousPopulationProp = new decimal(1.00001);
                        }
                        if (Math.Abs(1 - previousRevenuProp) <= new decimal(0.001))
                        {
                            previousRevenuProp = new decimal(1.00001);
                        }

                        lorenzCurve.Add(new KeyValuePair <decimal, decimal>(previousPopulationProp, previousRevenuProp));
                    }
                    else
                    {
                        if (i == dep.tranches.Length - 1) // last item : add 1,1
                        {
                            lorenzCurve.Add(new KeyValuePair <decimal, decimal>(new decimal(1), new decimal(1)));
                        }
                    }
                }

                lorenzCurvesEachYear.Add(dep.year.ToString(), lorenzCurve);
            }

            ldata.LorenzTranches = lorenzCurvesEachYear;
            // calcul par interpolation linéaire : 10 deciles

            Dictionary <string, List <KeyValuePair <decimal, decimal> > > lorenzDecilesEachYear = new Dictionary <string, List <KeyValuePair <decimal, decimal> > >();

            foreach (string year in lorenzCurvesEachYear.Keys)
            {
                List <KeyValuePair <decimal, decimal> > lorCurve = lorenzCurvesEachYear[year];

                List <KeyValuePair <decimal, decimal> > lorenzDeciles = new List <KeyValuePair <decimal, decimal> >();
                lorenzDeciles.Add(new KeyValuePair <decimal, decimal>(new decimal(0), new decimal(0)));

                decimal x = new decimal(.05);
                // loop sur les coordonnées d'une année
                // x sera la valeur incrémentée pour l'interpolation, on commence a 5% car

                // y = ax + b
                // a = (y2 - y1) / (x2 - x1)
                // b = y1 - a*x1 = y2 - a*x2
                KeyValuePair <decimal, decimal> previousCoord = new KeyValuePair <decimal, decimal>();
                foreach (KeyValuePair <decimal, decimal> currentCoord in lorCurve)
                {
                    decimal lorenzX = currentCoord.Key * 100;
                    decimal a       = new decimal(0);
                    decimal b       = new decimal(0);

                    if (currentCoord.Key != 0) // previous coord existe : transposition de fonction affine
                    {
                        if (currentCoord.Key - previousCoord.Key != 0)
                        {
                            a = (currentCoord.Value - previousCoord.Value) / (currentCoord.Key - previousCoord.Key);
                            b = currentCoord.Value - a * currentCoord.Key;
                        }
                        //Console.WriteLine("a = " + a + ", b = " + b);
                    }


                    while (x < currentCoord.Key)
                    {
                        decimal y = a * x + b;
                        //Console.WriteLine("x = " + x + ", y = " + y);
                        lorenzDeciles.Add(new KeyValuePair <decimal, decimal>(x, Math.Round(y, 4, MidpointRounding.ToEven)));
                        x += new decimal(0.05);
                    }

                    previousCoord = currentCoord;
                }

                lorenzDecilesEachYear.Add(year, lorenzDeciles);
            }

            ldata.LorenzDeciles = lorenzDecilesEachYear;

            return(ldata);
        }
        //---------------------------Bretagne Job Impair----------------------------//

        public List<Tranche> TanchesBretagneJobImpair()
        {
            donneesFichierExcel = new DonneesFichierExcelView(_filePath);

            int j = 0;

            while (j < (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Columns.Count) - 1)
            {
                int i = 2;
                // Si la premiere cellule contenant l'heure n'est pas vide
                if (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[j + 1].Value.ToString() != string.Empty)
                {
                    while (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[j + 1].Value.ToString() != string.Empty)
                    {

                        TTranche = new Tranche();

                        TTranche.Num_Train = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[0].Cells[j + 1]).Value.ToString();
                        TTranche.Type_Train = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[1].Cells[j + 1]).Value.ToString();

                        TTranche.Gare_Depart = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[0]).Value.ToString();
                        TTranche.Heure_Depart = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[j + 1]).Value.ToString();

                        while (((donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[j + 1])).Value.ToString() == string.Empty)
                        {
                            i = i + 1;
                        }

                        TTranche.Gare_Arrivee = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[0]).Value.ToString();
                        TTranche.Heure_Arrivee = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[j + 1]).Value.ToString();

                        TGare.Add(TTranche);

                        i = i + 2;
                    }

                    //ListeTGares.Add(TGare);
                    AllTGare.AddRange(TGare);

                    j++;
                }
                //Si la premiere cellule est vide
                else
                {
                    while (((donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[j + 1])).Value.ToString() == string.Empty)
                        {
                            i = i + 1;
                        }
                    
                        i = i + 1;

                        while (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[j + 1].Value.ToString() != string.Empty)
                        {
                            TTranche = new Tranche();

                            TTranche.Num_Train = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[0].Cells[j + 1]).Value.ToString();
                            TTranche.Type_Train = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[1].Cells[j + 1]).Value.ToString();

                            TTranche.Gare_Depart = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[0]).Value.ToString();
                            TTranche.Heure_Depart = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i].Cells[j + 1]).Value.ToString();

                            while (((donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[j + 1])).Value.ToString() == string.Empty)
                            {
                                i = i + 1;
                            }

                            TTranche.Gare_Arrivee = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[0]).Value.ToString();
                            TTranche.Heure_Arrivee = (donneesFichierExcel.GetDataGridViewBretagneJobImpair().Rows[i + 1].Cells[j + 1]).Value.ToString();

                            TGare.Add(TTranche);

                            i = i + 2;
                        }
                        
                        //ListeTGares.Add(TGare);
                        AllTGare.AddRange(TGare);

                        j++;
                    }        
                }

            return AllTGare.Distinct().ToList();
        }