Beispiel #1
0
        public void UpdateFormulaSheetReferences()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaSheetReferences("5+'OldSheet'!$G3+'Some Other Sheet'!C3+SUM(1,2,3)", "OldSheet", "NewSheet");

            Assert.AreEqual("5+'NewSheet'!$G3+'Some Other Sheet'!C3+SUM(1,2,3)", result);
        }
Beispiel #2
0
        public void UpdateFormulaDeletedSheetReference()
        {
            var    formulaManager = new FormulaManager();
            string actualFormula  = formulaManager.UpdateFormulaDeletedSheetReferences("CONCATENATE(Sheet1!B2, Sheet2!C3)", "sheet1");

            Assert.AreEqual("CONCATENATE(#REF!B2,'Sheet2'!C3)", actualFormula);
        }
Beispiel #3
0
        public void TestFormulas()
        {
            facade = new FacadeBacktester();
            facade.LoadAtivo("PETR4", 100, Consts.PERIODO_ACAO.DIARIO, "dados/petr4-diario.js");
            Ativo ativo = facade.GetAtivo("PETR4");

            FormulaManager fm = facade.formulaManager;

            Assert.IsNotNull(fm.GetFormula("3"));

            Formula f = fm.GetFormula("RSI(HV(SUBTRACT(O,-9),L),C)");

            Assert.IsNotNull(f);

            f = fm.GetFormula("PERCENTIL(SUBTRACT(PERCENTIL(C),C))");
            Assert.IsNotNull(f);

            f = fm.GetFormula("RSI(HV(SUBTRACT(O,-9),L),C)");
            Assert.IsNotNull(f);

            Assert.IsNotNull(fm.GetFormula("MME(C,3)"));

            string fonte    = "C";
            int    periodos = 3;

            validaFormulaMMS(ativo, fm, fonte, periodos);

            periodos = 6;
            fonte    = "MME(O,6)";
            validaFormulaMMS(ativo, fm, fonte, periodos);
        }
Beispiel #4
0
        public void UpdateFormulaReferencesReferencingADifferentSheetIsNotUpdated()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("'boring sheet'!C3", 3, 3, 2, 2, "boring sheet", "updated sheet");

            Assert.AreEqual("'boring sheet'!C3", result);
        }
Beispiel #5
0
        public void UpdateFormulaReferencesFullyQualifiedCrossSheetReferenceArray()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("SUM('sheet name here'!B2:D4)", 3, 3, 3, 3, "cross sheet", "sheet name here");

            Assert.AreEqual("SUM('sheet name here'!B2:G7)", result);
        }
Beispiel #6
0
        public void UpdateFormulaReferencesFullyQualifiedReferenceOnADifferentSheet()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("'updated sheet'!C3", 3, 3, 2, 2, "boring sheet", "updated sheet");

            Assert.AreEqual("'updated sheet'!F6", result);
        }
Beispiel #7
0
        public void UpdateFormulaReferencesFullyQualifiedReferenceOnTheSameSheet()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("'sheet name here'!C3", 3, 3, 2, 2, "sheet name here", "sheet name here");

            Assert.AreEqual("'sheet name here'!F6", result);
        }
Beispiel #8
0
        public void UpdateFormulaReferencesIgnoresIncorrectSheet()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("C3", 3, 3, 2, 2, "sheet", "other sheet");

            Assert.AreEqual("C3", result);
        }
        private void FillTaskAdvancedFields(Model.Task task)
        {
            var eventDao  = new EventInfoDao(dao.usingDbUtility);
            var eventList = eventDao.GetLinkedEventList(task.id);

            if (eventList.Length == 0)
            {
                task._hasLinkedEvent = false;
                task._firstStartTime = DateTime.MaxValue;
                task._lastEndTime    = DateTime.MinValue;
            }
            else
            {
                task._hasLinkedEvent = true;
                task._firstStartTime = DateTime.MaxValue;
                task._lastEndTime    = DateTime.MinValue;

                foreach (var item in eventList)
                {
                    var fm        = new FormulaManager(item.remindFormula);
                    var startTime = fm.GetStartDate();
                    startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, item.startTime.Hour, item.startTime.Minute, 0);
                    var endTime = fm.GetEndDate();
                    endTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, item.endTime.Hour, item.endTime.Minute, 59);
                    task._firstStartTime = startTime < task._firstStartTime ? startTime : task._firstStartTime;
                    task._lastEndTime    = endTime > task._lastEndTime ? endTime : task._lastEndTime;
                }
            }
        }
Beispiel #10
0
        public void UpdateFormulaReferencesOnTheSameSheet()
        {
            var formulaManager = new FormulaManager();
            var result         = formulaManager.UpdateFormulaReferences("C3", 3, 3, 2, 2, "sheet", "sheet");

            Assert.AreEqual("F6", result);
        }
Beispiel #11
0
        public void UpdateFormulaReferencesPreservesEscapedQuotes()
        {
            var formulaManager = new FormulaManager();

            Assert.AreEqual("\"Hello,\"\" World\"&\"!\"", formulaManager.UpdateFormulaReferences("\"Hello,\"\" World\"&\"!\"", 1, 1, 8, 2, "Sheet", "Sheet"));
            Assert.AreEqual("FUNCTION(1,\"Hello World\",\"My name is \"\"Bob\"\"\",16)", formulaManager.UpdateFormulaReferences("FUNCTION(1, \"Hello World\", \"My name is \"\"Bob\"\"\", 16)", 1, 1, 8, 2, "Sheet", "Sheet"));
            Assert.AreEqual("FUNCTION(\"This is an example of \"\" Nested \"\"\"\" Quotes \"\".\")", formulaManager.UpdateFormulaReferences("FUNCTION(\"This is an example of \"\" Nested \"\"\"\" Quotes \"\".\")", 1, 1, 8, 2, "Sheet", "Sheet"));
        }
Beispiel #12
0
        public void TestGeracaoFormulas()
        {
            string         formula = "MME(O,LV(PERCENTIL(MOD(L,H)),C))";
            FormulaManager fm      = facade.formulaManager;
            Formula        f1      = fm.GetFormula(formula);

            Assert.IsNotNull(f1);
            Assert.IsTrue(f1.GetCode() == formula);
        }
Beispiel #13
0
        public void ConfigureAppliesGivenIFormulaManager()
        {
            var formulaManager = new FormulaManager();
            var excelPackage   = new ExcelPackage();

            Assert.AreNotEqual(formulaManager, excelPackage.FormulaManager);
            excelPackage.Configure(formulaManager);
            Assert.AreEqual(formulaManager, excelPackage.FormulaManager);
        }
        public LabeledTransitionMarkovChain GenerateLabeledMarkovChain()
        {
            FormulaManager.Calculate(Configuration);
            var stateFormulasToCheckInBaseModel = FormulaManager.StateFormulasToCheckInBaseModel.ToArray();

            var createModel = new AnalysisModelCreator(() => new LtmcRetraverseModel(_sourceLtmc, stateFormulasToCheckInBaseModel, Configuration));

            Configuration.DefaultTraceOutput.WriteLine("Retraverse Model");

            var labeledTransitionMarkovChain = GenerateLtmc(createModel);

            return(labeledTransitionMarkovChain);
        }
Beispiel #15
0
        public void TestClarificarTradeSystem()
        {
            Config         config  = new Config();
            FormulaManager fm      = facade.formulaManager;
            Clarify        clarify = new Clarify();

            //TradeSystem tradeSystem = new TradeSystem(config);
            ValidaClarify(clarify, "SUM(H,MULTIPLY(STD(C,10),2))", "H + (STD(C,10) * 2)");
            ValidaClarify(clarify, "GREATER(MME(C, 9), MME(C, 6))", "MME(C,9) > MME(C,6)");
            ValidaClarify(clarify, "AND(LV(C, L), C)", "LV(C,L) && C");


            ValidaClarifyViciado(clarify, "MME(C, 9)", false);
            ValidaClarifyViciado(clarify, "MME(9, C)", true);
        }
Beispiel #16
0
        public void TestCondicaoComplexa()
        {
            facade.LoadAtivo("PETR4", 100, Consts.PERIODO_ACAO.DIARIO, "dados/petr4-diario.js");
            Ativo ativo = facade.GetAtivo("PETR4");

            Config      config = new Config();
            TradeSystem ts     = new TradeSystem(config);

            /*
             * Exemplos:
             * C>O
             *
             * !C>O
             *
             * C>O||C<REF(C,1)
             *
             * (C>O||C<REF(C,1))&&RSI(C,9)>7
             *
             *
             */

            string strFormulaA = "MME(C,9)";
            string strFormulaB = "MMS(C,9)";
            string strFormulaC = "MMS(C,3)";

            ICondicao      cond1  = new CondicaoComplexa(config, strFormulaA + ">" + strFormulaB);
            FormulaManager fm     = facade.formulaManager;
            Candle         candle = ativo.firstCandle;

            candle.SetValor(strFormulaA, 10);
            candle.SetValor(strFormulaB, 20);
            candle.SetValor(strFormulaC, 5);
            Assert.IsFalse(cond1.VerificaCondicao(candle, ts));
            candle.SetValor(strFormulaA, 30);
            Assert.IsTrue(cond1.VerificaCondicao(candle, ts));

            ICondicao cond2 = new CondicaoComplexa(config, strFormulaA + ">" + strFormulaB + "&&" + strFormulaB + ">" + strFormulaC);

            Assert.IsTrue(cond2.VerificaCondicao(candle, ts));
            candle.SetValor(strFormulaC, 30);
            Assert.IsFalse(cond2.VerificaCondicao(candle, ts));
            candle.SetValor(strFormulaC, 5);
            Assert.IsTrue(cond2.VerificaCondicao(candle, ts));
            candle.SetValor(strFormulaA, 10);
            Assert.IsFalse(cond2.VerificaCondicao(candle, ts));
        }
        /// <summary>
        ///   Generates a <see cref="MarkovDecisionProcess" /> for the model created by <paramref name="createModel" />.
        /// </summary>
        public LabeledTransitionMarkovDecisionProcess GenerateLabeledTransitionMarkovDecisionProcess()
        {
            Requires.That(IntPtr.Size == 8, "Model checking is only supported in 64bit processes.");

            ProbabilityMatrixCreationStarted = true;

            FormulaManager.Calculate(Configuration);
            var stateFormulasToCheckInBaseModel = FormulaManager.StateFormulasToCheckInBaseModel.ToArray();

            ExecutedModel <TExecutableModel> model = null;
            var modelCreator = _runtimeModelCreator.CreateCoupledModelCreator(stateFormulasToCheckInBaseModel);
            Func <AnalysisModel> createAnalysisModelFunc = () =>
                                                           model = new LtmdpExecutedModel <TExecutableModel>(modelCreator, Configuration);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);

            var ltmdp = GenerateLtmdp(createAnalysisModel);

            return(ltmdp);
        }
Beispiel #18
0
        private static void validaFormulaMMS(Ativo ativo, FormulaManager fm, string fonte, int periodos)
        {
            string  codigoFormula = "MMS(" + fonte + "," + periodos + ")";
            Formula formulaMMS    = fm.GetFormula(codigoFormula);

            Assert.IsNotNull(formulaMMS);
            Assert.IsTrue(formulaMMS.GetCode() == codigoFormula, formulaMMS.GetCode() + "<>" + codigoFormula);

            float  soma   = 0;
            Candle candle = ativo.firstCandle;

            for (int i = 0; i < 10; i++)
            {
                candle = candle.proximoCandle;
            }
            for (int i = 0; i < periodos; i++)
            {
                soma  += candle.GetValor(fonte);
                candle = candle.proximoCandle;
            }
            soma   = soma / periodos;
            candle = candle.candleAnterior;
            Assert.IsTrue(Math.Abs(candle.GetValor(codigoFormula) - soma) < 0.1f, candle.GetValor(codigoFormula) + "<>" + soma);
        }
Beispiel #19
0
 public float getProduction()
 {
     return(FormulaManager.productionFormula(baseProduction, level, multiplier));
 }
Beispiel #20
0
 public float getCost()
 {
     return(FormulaManager.costFormula(baseCost, level, coefficient));
 }
 public FacadeBacktester()
 {
     dm             = new DataLoader(this);
     dh             = new DataHolder(this);
     formulaManager = new FormulaManager(this);
 }
Beispiel #22
0
        public void FinishStats(FormulaManager fm, Carteira carteira)
        {
            TradeSystem tradeSystem = carteira.tradeSystem;

            if (ERROR_STOP_0)
            {
                fitness -= PENALTY * 100;
                carteira.tradeSystem.AddError("Stop 0");
            }
            if (ERROR_VLR_STOP_ERRADO)
            {
                fitness -= PENALTY * 100;
            }
            if (ERROR_DISTANCIA_SUPERADA > 0)
            {
                fitness -= PENALTY * ERROR_DISTANCIA_SUPERADA * 100;
            }

            //O tradesystem tentou entrar em todo candle... o que é ruim...
            if (tentouEntrarTodoCandle)
            {
                fitness -= PENALTY * 10000;
                carteira.tradeSystem.AddError("Tentou entrar em todo candle (condicao entrada sempre true)");
            }

            //tentou usar um de sizing fora do range 0 a 100
            if (flagSizingForaRange)
            {
                fitness -= PENALTY * 1000;
                carteira.tradeSystem.AddError("Sizing fora do range");
            }



            if (qtdTrades == 0)
            {
                fitness -= PENALTY * 10000f;
                carteira.tradeSystem.AddError("Zero trades Gerados");
            }

            fitness += qtdTradesGanhadores * BONUS * 10f;

            if (qtdTradesGanhadores < QTD_MINIMA_TRADES / 4)
            {
                fitness -= PENALTY * 10000f;
                carteira.tradeSystem.AddWarning("Qtd. Trades Ganhadores muito baixa.");
            }

            bool viciadaCompra = carteira.config.flagCompra && ((tradeSystem.usaStopMovel && clarify.VerificaFormulaViciada(fm, tradeSystem.stopMovelC)) || clarify.VerificaFormulaViciada(fm, tradeSystem.condicaoEntradaC) || clarify.VerificaFormulaViciada(fm, tradeSystem.stopInicialC));
            bool viciadaVenda  = carteira.config.flagVenda && ((tradeSystem.usaStopMovel && clarify.VerificaFormulaViciada(fm, tradeSystem.stopMovelV)) || clarify.VerificaFormulaViciada(fm, tradeSystem.condicaoEntradaV) || clarify.VerificaFormulaViciada(fm, tradeSystem.stopInicialV));

            if (viciadaCompra || viciadaVenda)
            {
                fitness -= PENALTY * 10000f;
                carteira.tradeSystem.AddError("TradeSystem dependendo de números para gerar resultados.");
            }

            //TODO: Rever essa conta... acho que está prejudicando os que começam a dar lucro...

            /* if (global.maxCapital > carteira.capitalInicial)
             * {
             *   float difMaxCapital = (global.maxCapital - carteira.GetCapital()) * 10;
             *   fitness -= difMaxCapital;
             * }*/

            //Conta a variedade nas ações ganhadoras: acerta 2 ações é melhor que 1 ação
            fitness += CalcBonusVariedade(carteira);



            float difCapital = carteira.GetCapital() - carteira.capitalInicial;

            fitness += BONUS * difCapital / 1000;
            if (difCapital <= 0)
            {
                fitness -= PENALTY * 100;
            }

            fitness += VerificaNumerosFormula(carteira);


            int difTrades = QTD_MINIMA_TRADES - qtdTrades;

            if (difTrades > 0)
            {
                fitness -= PENALTY * difTrades * 1000;
                carteira.tradeSystem.AddWarning("Não atingiu a quantidade mínima de trades.");
            }
            else if (difCapital > 0)
            {
                fitness += percAcerto * BONUS * 100;
            }

            /*//só dou bonus de acerto para os que estiverem acima do objetivo de qtd minima de trades
             * if (difTrades == 0)
             * {
             *  FitnessQtdAcoes();
             *  FitnessPercUsoCapital();
             *  fitness += BONUS * percAcerto / 10;
             *  float avgDias = global.getGeral().getAmbasPontas().getTodosTrades().getAvgDias();
             *  //bonus até 50 dias...
             *  if (avgDias < AVG_DIAS_GOAL)
             *  {
             *      fitness += BONUS;
             *  }
             * }
             */



            fitness /= 1000;
        }
Beispiel #23
0
 public void UpdateFormulaDeletedSheetReferenceEmptySheetNameThrowsException()
 {
     var    formulaManager = new FormulaManager();
     string actualFormula  = formulaManager.UpdateFormulaDeletedSheetReferences("CONCATENATE(Sheet1!B2, Sheet2!C3)", string.Empty);
 }
Beispiel #24
0
 public float getOutputPerSecond()
 {
     return(FormulaManager.productionFormula(outputPerSecond, level, multiplier));
 }
Beispiel #25
0
        public void UpdateFormulaSheetReferencesNullOldSheetThrowsException()
        {
            var formulaManager = new FormulaManager();

            formulaManager.UpdateFormulaSheetReferences("formula", null, "sheet2");
        }
Beispiel #26
0
        public void TestaFormulasDiretamente()
        {
            facade = new FacadeBacktester();
            FormulaManager fm = facade.formulaManager;

            facade.LoadAtivo("PETR4", 100, Consts.PERIODO_ACAO.DIARIO, "dados/petr4-diario.js");
            Ativo   ativo   = facade.GetAtivo("PETR4");
            Formula fTeste  = new Formula(facade, "TESTE");
            Formula fTeste2 = new Formula(facade, "TESTE2");

            Formula f      = new FormulaPercentil(facade, "PERCENTIL", fTeste);
            Candle  candle = ativo.firstCandle;

            candle.SetValor("TESTE", candle.GetValor(FormulaManager.LOW));
            Assert.IsTrue(f.Calc(candle) == 0, f.Calc(candle) + " <> " + 0);
            candle.SetValor("TESTE", candle.GetValor(FormulaManager.HIGH));
            Assert.IsTrue(f.Calc(candle) == 1, f.Calc(candle) + " <> " + 1);

            f = new FormulaMultiply(facade, "MULT", fTeste, 10);
            candle.SetValor(fTeste, 10);
            Assert.IsTrue(f.Calc(candle) == 100, f.Calc(candle) + " <> " + 100);
            candle.SetValor(fTeste, 5);
            Assert.IsTrue(f.Calc(candle) == 50, f.Calc(candle) + " <> " + 50);

            f = new FormulaSUM(facade, "MULT", fTeste, fTeste2);
            candle.SetValor(fTeste2, 10);
            Assert.IsTrue(f.Calc(candle) == 15, f.Calc(candle) + " <> " + 15);

            //HV e LV
            Candle  candle2 = candle.proximoCandle;
            Candle  candle3 = candle2.proximoCandle;
            Candle  candle4 = candle3.proximoCandle;
            Formula fHV     = new FormulaHV(facade, "HV", fm.GetFormula(FormulaManager.HIGH), fTeste2);
            Formula fLV     = new FormulaLV(facade, "LV", fm.GetFormula(FormulaManager.HIGH), fTeste2);

            candle4.SetValor(fTeste2, 3);
            float  max = candle4.GetValor(fm.GetFormula(FormulaManager.HIGH));
            float  low = candle4.GetValor(fm.GetFormula(FormulaManager.HIGH));
            Candle c   = candle4;

            for (int i = 0; i < 3; i++)
            {
                float value = c.GetValor(fm.GetFormula(FormulaManager.HIGH));
                if (value > max)
                {
                    max = value;
                }
                if (value < low)
                {
                    low = value;
                }
                c = c.candleAnterior;
            }
            Assert.IsTrue(max == fHV.Calc(candle4), max + "<>" + fHV.Calc(candle4));
            Assert.IsTrue(low == fLV.Calc(candle4), max + "<>" + fLV.Calc(candle4));

            //REF
            f = new FormulaREF(facade, "REF", fTeste, fTeste2);
            candle4.SetValor(fTeste, 10);
            candle3.SetValor(fTeste, 20);
            candle2.SetValor(fTeste, 30);
            candle4.SetValor(fTeste2, 1);
            Assert.IsTrue(20 == f.Calc(candle4));
            candle4.SetValor(fTeste2, 2);
            Assert.IsTrue(30 == f.Calc(candle4));
        }
Beispiel #27
0
        public void UpdateFormulaSheetReferencesEmptyOldSheetThrowsException()
        {
            var formulaManager = new FormulaManager();

            formulaManager.UpdateFormulaSheetReferences("formula", string.Empty, "sheet2");
        }
Beispiel #28
0
        private void ValidaClarifyViciado(Clarify clarify, string formula, bool esperado)
        {
            FormulaManager fm = facade.formulaManager;

            Assert.IsTrue(clarify.VerificaFormulaViciada(fm, formula) == esperado, "Formula '" + formula + "' retornou diferente de " + esperado);
        }
Beispiel #29
0
        public Output Get(Input input)
        {
            FormulaManager manager = new FormulaManager();

            return(manager.Identify(input));
        }
Beispiel #30
0
        public RodSetOutput CalculateRodset(RodSetInput input)
        {
            FormulaManager manager = new FormulaManager();

            return(manager.Identify(input));
        }