Exemplo n.º 1
0
        // Beyond 0.6 and less than 0.3 does not work good, at least surely in nifty
        // Stoploss 1 is most optimized
        // Min profit 0.5, 0.75 and 1 are optimized. Not needed to dabble with them

        public static TradingAlgo GetAlgo(short algoId, AlgoParams algoParams, bool onlyCheckAlgoExist)//bool doLimitLoss = false)
        {
            TradingAlgo algo        = null;
            bool        isAlgoFound = true;

            //algoParams.AllowInitialTickStabilization = true;


            switch (algoId)
            {
            // -------------------- New Experiments Scalper 150 Algos-------------------------------- //
            case 150:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 151:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 152:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            case 153:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.3;
                break;

            // --------------------Scalper Algos: Immediate squareoff on min profit. No peak or minmax reset-------------------------------- //
            case 13:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 14:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 15:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 17:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 18:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 19:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            // --------------------Scalper Algos: Immediate squareoff on min profit. Reset peaktype and minmax-------------------------------- //
            case 20:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 21:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 22:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            case 23:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.35;
                break;

            // ----------------------Min Profit must. threshold moves (perc-minprofit) ---------------------------------- //
            case 30:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 31:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 32:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            // ---------------------Min profit + half of over that is must. threshold moves (perc-minprofit)/2------------------------------------------- //
            case 40:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 41:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 42:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            // -------------------------Same like 40s with reset min-max--------------------------- //
            case 50:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 51:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            case 52:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 53:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.35;
                break;

            case 60:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 1;
                break;

            case 61:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 62:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 3;
                break;

            // ------------------ Stop loss threshold moves with profit : lenient------------------------- //
            case 100:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 101:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 102:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            case 113:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 114:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            case 115:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            // ------------------ Stop loss threshold moves with profit :Straight profit/3 lenient------------------------- //
            case 116:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.5;
                break;

            case 117:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 1;
                break;

            case 118:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.75;
                break;

            case 119:
                algoParams.PercSquareOffThreshold = 1;
                algoParams.PercMinProfit          = 0.35;
                algoParams.IsFixedTradesPerDay    = true;
                algoParams.NumTradesStopForDay    = 2;
                break;

            default:
                isAlgoFound = false;
                break;
            }

            // Temporary test
            //if (algoParams.IsReplayMode)
            //{
            //    //algoParams.PercSquareOffThreshold = 1;
            //    //algoParams.AllowInitialTickStabilization = true;
            //    //algoParams.IsFixedTradesPerDay = true;
            //    algoParams.IsLimitLossPerDay = true;
            //    algoParams.NumTradesStopForDay = 2;
            //    algoParams.PercSquareOffThreshold = 1.25;
            //}


            if (!isAlgoFound)
            {
                return(null);
            }
            else if (onlyCheckAlgoExist)
            {
                algoParams.I = new Instrument("dummy", InstrumentType.FutureIndex, 100);
                if (algoParams.IsHedgeAlgo)
                {
                    algo = new AlgoHedge(algoParams);
                }
                else
                {
                    algo = new AlgoScalper(algoParams);
                }

                return(algo);
            }

            algoParams.IsLimitLossPerDay           = true;
            algoParams.PercLossStopForDay          = 2.5;
            algoParams.NumNettLossTradesStopForDay = 5;

            if (algoId >= 10)
            {
                algoParams.IsMinProfitMust = true;
            }

            if (StockUtils.IsInstrumentOptionType(algoParams.I.InstrumentType))
            {
                algoParams.PercMinProfit += 5;
                if (algoParams.PercMarketDirectionChange == 7.05)
                {
                    algoParams.PercSquareOffThreshold += 5;
                }
                else if (algoParams.PercMarketDirectionChange == 7.15)
                {
                    //algoParams.PercMarketDirectionChange += 3.6;
                    algoParams.PercSquareOffThreshold += 15;
                }
                else
                {
                    algoParams.PercSquareOffThreshold += 10;
                }
                algoParams.PercBrokerage = 12000 / (algoParams.I.StrikePrice * algoParams.I.Qty);
                //algoParams.SquareOffBrokerageFactor = 1.3;
            }

            //if (algoId < 10)
            //    algo = new AlgoMinMax(algoParams);
            //else
            if (algoParams.IsHedgeAlgo)
            {
                algo = new AlgoHedge(algoParams);
            }
            else
            {
                algo = new AlgoScalper(algoParams);
            }

            return(algo);
        }