Esempio n. 1
0
 private void SetupParamValue(Project prj, string paramName, object val, bool logValue)
 {
     if (prj.Parameters.Contains(paramName))
     {
         if (logValue)
             Console.WriteLine(string.Format("PARAM : {0} [VALUE: {1}]", paramName, val));
         prj.Parameters[paramName].Value = val;
     }
 }
Esempio n. 2
0
        private void SetupInstruments(Project prj)
        {
            string[] symbols = stockSymbols.Split(new char[] { '\n', '\r' });
            prj.ClearInstruments();

            foreach (string symbol in symbols)
            {
                AttachInstrument(prj, symbol);
            }
        }
Esempio n. 3
0
 private void SetupParams(Project prj, Dictionary<string, object> paramsDictionary, bool logValues)
 {
     foreach (string currentParamName in paramsDictionary.Keys)
     {
         object val = paramsDictionary[currentParamName];
         if (null != val && prj.Parameters.Contains(currentParamName))
         {
             SetupParamValue(prj, currentParamName, val, logValues);
         }
     }
 }
Esempio n. 4
0
        public void SetupProject(Project prj)
        {
            SetupInstruments(prj);
            SetupParams(prj, SolutionWideParameters, false);

            //private int? retryInterval;
            //private double? minSlippage;
            //private double? maxSlippage;
            //private string ibAccountNumber;

            var localParamsDictionary = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

            if (executionHour.HasValue)
                localParamsDictionary.Add("ValidityTriggerHour", executionHour.Value);

            if (executionMinute.HasValue)
                localParamsDictionary.Add("ValidityTriggerMinute", executionMinute.Value);

            if (portfolioAmt.HasValue)
                localParamsDictionary.Add("TotalPortfolioAmount", portfolioAmt.Value);

            if (portfolioAllocation.HasValue)
                localParamsDictionary.Add("PositionSizePercentage", portfolioAllocation.Value);

            if (noOfPositions.HasValue)
                localParamsDictionary.Add("NumberOfPortfolioPositions", noOfPositions.Value);

            if (retryInterval.HasValue)
                localParamsDictionary.Add("MaximumIntervalInMinutesBetweenOrderRetries", retryInterval.Value);

            if (minSlippage.HasValue)
                localParamsDictionary.Add("MinAllowedSlippage", minSlippage.Value);

            if (maxSlippage.HasValue)
                localParamsDictionary.Add("MaxAllowedSlippage", maxSlippage.Value);

            if (!string.IsNullOrWhiteSpace(ibAccountNumber))
                localParamsDictionary.Add("IbAccountNumber", ibAccountNumber);

            if (executionHour.HasValue)
                localParamsDictionary.Add("ValidityTriggerHour", executionHour.Value);

            if (fastMaPeriod.HasValue)
                localParamsDictionary.Add("FastMaPeriod", fastMaPeriod.Value);

            if (slowMaPeriod.HasValue)
                localParamsDictionary.Add("SlowMaPeriod", slowMaPeriod.Value);

            if (specificSize.HasValue)
                localParamsDictionary.Add("SpecificPositionSize", specificSize.Value);

            if (specificPosSide.HasValue)
                localParamsDictionary.Add("SpecificPositionSideToReverse", specificPosSide.Value);

            if (ProjectTemplate.Value == ProjectTemplateType.OpenLong)
            {
                localParamsDictionary.Add("OpeningOrderSide", OrderSide.Buy);
            }
            else if (ProjectTemplate.Value == ProjectTemplateType.OpenShort)
            {
                localParamsDictionary.Add("OpeningOrderSide", OrderSide.Sell);
            }
            string projNameForStrategy = "P00";
            if (projIndex.HasValue)
            {
                projNameForStrategy = ProjectTemplate.Value.ToString().ToUpper().Substring(0, 1) +
                                      projIndex.Value.ToString("00");
            }
            localParamsDictionary.Add("ProjectName", projNameForStrategy);

            SetupParams(prj, localParamsDictionary, true);
        }
Esempio n. 5
0
        private void AttachInstrument(Project prj, string symbol)
        {
            if (string.IsNullOrEmpty(symbol))
                return;

            string trimmedSymbol = symbol.Trim();
            string normalizedSymbol = string.Empty;

            if (trimmedSymbol.Length > 0)
            {
                normalizedSymbol = trimmedSymbol.Replace(".", "");
                Instrument currentIns = InstrumentManager.Instruments[normalizedSymbol];

                if (null == currentIns || currentIns.Type != InstrumentType.Stock)
                {
                    Console.WriteLine("ADDING SYMBOL -- " + trimmedSymbol);
                    Instrument newInstrument = new Instrument(InstrumentType.Stock, normalizedSymbol);
                    newInstrument.Currency = defaultCurrency;
                    newInstrument.Exchange = defaultExchange;

                    int dotIdx = trimmedSymbol.IndexOf('.');
                    if (dotIdx > -1)
                    {
                        AltIDGroup ibAltIdGroup = newInstrument.AltIDGroups.Add("IB");
                        ibAltIdGroup.AltSource = "IB";
                        ibAltIdGroup.AltSymbol = trimmedSymbol.Replace(".", " ");
                    }
                }

                currentIns = InstrumentManager.Instruments[normalizedSymbol];
                if (null != currentIns)
                    prj.AddInstrument(currentIns);

            }
        }
Esempio n. 6
0
        private void SetupInstruments(Project prj)
        {
            string[] symbols = stockSymbols
                .Split(new char[] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries)
                .Distinct()
                .ToArray();
            prj.ClearInstruments();

            foreach (string symbol in symbols)
            {
                AttachInstrument(prj, symbol);
            }
        }
Esempio n. 7
0
		public bool TryGetValue(string name, out Project project)
		{
			return this.projects.TryGetValue(name, out project);
		}
Esempio n. 8
0
        private void SetupIwmForStopTriggerIfRequired(Project prj)
        {
            Parameter iwmStopPriceParam = null;
            if (prj.Parameters.Contains(IwmStopPriceTriggerStrategy))
            {
                iwmStopPriceParam = prj.Parameters[IwmStopPriceTriggerStrategy];
                if (null != iwmStopPriceParam)
                {
                    OrderTriggerStrategy ordStrat = (OrderTriggerStrategy)Enum.Parse(typeof(OrderTriggerStrategy), iwmStopPriceParam.Value.ToString(), true);

                    bool isBasedOnIwmStopPrice = ordStrat == OrderTriggerStrategy.IwmStopPriceBasedTrigger;
                    bool isIwmAlreadyAttached = false;

                    foreach (Instrument currentIns in prj.Instruments)
                    {
                        if (SolutionUtility.IsInstrumentIwm(currentIns))
                        {
                            isIwmAlreadyAttached = true;
                            break;
                        }
                    }

                    if (isBasedOnIwmStopPrice)
                    {
                        if (!isIwmAlreadyAttached)
                        {
                            AttachInstrument(prj, "IWM");
                            SetupParamValue(prj, "IsIwmAlsoToBeIncludedInOrder", false, false);
                        }
                        else
                        {
                            SetupParamValue(prj, "IsIwmAlsoToBeIncludedInOrder", true, false);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private void SetupClosingProjectParameters(Project prj, string ibAccountNumber)
        {
            if (prj.Name.StartsWith("CLOSE", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (Instrument currentIns in prj.Instruments)
                {
                    if (!SolutionUtility.IsInstrumentIwm(currentIns))
                    {
                        OrderSide ordSide = SolutionUtility.GetOrderSideToCloseCurrentPosition(currentIns.Symbol, ibAccountNumber);
                        SetupParamValue(prj, "OrderSideForIwmStopTriggerForClosing", ordSide, true);

                        break;
                    }
                }
            }
        }
Esempio n. 10
0
        public void SetupProject(Project prj)
        {
            SetupInstruments(prj);
            SetupParams(prj, ProjectTemplateParameters, false);
            SetupParams(prj, SolutionWideParameters, false);

            var localParamsDictionary = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

            if (executionHour.HasValue)
                ParamsSetterUtility.SetExecutionHour(localParamsDictionary, executionHour.Value);

            if (executionMinute.HasValue)
                ParamsSetterUtility.SetExecutionMinute(localParamsDictionary, executionMinute.Value);

            if (portfolioAmt.HasValue)
                localParamsDictionary.Add("GrandTotalPortfolioAmount", portfolioAmt.Value);

            if (portfolioAllocation.HasValue)
                localParamsDictionary.Add("PortfolioAllocationPercentage", portfolioAllocation.Value);

            if (noOfPositions.HasValue)
                localParamsDictionary.Add("NumberOfPortfolioPositions", noOfPositions.Value);

            if (maxPortfolioRisk.HasValue)
                localParamsDictionary.Add("MaxPortfolioRisk", maxPortfolioRisk.Value);

            if (maxPositionRisk.HasValue)
                localParamsDictionary.Add("MaxPositionRisk", maxPositionRisk.Value);

            if (riskAppetiteStrategy.HasValue)
                localParamsDictionary.Add("RiskAppetiteStrategy", riskAppetiteStrategy.Value);

            if (noOfRetries.HasValue)
            {
                if (noOfRetries.Value <= 0)
                {
                    localParamsDictionary.Add("OrderRetrialStrategy", OrderRetrialStrategy.None);
                    localParamsDictionary.Add("MaximumRetries", 0);
                }
                else
                {

                    localParamsDictionary.Add("MaximumRetries", noOfRetries.Value);
                }
            }

            if (retryInterval.HasValue)
                localParamsDictionary.Add("RetryTriggerIntervalMinute", retryInterval.Value);

            if(minSlippage.HasValue)
                localParamsDictionary.Add("MinAllowedSlippage", minSlippage.Value);

            if (maxSlippage.HasValue)
                localParamsDictionary.Add("MaxAllowedSlippage", maxSlippage.Value);

            if (stopTriggerAtr.HasValue)
            {
                localParamsDictionary.Add("IwmCalculatedStopAtrCoefficient", stopTriggerAtr.Value);
                localParamsDictionary.Add("CalculatedStopAtrCoefficient", stopTriggerAtr.Value);
            }
            if (gapTriggerAtr.HasValue)
            {
                localParamsDictionary.Add("IwmOpeningGapAtrCoefficient", gapTriggerAtr.Value);
                localParamsDictionary.Add("OpeningGapAtrCoefficient", gapTriggerAtr.Value);
            }

            if (SolutionWideParameters.ContainsKey("IbBrokerAccountNumber"))
            {
                object tempAccountNumber = SolutionWideParameters["IbBrokerAccountNumber"].ToString();
                if (null != tempAccountNumber)
                {
                    ibAccountNumber = tempAccountNumber.ToString();
                }
            }

            if (string.IsNullOrWhiteSpace(ibAccountNumber))
            {
                throw new ArgumentNullException("IbBrokerAccountNumber", "!!!! IB ACCOUNT NUMBER NOT PROVIDED. !!!!");

            }

            SetupClosingProjectParameters(prj, ibAccountNumber);
            SetupIwmForStopTriggerIfRequired(prj);

            SetupParams(prj, localParamsDictionary, true);
        }