Exemplo n.º 1
0
        private int CorridorCrossesCount(CorridorStatistics corridornes, Func <Rate, double> getPriceHigh, Func <Rate, double> getPriceLow, Func <CorridorStatistics, double> heightUp, Func <CorridorStatistics, double> heightDown)
        {
            var rates = corridornes.Rates;

            double[] coeffs = corridornes.Coeffs;

            var rateByIndex    = rates.Select((r, i) => new { index = i, rate = r }).Skip(3).ToList();
            var crossPriceHigh = CorridorCrossGetHighPrice();
            var crossUps       = rateByIndex
                                 .Where(rbi => crossPriceHigh(rbi.rate) >= corridornes.priceLine[rbi.index] + heightUp(corridornes))
                                 .Select(rbi => new __rateCross(rbi.rate, true)).ToList();
            var crossPriceLow = CorridorCrossGetLowPrice();
            var crossDowns    = rateByIndex
                                .Where(rbi => crossPriceLow(rbi.rate) <= corridornes.priceLine[rbi.index] - heightDown(corridornes))
                                .Select(rbi => new __rateCross(rbi.rate, false)).ToList();

            if (crossDowns.Any() || crossUps.Any())
            {
                var crosses     = crossUps.Concat(crossDowns).OrderByDescending(r => r.rate.StartDate).ToList();
                var crossesList = new List <__rateCross>();
                crossesList.Add(crosses[0]);
                crosses.Aggregate((rp, rn) => {
                    if (rp.isUp != rn.isUp)
                    {
                        crossesList.Add(rn);
                        //corridornes.LegInfos.Add(new CorridorStatistics.LegInfo(rp.rate, rn.rate, BarPeriodInt.FromMinutes()));
                    }
                    return(rn);
                });
                return(crossesList.Count);
            }
            return(0);
        }
Exemplo n.º 2
0
        private static void SetCorrelations(TradingMacro tm, List <Rate> rates, CorridorStatistics csFirst, PriceBar[] priceBars)
        {
            var pbs = priceBars /*.Where(pb => pb.StartDate > csFirst.StartDate)*/.OrderBy(pb => pb.StartDate).Select(pb => pb.Power).ToArray();
            var rs  = rates /*.Where(r => r.StartDate > csFirst.StartDate)*/.Select(r => r.PriceAvg).ToArray();

            tm.Correlation_P = global::alglib.pearsoncorrelation(pbs, rs);
            tm.Correlation_R = global::alglib.spearmancorr2(pbs, rs, Math.Min(pbs.Length, rs.Length));
        }
Exemplo n.º 3
0
 public void Init(CorridorStatistics cs, double pipSize)
 {
     this._pipSize  = pipSize;
     this.priceLine = cs.priceLine;
     this.priceHigh = cs.priceHigh;
     this.priceLow  = cs.priceLow;
     Init(cs.Rates, cs.StDev, cs.Coeffs, cs.HeightUp0, cs.HeightDown0, cs.HeightUp, cs.HeightDown, cs.Iterations, cs.CorridorCrossesCount);
     this.Spread             = cs.Spread;
     this.StDevs             = cs.StDevs;
     this.HeightByRegression = cs.HeightByRegression;
     //GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() => {
     //  LegInfos.Clear();
     //  LegInfos.AddRange(cs.LegInfos);
     //});
     RaisePropertyChanged(
         () => HeightUpDown0, () => HeightUpDown, () => HeightUpDown0InPips, () => HeightUpDownInPips, () => HeightUpDown0ToSpreadRatio);
 }
Exemplo n.º 4
0
 private int CorridorCrossesCount(CorridorStatistics corridornes)
 {
     return(CorridorCrossesCount(corridornes, corridornes.priceHigh, corridornes.priceLow, c => c.HeightUp, c => c.HeightDown));
 }
Exemplo n.º 5
0
 private static bool IsCorridorCountOk(CorridorStatistics cs, double corridorCrossesCountMinimum)
 {
     return(IsCorridorCountOk(cs.CorridorCrossesCount, corridorCrossesCountMinimum));
 }
Exemplo n.º 6
0
 private bool IsCorridorCountOk(CorridorStatistics cs)
 {
     return(IsCorridorCountOk(cs, CorridorCrossesCountMinimum));
 }
Exemplo n.º 7
0
 private bool IsCorridorOk(CorridorStatistics cs)
 {
     return(true);
 }