private double GetMonteCarloProbHighTouchesM(double sigma, int numSteps, double m, int iterations) { var countAbove = 0; for (var i = 0; i < iterations; i++) { var hasAbove = false; var startPrice = 0.0; for (var j = 0; j < numSteps; j++) { startPrice += Gaussian.BoxMuller(0, sigma); if (startPrice >= m) { hasAbove = true; break; } } if (hasAbove) { countAbove++; } } return((double)countAbove / iterations); }
private void GenerateLoop() { var genPass = new Random(); var quoteNames = new[] { "EURUSD", "GBPUSD", "USDJPY", "USDCHF" }; var quoteMO = new[] { 1.2858f, 1.4261f, 96.45f, 0.9875f }; var quoteSig = new[] { 0.0003f, 0.0004f, 0.03f, 0.0003f }; while (!stopFlag) { var lstNames = new List <string>(); var lstQuotes = new List <QuoteData>(); for (var i = 0; i < quoteNames.Length; i++) { // случайно пропустить пару if (genPass.Next(100) > 70) { continue; } // расчитать новое значение quoteMO[i] = quoteMO[i] + quoteSig[i] * (float)Gaussian.BoxMuller(0, 0.00015f); lstNames.Add(quoteNames[i]); lstQuotes.Add(new QuoteData(quoteMO[i], quoteMO[i] + quoteSig[i], DateTime.Now)); if (onQuotesReceived != null) { onQuotesReceived(lstNames, lstQuotes); } } Thread.Sleep(200); } }
//public override void Add(Plant p) //{ // p.Tilt = InitialTilt(); // p.currNormal = Quaternion.identity; //} protected Quaternion InitialTilt() { var gaussian = Gaussian.BoxMuller(); var tilt = Quaternion.FromToRotation(Vector3.up, Vector3.back) * Quaternion.Euler(tiltPower * gaussian.x, Random.Range(0f, ROUND_IN_DEG), tiltPower * gaussian.y); return(tilt); }
public Vector2 RandomStep() { #if RANDOM_UNIFORM return(new Vector2( sigma * dist.x * Random.Range(-1f, 1f), sigma * dist.y * Random.Range(-1f, 1f))); #else var g = Gaussian.BoxMuller(); return(new Vector2(sigma * dist.x * g.x, sigma * dist.y * g.y)); #endif }
public void TestDeltaGeneration() { var candles = new List <CandleData>(); for (var i = 0; i < 10000; i++) { var delta = Gaussian.BoxMuller(0, 1); candles.Add(new CandleData(100, 100, 99, 100 + (float)delta, new DateTime(), new DateTime())); } // небольшой процент больших смещений for (var i = 0; i < 10; i++) { var delta = 5 * (i % 2 == 0 ? 1 : -1); candles.Add(new CandleData(100, 100, 99, 100 + 1f * (float)delta, new DateTime(), new DateTime())); } var listOc = candles.Select(c => (double)(c.close - c.open)).OrderBy(c => c).ToList(); var model = new PriceModel(listOc); const int checksCount = 5000; var deltas = new double[checksCount]; for (var i = 0; i < checksCount; i++) { deltas[i] = model.GetRandomDelta(); } var meanDelta = deltas.Average(); var maxDelta = deltas.Max(d => Math.Abs(d)); var vl = deltas.Sum(d => (d - meanDelta) * (d - meanDelta)); vl = Math.Sqrt(vl / checksCount); Assert.Less(Math.Abs(meanDelta), 0.3, "Mean value should be around 0"); Assert.Less(Math.Abs(vl - 1), 0.3, "AD should be around 1"); Assert.Greater(maxDelta, 1, "max delta should be greater than 1"); }
public double CalculateDelta() { return(Gaussian.BoxMuller(0, volatility.Value)); }