I realized that my strategies are far different than other people's, so that
should be mentioned first.  I do intra-day trading based on things like
limits and stops that are based on daily open and close prices.  I optimize
these limit prices with the parameters.

My indicators do not change with the parameters, so they are the same for
each permutation of the parameters.  This is probably very different than
most of you, but I was able to make it work for me and give me some nice
benefits (do the most you can with what you have).

If you can assume the indicators are the same for every instance of the
strategy at time = t, then you only need 1 indicator manager running 1 copy
of your indicators.  I was able to leverage this for speeding up my
optimizations.

First step is to modify Strategy  class so that you can set the
IndicatorManager and Trading Schedule class instances:

    public void reassignIndicatorManager(IndicatorManager indicatorManager)
    {
        this.indicatorManager = indicatorManager;
    }

    public void reassignTradingSchedule(TradingSchedule sched)
    {
        this.tradingSchedule = sched;
    }

The next mod needs to be done so that you can set the indicator class
instance in your strategy subclass.  Right now this has to be custom coded
for each strategy, and is really nasty.  Here is an example from my strategy
I am working on:

    public void ReassignVolitilityIndicator(volitilityIndicator ind)
    {
        this.volitilityInd = ind;
    }

Now, with this, you can do the reassignments necessary from the
OptimizerWorker.  This code, for the reasons I explained in the previous
snippet, only works for this one strategy,  and would need to be changed to
optimize a different strategy:


public class OptimizerWorker implements Callable<List<OptimizationResult>> {
    private final OptimizerRunner optimizerRunner;
    private final List<Strategy> strategies;

    public OptimizerWorker(OptimizerRunner optimizerRunner, List<Strategy>
strategies) {
        this.optimizerRunner = optimizerRunner;
        this.strategies = strategies;
    }

    public List<OptimizationResult> call() {
        List<OptimizationResult> optimizationResults = new
ArrayList<OptimizationResult>();
        int size = strategies.size();
        MarketBook marketBook = new MarketBook();
        TradingSchedule tradingSchedule =
strategies.get(0).getTradingSchedule();
        //added
        IndicatorManager indicatorManager =
strategies.get(0).getIndicatorManager();

        for (Strategy strategy : strategies) {
            strategy.setMarketBook(marketBook);
            //added
            strategy.reassignTradingSchedule(tradingSchedule);
            strategy.reassignIndicatorManager(indicatorManager);
            ((MyStrategy)strategy).ReassignVolitilityIndicator(
(volitilityIndicator)indicatorManager.getIndicators().get(0));
        }

        List<MarketSnapshot> snapshots = optimizerRunner.getSnapshots();
        for (MarketSnapshot marketSnapshot : snapshots) {
            marketBook.setSnapshot(marketSnapshot);
            long time = marketSnapshot.getTime();

            //added
            tradingSchedule.updateBoolInTradingSchedule(time);

//            boolean inSchedule = tradingSchedule.contains(time);
            boolean inSchedule = tradingSchedule.getInTradingSchedule();
            indicatorManager.updateIndicators();

            for (Strategy strategy : strategies) {
                strategy.setTime(time);
//                IndicatorManager indicatorManager =
strategy.getIndicatorManager();
//                indicatorManager.updateIndicators();

                //added
                strategy.onBookChange();

                if (inSchedule) {
                    if (indicatorManager.hasValidIndicators()) {
                        //strategy.onBookChange();
                    }
                } else {
                    strategy.closePosition();// force flat position
                }

                strategy.getPositionManager().trade();

            }

            optimizerRunner.iterationsCompleted(size);
            if (optimizerRunner.isCancelled()) {
                break;
            }
        }

        int minTrades = optimizerRunner.getMinTrades();
        for (Strategy strategy : strategies) {
            strategy.closePosition();
            strategy.getPositionManager().trade();


            PerformanceManager performanceManager =
strategy.getPerformanceManager();
            int trades = performanceManager.getTrades();
            if (trades >= minTrades) {
                OptimizationResult optimizationResult = new
OptimizationResult(strategy.getParams(), performanceManager);
                optimizationResults.add(optimizationResult);
            }
        }

        return optimizationResults;
    }
}










On Tue, Jul 28, 2009 at 6:27 AM, Eugene Kononov <[email protected]>wrote:

>
> This looks like some important work, but I can't say that I completely
>> follow you, Shaggs.  Eugene, are you following along here?
>>
>
>
> I am not following either. Shaggs, can you please post your code?
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"JBookTrader" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jbooktrader?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to