private static void ElapseMinute(EWMA ewma) { for (var i = 1; i <= 12; i++) { ewma.Tick(); } }
public NBarBreakMA(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol, bars => bars.high, bars => bars.low) { maSlow = new EWMA(bars.close, parameter <double>("MASlow")); maFast = new EWMA(bars.close, parameter <double>("MAFast")); addToPlot(maSlow, "maSlow", Color.BlueViolet); addToPlot(maFast, "maFast", Color.DeepPink); }
private void ElapseMinute(EWMA ewma) { for (int i = 1; i <= 12; i++) { ewma.Tick(); } }
public void DataStream_must_calculate_correct_ewma_for_normal_decay() { var d0 = new EWMA(1000.0D, 2.0 / (1 + 10)); Assert.True(d0.Value >= 1000.0D - 0.01 && d0.Value <= 1000.0D + 0.01); var d1 = d0 + 10.0d; Assert.True(d1.Value >= 820.0D - 0.01 && d1.Value <= 820.0D + 0.01); var d2 = d1 + 10.0d; Assert.True(d2.Value >= 672.73D - 0.01 && d2.Value <= 672.73D + 0.01); var d3 = d2 + 10.0d; Assert.True(d3.Value >= 552.23D - 0.01 && d3.Value <= 552.23D + 0.01); var d4 = d3 + 10.0d; Assert.True(d4.Value >= 453.64D - 0.01 && d4.Value <= 453.64D + 0.01); var dn = d0; for (var i = 0; i < 100; i++) { dn = dn + 10.0d; } Assert.True(dn.Value >= 10.0D - 0.1 && dn.Value <= 10.0D + 0.1); }
private MeterMetric(MetricName metricName, string eventType, TimeUnit rateUnit, EWMA m15Rate, EWMA m1Rate, EWMA m5Rate, long startTime) : this(metricName, eventType, rateUnit) { _m15Rate = m15Rate; _m1Rate = m1Rate; _m5Rate = m5Rate; _startTime = startTime; }
public void DataStream_must_calculate_sane_alpha_from_short_halflife() { var alpha = EWMA.CalculateAlpha(TimeSpan.FromMilliseconds(1), TimeSpan.FromSeconds(3)); Assert.True(alpha <= 1.0d); Assert.True(alpha >= 0.0d); Assert.True(alpha >= 1.0d - 0.001 && alpha <= 1.0d + 0.001); }
private PerSecondCounterMetric(string eventType, TimeUnit rateUnit) { _ewma = EWMA.OneSecondEWMA(Timer.ElapsedNanoseconds); Timer.Tick += TimeElapsed; _eventType = eventType; _rateUnit = rateUnit; }
public void DataStream_must_calculate_correct_emwa_value_for_alpha_10_max_bias_towards_latest_value() { var d0 = new EWMA(100.0D, 1.0); Assert.True(d0.Value >= 100.0D - 0.01 && d0.Value <= 100.0D + 0.01); var d1 = d0 + 1.0d; Assert.True(d1.Value >= 1.0D - 0.01 && d1.Value <= 1.0D + 0.01); var d2 = d1 + 57.0d; Assert.True(d2.Value >= 57.0D - 0.01 && d2.Value <= 57.0D + 0.01); var d3 = d2 + 10.0d; Assert.True(d3.Value >= 10.0D - 0.01 && d3.Value <= 10.0D + 0.01); }
private static long ElapseMinute(long currentTimestamp, EWMA ewma) { for (var i = 1; i <= 12; i++) { currentTimestamp += FiveSecondsTimestamp; ewma.Tick(currentTimestamp); } return(currentTimestamp); }
public void Can_retrieve_decaying_rate_with_discrete_value() { var ewma = EWMA.OneMinuteEWMA(InitialTimestamp); ewma.Update(3); ewma.Tick(FiveSecondsTimestamp); // Assumes 5 seconds have passed var rate = ewma.Rate(TimeUnit.Seconds); Assert.AreEqual(0.6, rate, "the EWMA has a rate of 0.6 events/sec after the first tick"); var timestamp = FiveSecondsTimestamp; timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.22072766, rate, 8, "the EWMA has a rate of 0.22072766 events/sec after 1 minute"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.08120116, rate, 8, "the EWMA has a rate of 0.08120116 events/sec after 2 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.02987224, rate, 8, "the EWMA has a rate of 0.02987224 events/sec after 3 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.01098938, rate, 8, "the EWMA has a rate of 0.01098938 events/sec after 4 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00404276, rate, 8, "the EWMA has a rate of 0.00404276 events/sec after 5 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00148725, rate, 8, "the EWMA has a rate of 0.00148725 events/sec after 6 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00054712, rate, 8, "the EWMA has a rate of 0.00054712 events/sec after 7 minutes"); ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00020127, rate, 8, "the EWMA has a rate of 0.00020127 events/sec after 8 minutes"); }
public void DataStream_must_calculate_alpha_from_halflife_and_collect_interval() { // according to http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average var expectedAlpha = 0.1; // alpha = 2.0 / (1 + N) var n = 19; var halfLife = n / 2.8854; var collectInterval = TimeSpan.FromSeconds(1); var halfLifeDuration = TimeSpan.FromMilliseconds(halfLife * 1000); var alpha = EWMA.CalculateAlpha(halfLifeDuration, collectInterval); Assert.True(alpha >= expectedAlpha - 0.001 && alpha <= expectedAlpha + 0.001); }
public MeterMetric(string eventType, TimeUnit rateUnit) { var timestamp = Timer.ElapsedNanoseconds; _m1Rate = EWMA.OneMinuteEWMA(timestamp); _m5Rate = EWMA.FiveMinuteEWMA(timestamp); _m15Rate = EWMA.FifteenMinuteEWMA(timestamp); EventType = eventType; RateUnit = rateUnit; Timer.Tick += Tick; }
public CouponSwap(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { //Set up signal data string tickerHeader; if (symbol.name.Substring(symbol.name.Length - 3, 3) == "TRS") { tickerHeader = symbol.name.Substring(0, 5); } else if (Regex.IsMatch(symbol.name, @"....\.\d")) { var tickerParts = symbol.name.Split(Convert.ToChar(".")); tickerHeader = (tickerParts[0] == "FNCL" ? "F" : "D"); tickerHeader = tickerHeader + tickerParts[1] + tickerParts[2]; tickerHeader = tickerHeader + tickerParts[3] + tickerParts[4]; } else { throw Bomb.toss("Bad symbol name, not able to figure out the signal data."); } modelPrice = new Symbol(tickerHeader + "MDL").doubles(bars); actualPrice = new Symbol(tickerHeader + "ACT").doubles(bars); rollDecimal = new Symbol(tickerHeader + "WRL").doubles(bars); rollTicks = new Times(rollDecimal, rollDecimal.manager.constant(32.0)); tradeSize = parameter <long>("TradeSize"); maxSize = parameter <long>("MaxPyramid") * tradeSize; entryTicks = parameter <double>("EntryTicks"); stopTicks = parameter <double>("StopTicks"); richCheap = new RichCheapSpud(modelPrice, actualPrice); longEntryCross = new CrossOverSpud <double>(richCheap, entryTicks); shortEntryCross = new CrossOverSpud <double>(richCheap, -entryTicks); longExitCross = new CrossOverSpud <double>(richCheap, parameter <double>("ExitTicks")); shortExitCross = new CrossOverSpud <double>(richCheap, -parameter <double>("ExitTicks")); longMA = new EWMA(richCheap, parameter <double>("HalfLife")); rollCutOff = parameter <double>("RollCutOff"); rollCutOffMargin = parameter <double>("RollCutOff.Margin"); longRollCross = new CrossOverSpud <double>(rollDecimal, -(rollCutOff - rollCutOffMargin) / 32); shortRollCross = new CrossOverSpud <double>(rollDecimal, (rollCutOff - rollCutOffMargin) / 32); //Add Plots addToPlot(modelPrice, "Model Price", Color.Red, "Coupon Swap"); addToPlot(actualPrice, "Actual Price", Color.Blue, "Coupon Swap"); addToPlot(rollTicks, "Weighted Roll", Color.Green, "Roll"); }
static void Main(string[] args) { //FixedTimeBenchmark.Run<CounterMetric>(m => m.Increment()); //FixedTimeBenchmark.Run<MeterMetric>(m => m.Mark()); //FixedTimeBenchmark.Run<HistogramMetric>(m => m.Update(1)); FixedTimeBenchmark.Run(() => EWMA.OneMinuteEWMA(), m => m.Update(1), maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new TimerMetric(new SlidingWindowReservoir()), m => { using (m.NewContext()) { } }, maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new ExponentiallyDecayingReservoir(), r => r.Update(100), maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new UniformReservoir(), r => r.Update(100), maxThreads: 32, seconds: 5, decrement: 4); //FixedIterationsBenchmark.Run<TimerMetric>(m => { using (m.NewContext()) { } }, 1000 * 1000); }
static void Main(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options, (t, o) => { target = t; targetOptions = o as CommonOptions; })) { Console.WriteLine(new CommonOptions().GetUsage()); Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } Console.WriteLine("{0} | Duration {1} seconds | Start Threads {2} | Step {3}", target, targetOptions.Seconds, targetOptions.MaxThreads, targetOptions.Decrement); switch (target) { case "counter": Run(() => new CounterMetric(), c => c.Increment()); break; case "meter": Run(() => new MeterMetric(), m => m.Mark()); break; case "histogram": Run(() => new HistogramMetric(), h => h.Update(37)); break; case "timer": Run(() => new TimerMetric(SamplingType.FavourRecent), t => t.Record(10, TimeUnit.Milliseconds)); break; case "ewma": Run(() => EWMA.OneMinuteEWMA(), m => m.Update(1)); break; case "edr": Run(() => new ExponentiallyDecayingReservoir(), r => r.Update(100)); break; case "uniform": Run(() => new UniformReservoir(), r => r.Update(100)); break; case "sliding": Run(() => new SlidingWindowReservoir(), r => r.Update(100)); break; } }
public void DataStream_must_calculate_correct_ewma_for_normal_decay() { var d0 = new EWMA(1000.0D, 2.0 / (1 + 10)); Assert.True(d0.Value >= 1000.0D - 0.01 && d0.Value <= 1000.0D + 0.01); var d1 = d0 + 10.0d; Assert.True(d1.Value >= 820.0D - 0.01 && d1.Value <= 820.0D + 0.01); var d2 = d1 + 10.0d; Assert.True(d2.Value >= 672.73D - 0.01 && d2.Value <= 672.73D + 0.01); var d3 = d2 + 10.0d; Assert.True(d3.Value >= 552.23D - 0.01 && d3.Value <= 552.23D + 0.01); var d4 = d3 + 10.0d; Assert.True(d4.Value >= 453.64D - 0.01 && d4.Value <= 453.64D + 0.01); var dn = d0; for (var i = 0; i < 100; i++) dn = dn + 10.0d; Assert.True(dn.Value >= 10.0D - 0.1 && dn.Value <= 10.0D + 0.1); }
public void Can_relative_decay_rates_for_discrete_values() { var one = EWMA.OneMinuteEWMA(InitialTimestamp); one.Update(100000); one.Tick(FiveSecondsTimestamp); var five = EWMA.FiveMinuteEWMA(InitialTimestamp); five.Update(100000); five.Tick(FiveSecondsTimestamp); var fifteen = EWMA.FifteenMinuteEWMA(InitialTimestamp); fifteen.Update(100000); fifteen.Tick(FiveSecondsTimestamp); var rateOne = one.Rate(TimeUnit.Seconds); var rateFive = five.Rate(TimeUnit.Seconds); var rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(20000, rateOne); Assert.AreEqual(20000, rateFive); Assert.AreEqual(20000, rateFifteen); var timestamp = FiveSecondsTimestamp; ElapseMinute(timestamp, one); rateOne = one.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, five); rateFive = five.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, fifteen); rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(7357.5888234288504d, rateOne); Assert.AreEqual(16374.615061559636d, rateFive); Assert.AreEqual(18710.13970063235d, rateFifteen); }
public TestSystemWithEWMA(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol) { ewma = new EWMA(bars.close, 5); }
public SimulationOutput ComputeSimulation(SimulationInput input) { var securities = _repository.GetSecurities(); var underlying = securities.FirstOrDefault(x => x.SecurityType == SecurityType.Underlying); var future = securities.FirstOrDefault(x => x.SecurityType == SecurityType.Future); var call = securities.FirstOrDefault(x => x.SecurityType == SecurityType.Option); ReturnCalculator.ComputeReturn(underlying.DataSeries); var output = new SimulationOutput(); output.Type = SimulationType.FixedVol; if (input != null && input.TimeWindow.HasValue) { output.TimeWindow = input.TimeWindow; } else { output.TimeWindow = 252; } if (input != null && input.Sigma.HasValue && input.Sigma.Value != 0) { output.Sigma = input.Sigma / 100; } else { output.Sigma = StdDev.ComputeStdDev(underlying.DataSeries, 252); } if (input != null && input.RiskFree.HasValue) { output.RiskFree = input.RiskFree / 100; } else { output.RiskFree = 4.5 / 100; } var minDate = call.DataSeries.Min(x => x.Date); var initialVol = EWMA.ComputeInitalVol(underlying.DataSeries, input.Lambda.Value, minDate, input.TimeWindow.Value); var count = 0; double volYesterday = 0, returnYesterday = 0; call.DataSeries .OrderByDescending(x => x.Date) .ToList() .ForEach(x => { var underPrice = future.DataSeries.Where(y => y.Date == x.Date).FirstOrDefault(); if (underPrice != null) { var simulationDataSerie = new SimulationDataSerie(); simulationDataSerie.Volatility = output.Sigma.Value; simulationDataSerie.Date = x.Date; simulationDataSerie.BlackAndScholesPrice = BlackAndScholes.ComputePrice(underPrice.Price, call.Strike, output.RiskFree.Value, output.Sigma.Value, (x.TTM.Value / 252.0), 0); simulationDataSerie.Black76Price = Black76.ComputePrice(underPrice.Price, call.Strike, output.RiskFree.Value, output.Sigma.Value, (x.TTM.Value / 252.0), 0); simulationDataSerie.UnderlyingPrice = underPrice.Price; simulationDataSerie.MarketPrice = x.Price; if (count == 0) { simulationDataSerie.EWMAVol = initialVol; } else { simulationDataSerie.EWMAVol = EWMA.ComputeVol(volYesterday, returnYesterday, input.Lambda.Value); } simulationDataSerie.BlackAndScholesPriceEWMA = BlackAndScholes.ComputePrice(underPrice.Price, call.Strike, output.RiskFree.Value, simulationDataSerie.EWMAVol * 100, (x.TTM.Value / 252.0), 0); simulationDataSerie.Black76PriceEWMA = Black76.ComputePrice(underPrice.Price, call.Strike, output.RiskFree.Value, simulationDataSerie.EWMAVol, (x.TTM.Value / 252.0), 0); returnYesterday = underlying.DataSeries.OrderByDescending(y => y.Date).First(y => y.Date < x.Date).Return; volYesterday = simulationDataSerie.EWMAVol; output.DataSeries.Add(simulationDataSerie); count++; } }); output.DataSeries = output.DataSeries.OrderBy(x => x.Date).ToList(); return(output); }
public void DataStream_must_calculate_same_emwa_for_constant_values() { var ds = new EWMA(100.0d, 0.18) + 100.0D + 100.0D + 100.0D; Assert.True(ds.Value >= 100.0D - 0.001 && ds.Value <= 100.0D + 0.001); }
public void EWMA_aFiveMinuteEWMAWithAValueOfThree() { var ewma = EWMA.FiveMinuteEWMA(); ewma.Update(3L); ewma.Tick(); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.6, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.49123845, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.40219203, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.32928698, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.26959738, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.22072766, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.18071653, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.14795818, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.12113791, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.09917933, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.08120117, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.06648190, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.05443077, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.04456415, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.03648604, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.02987224, 0.000001); }
public void EWMA_aOneMinuteEWMAWithAValueOfThree() { var ewma = EWMA.OneMinuteEWMA(); ewma.Update(3L); ewma.Tick(); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.6, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.22072766, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.08120117, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.02987224, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.01098938, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00404277, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00148725, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00054713, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00020128, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00007405, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00002724, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00001002, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000369, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000136, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000050, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000018, 0.000001); }
public void EWMA_aFifteenMinuteEWMAWithAValueOfThree() { var ewma = EWMA.FifteenMinuteEWMA(); ewma.Update(3L); ewma.Tick(); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.6, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.56130419, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.52510399, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.49123845, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.45955700, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.42991879, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.40219203, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.37625345, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.35198773, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.32928698, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.30805027, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.28818318, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.26959738, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.25221023, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.23594443, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.22072766, 0.000001); }
static void Main(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options, (t, o) => { target = t; targetOptions = o as CommonOptions; })) { Console.WriteLine(new CommonOptions().GetUsage()); Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } BenchmarkRunner.DefaultTotalSeconds = targetOptions.Seconds; BenchmarkRunner.DefaultMaxThreads = targetOptions.MaxThreads; //Metric.Config.WithHttpEndpoint("http://localhost:1234/"); switch (target) { case "noop": BenchmarkRunner.Run("Noop", () => { }); break; case "counter": var counter = new CounterMetric(); BenchmarkRunner.Run("Counter", () => counter.Increment()); break; case "meter": var meter = new MeterMetric(); BenchmarkRunner.Run("Meter", () => meter.Mark()); break; case "histogram": var histogram = new HistogramMetric(); BenchmarkRunner.Run("Histogram", () => histogram.Update(137)); break; case "timer": var timer = new TimerMetric(); BenchmarkRunner.Run("Timer", () => timer.Record(1, TimeUnit.Milliseconds)); break; case "hdrtimer": var hdrTimer = new TimerMetric(new HdrHistogramReservoir()); BenchmarkRunner.Run("HDR Timer", () => hdrTimer.Record(1, TimeUnit.Milliseconds)); break; case "ewma": var ewma = EWMA.OneMinuteEWMA(); BenchmarkRunner.Run("EWMA", () => ewma.Update(1)); break; case "edr": var edr = new ExponentiallyDecayingReservoir(); BenchmarkRunner.Run("EDR", () => edr.Update(1)); break; case "hdr": var hdrReservoir = new HdrHistogramReservoir(); BenchmarkRunner.Run("HDR Recorder", () => hdrReservoir.Update(1)); break; case "uniform": var uniform = new UniformReservoir(); BenchmarkRunner.Run("Uniform", () => uniform.Update(1)); break; case "sliding": var sliding = new SlidingWindowReservoir(); BenchmarkRunner.Run("Sliding", () => sliding.Update(1)); break; case "timerimpact": var load = new WorkLoad(); BenchmarkRunner.Run("WorkWithoutTimer", () => load.DoSomeWork(), iterationsChunk: 10); BenchmarkRunner.Run("WorkWithTimer", () => load.DoSomeWorkWithATimer(), iterationsChunk: 10); break; } }