Esempio n. 1
0
        public override void OnConfigure()
        {
            changeActiveNow.OnInitialize();
            changeNextBar.OnInitialize();
            reverseActiveNow.OnInitialize();
            reverseNextBar.OnInitialize();
            exitActiveNow.OnInitialize();
            enterActiveNow.OnInitialize();
            exitNextBar.OnInitialize();
            enterNextBar.OnInitialize();
            exitNextBar.OnInitialize();
            base.OnConfigure();

            BreakPoint.TrySetStrategy(this);
            AddInterceptor(preFillManager);
            AddInterceptor(performance.Equity);
            AddInterceptor(performance);
            AddInterceptor(exitStrategy);
            AddInterceptor(postFillManager);
        }
Esempio n. 2
0
        public sealed override void OnConfigure()
        {
            BreakPoint.TrySetStrategy(this);
            base.OnConfigure();
            AddInterceptor(performance.Equity);
            AddInterceptor(performance);
            do
            {
                // Count all the unique symbols used by dependencies and
                // get a list of all the strategies.
                strategies = new List <Strategy>();
                portfolios = new List <Portfolio>();
                Dictionary <string, List <Model> > symbolMap = new Dictionary <string, List <Model> >();
                for (int i = 0; i < Chain.Dependencies.Count; i++)
                {
                    Chain chain = Chain.Dependencies[i];
                    if (chain.Model is Strategy || chain.Model is Portfolio)
                    {
                        Model        model = (Model)chain.Model;
                        List <Model> tempModels;
                        if (symbolMap.TryGetValue(model.SymbolDefault, out tempModels))
                        {
                            tempModels.Add(model);
                        }
                        else
                        {
                            tempModels = new List <Model>();
                            tempModels.Add(model);
                            symbolMap[model.SymbolDefault] = tempModels;
                        }
                        if (model is Strategy)
                        {
                            strategies.Add((Strategy)model);
                        }
                        else if (model is Portfolio)
                        {
                            portfolios.Add((Portfolio)model);
                        }
                    }
                }
                if (symbolMap.Count == 1)
                {
                    portfolioType = PortfolioType.SingleSymbol;
                }
                else if (symbolMap.Count == (strategies.Count + portfolios.Count))
                {
                    portfolioType = PortfolioType.MultiSymbol;
                }
                else
                {
                    // Remove all dependencies which have more than one obect.
                    for (int i = Chain.Dependencies.Count - 1; i >= 0; i--)
                    {
                        Chain chain = Chain.Dependencies[i];
                        Chain.Dependencies.RemoveAt(i);
                    }
                    // There is a mixture of multi symbols and multi strategies per symbol.
                    // Insert additional Portfolios for each symbol.
                    foreach (var kvp in symbolMap)
                    {
                        string       symbol         = kvp.Key;
                        List <Model> tempStrategies = kvp.Value;
                        if (tempStrategies.Count > 1)
                        {
                            Portfolio portfolio = new Portfolio();
                            portfolio.Name            = "AutoGen-Portfolio-" + symbol;
                            portfolio.SymbolDefault   = symbol;
                            portfolio.IntervalDefault = IntervalDefault;
                            portfolio.Performance.Equity.EnableDailyStats   = Performance.Equity.EnableDailyStats;
                            portfolio.Performance.Equity.EnableWeeklyStats  = Performance.Equity.EnableWeeklyStats;
                            portfolio.Performance.Equity.EnableMonthlyStats = Performance.Equity.EnableMonthlyStats;
                            portfolio.Performance.Equity.EnableYearlyStats  = Performance.Equity.EnableYearlyStats;

                            foreach (var strategy in tempStrategies)
                            {
                                portfolio.Chain.Dependencies.Add(strategy.Chain);
                            }
                            Chain.Dependencies.Add(portfolio.Chain);
                        }
                        else
                        {
                            Model model = tempStrategies[0];
                            Chain.Dependencies.Add(model.Chain);
                        }
                    }
                }
            } while(portfolioType == PortfolioType.None);

            if (debug)
            {
                log.Debug("Configuring Portfolio " + Name + " for sub strategies/portfolios..");
            }

            // Create strategy watchers
            foreach (var strategy in strategies)
            {
                SetupWatcher(strategy);
            }

            foreach (var portfolio in portfolios)
            {
                SetupWatcher(portfolio);
            }
        }