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);
        }
示例#2
0
        public static InvestmentPlan solve(Tranche tranche)
        {
            Investor investor = new Investor(tranche.period, tranche.capital, tranche.assets);

            InvestmentsSolver solver = new InvestmentsSolver(investor);

            InvestmentPlan plan = solver.TheoreticalProfitPlan();

            return(plan);
        }
 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 void WriteConditionToTextFile(string fileName, Tranche tranche)
        {
            using (var sw = new StreamWriter(fileName))
            {
                sw.WriteLine(tranche.capital.ToString(ci));
                sw.WriteLine(tranche.period.ToString(ci));
                sw.WriteLine(tranche.assets.Count.ToString(ci));
                for (int i = 0; i < tranche.assets.Count; i++)
                {
                    var tmp = tranche.assets[i];

                    sw.WriteLine(tmp.profit.ToString(ci));
                    sw.WriteLine(tmp.prob.ToString(ci));
                }
            }
        }
        public static Tranche ReadConditionFromTextFile(string fileName)
        {
            Tranche tranche;

            using (var sr = new StreamReader(fileName))
            {
                string  line = sr.ReadLine();
                decimal C    = Decimal.Parse(line, ci);
                line = sr.ReadLine();

                int period = int.Parse(line, ci);
                if (period < 1)
                {
                    throw new ArgumentException();
                }

                line = sr.ReadLine();
                int n = int.Parse(line, ci);
                if (n < 1)
                {
                    throw new ArgumentException();
                }

                List <Asset> assets = new List <Asset>();
                for (int i = 0; i < n; i++)
                {
                    line = sr.ReadLine();
                    decimal profit = Decimal.Parse(line, ci);
                    line = sr.ReadLine();
                    decimal prob = Decimal.Parse(line, ci);

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

                tranche = new Tranche(C, period, assets);
            }
            return(tranche);
        }