Question

I am trying to run the SimulationStarted class with the moving average strategy in the open source edition of AlgoTrader.

When I start the SimulationStarter I get ArrayIndexOutOfBoundsException.

I am trying to run it through eclipse. From AlgoTrader they run it with the following command

java.exe -cp target/classes;../../AlgoTrader/code/target/classes;../../AlgoTrader/code/lib/*;target/* -Dsimulation=true -DdataSource.dataSet=1year com.algoTrader.starter.SimulationStarter simulateWithCurrentParams

So is it even possible to run it through eclipse or this is the only way?

If anyone has any ideas or suggestions it will be much appreciated.

Here is the code for the SimulationStarter and ServiceLocator classes.

package com.algoTrader.starter;

import org.apache.commons.math.*;
import org.apache.log4j.Logger;



import com.algoTrader.ServiceLocator;
import com.algoTrader.service.SimulationServiceImpl;
import com.algoTrader.util.MyLogger;

public class SimulationStarter {

    private static Logger logger = MyLogger.getLogger(SimulationServiceImpl.class.getName());

    public static void main(String[] args) throws ConvergenceException, FunctionEvaluationException {

        ServiceLocator.serverInstance().init("beanRefFactorySimulation.xml");

        if ("simulateWithCurrentParams".equals(args[0])) {

            ServiceLocator.serverInstance().getSimulationService().simulateWithCurrentParams();

        } else if ("optimizeSingleParamLinear".equals(args[0])) {

            String strategyName = args[1];
            for (int i = 2; i < args.length; i++) {
                String[] params = args[i].split(":");
                String parameter = params[0];
                double min = Double.parseDouble(params[1]);
                double max = Double.parseDouble(params[2]);
                double increment = Double.parseDouble(params[3]);

                ServiceLocator.serverInstance().getSimulationService().optimizeSingleParamLinear(strategyName, parameter, min, max, increment);

            }
        }

        ServiceLocator.serverInstance().shutdown();
    }
}

And the service locator class

package com.algoTrader;

import com.algoTrader.entity.StrategyImpl;
import com.algoTrader.util.ConfigurationUtil;

public class ServiceLocator {

    private static boolean simulation = ConfigurationUtil.getBaseConfig().getBoolean("simulation");
    private static String strategyName = ConfigurationUtil.getBaseConfig().getString("strategyName");

    public static CommonServiceLocator commonInstance() {

        if (!simulation && !StrategyImpl.BASE.equals(strategyName)) {
            return RemoteServiceLocator.instance();
        } else {
            return ServerServiceLocator.instance();
        }
    }

    public static ServerServiceLocator serverInstance() {

        if (!simulation && !StrategyImpl.BASE.equals(strategyName)) {
            throw new IllegalArgumentException("serverInstance cannot be called from the client");
        } else {
            return ServerServiceLocator.instance();
        }
    }
}
Was it helpful?

Solution

To Fix this error you will need to open the Run Configuraitons in Eclipse and Add the program Arguments and the VM Arguments and the ArrayIndexOutOfBoundsException will be gone.

enter image description here

The bad news are that there is another error: 2014-01-22 11:15:35,771 ERROR JDBCExceptionReporter Access denied for user 'algouser'@'localhost' (using password: YES)

Which I will be investigating now

OTHER TIPS

In order to run AlgoTrader you need to have a database (MySQL) and configure DB in the source code of AlgoTrader. Without DB AlgoTrader does not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top