Exemple #1
0
        public static List <Trade> RegressionAnalysis_OnPL(int N, List <Trade> Trades)
        {
            List <VariableIndicator> V = new List <VariableIndicator>();
            var tradeonlyList          = Trades.Where(z => z.Reason == Trade.Trigger.CloseLong || z.Reason == Trade.Trigger.CloseShort);

            foreach (var v in tradeonlyList)
            {
                var varindicator = new VariableIndicator()
                {
                    TimeStamp = v.TimeStamp,
                    Value     = v.TotalPL,
                };

                V.Add(varindicator);
            }
            var reg = Factory_Indicator.createRegression(N, V);

            // var avg= reg.Sum(z => z.Slope) / reg.Count;
            // Debug.WriteLine(avg);
            foreach (var t in tradeonlyList)
            {
                foreach (var e in reg)
                {
                    if (e.TimeStamp == t.TimeStamp)
                    {
                        t.Extention.Regression = e.Regression;
                        t.Extention.Slope      = e.Slope;
                        t.Extention.OrderVol   = 1;
                    }
                }
            }



            return(tradeonlyList.ToList());
        }
Exemple #2
0
        private void SetRegressionSlopes()
        {           //cannot use linq, too slow
            var FTL       = _FullTradeList.Where(z => z.StopLoss_CenterLine != 0).ToList();
            var Ftl_Count = FTL.Count;


            #region Regression Calcs-Regression of MAMA

            var varList1 = new List <VariableIndicator>();
            foreach (var x in FTL.Where(z => z.Mama != null))
            {
                var v = new VariableIndicator()
                {
                    TimeStamp = x.TimeStamp,
                    Value     = x.Mama.Mama,
                };
                varList1.Add(v);
            }

            var reg1     = Factory_Indicator.createRegression(_reg1, varList1);
            var varList2 = new List <VariableIndicator>();

            foreach (var rr in reg1)
            {
                var q = new VariableIndicator()
                {
                    TimeStamp = rr.TimeStamp,
                    Value     = rr.Slope,
                };
                varList2.Add(q);
            }

            var reg2 = Factory_Indicator.createRegression(_reg2, varList2);

            var varList3 = new List <VariableIndicator>();

            foreach (var rr in reg2)
            {
                var qq = new VariableIndicator()
                {
                    TimeStamp = rr.TimeStamp,
                    Value     = rr.Slope,
                };
                varList3.Add(qq);
            }

            var reg3 = Factory_Indicator.createRegression(_reg3, varList3);
            #endregion

            #region Populate TakeProfitTrade object

            int ftl_Start_Index;

            //REG_1_SLOPE
            ftl_Start_Index = 0;
            //find start for reg1
            var reg1_Count = reg1.Count;
            //find first reg1.Time=FTL.Time
            var Ftl_Time_Equal_Reg1_Time = FTL.Where(f => f.TimeStamp == reg1[0].TimeStamp).First().TimeStamp;
            foreach (var Ft in FTL)
            {
                if (Ft.TimeStamp == Ftl_Time_Equal_Reg1_Time)
                {
                    break;
                }
                ftl_Start_Index++;
            }
            for (int x = 0; x < Ftl_Count - ftl_Start_Index; x++)
            {
                FTL[ftl_Start_Index + x].Reg1_Slope = reg1[x].Slope;
            }

            //REG_2_SLOPE
            ftl_Start_Index = 0;
            //find start for reg2
            var reg2_Count = reg2.Count;
            //find first reg1.Time=FTL.Time
            var Ftl_Time_Equal_Reg2_Time = FTL.Where(f => f.TimeStamp == reg2[0].TimeStamp).First().TimeStamp;
            foreach (var Ft in FTL)
            {
                if (Ft.TimeStamp == Ftl_Time_Equal_Reg2_Time)
                {
                    break;
                }
                ftl_Start_Index++;
            }
            for (int x = 0; x < Ftl_Count - ftl_Start_Index; x++)
            {
                FTL[ftl_Start_Index + x].Reg2_Slope = reg2[x].Slope * 10;
            }


            //REG_3_SLOPE
            ftl_Start_Index = 0;
            //find start for reg3
            var reg3_Count = reg3.Count;
            //find first reg1.Time=FTL.Time
            var Ftl_Time_Equal_Reg3_Time = FTL.Where(f => f.TimeStamp == reg3[0].TimeStamp).First().TimeStamp;
            foreach (var Ft in FTL)
            {
                if (Ft.TimeStamp == Ftl_Time_Equal_Reg3_Time)
                {
                    break;
                }
                ftl_Start_Index++;
            }
            for (int x = 0; x < Ftl_Count - ftl_Start_Index; x++)
            {
                FTL[ftl_Start_Index + x].Reg3_Slope = reg3[x].Slope * 100;
            }

            #endregion
        }