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; }
public static TimeValues FloatToTimeObject(float time) { TimeValues returnValue; float hours = Mathf.Floor(time / 3600); float v = time % 3600; float minutes = Mathf.Floor(v / 60); float seconds = Mathf.Floor(v % 60); returnValue = new TimeValues { convertedHours = hours, convertedMinutes = minutes, convertedSeconds = seconds }; return(returnValue); }
public void Test(object sender, DoWorkEventArgs eventArgs) { var approxAlgorithm = new MaxCut2Approximation(); var exactAlgorithm = new MaxCutExact(); TimeValues.Clear(); ResultValues.Clear(); var bw = sender as BackgroundWorker; var iterationsPerTest = (decimal)eventArgs.Argument; if (bw == null) { return; } var counter = 0.0; var currentProgress = 0; var calculationsCount = (double)(Graphs.Count * iterationsPerTest); var sw = new Stopwatch(); foreach (var g in Graphs) { TimeValues.Add(new TimePoint { N = g.N }); ResultValues.Add(new Result { Graph = g }); approxAlgorithm.InputGraph = g; exactAlgorithm.InputGraph = g; var sumOfTimesForExact = 0.0; var sumOfTimesForApprox = 0.0; for (var j = 0; j < iterationsPerTest; j++) { if (TestExactAlgorithm) { sw.Restart(); //DO WORK EXACT ALGORITHM exactAlgorithm.MaxCut(); // sw.Stop(); } ResultValues.Last().ExactCutSize = exactAlgorithm.CutSize; ResultValues.Last().ExactSet = exactAlgorithm.OutputSet; if (TestExactAlgorithm) { sumOfTimesForExact += sw.Elapsed.TotalMilliseconds; } if (TestApproximatedAlgorithm) { sw.Restart(); //DO WORK APPROX ALGORITHM approxAlgorithm.MaxCut(); // sw.Stop(); } ResultValues.Last().ApproximationCutSize = approxAlgorithm.CutSize; ResultValues.Last().ApproximationSet = approxAlgorithm.OutputSet; if (TestApproximatedAlgorithm) { sumOfTimesForApprox += sw.Elapsed.TotalMilliseconds; } counter++; var lastProgress = currentProgress; currentProgress = (int)(100.0 * (counter / calculationsCount)); if (currentProgress != lastProgress) { bw.ReportProgress(currentProgress); } } TimeValues.Last().ApproximationAlgorithmTime = sumOfTimesForApprox / (double)iterationsPerTest; TimeValues.Last().ExactAlgorithmTime = sumOfTimesForExact / (double)iterationsPerTest; } }