コード例 #1
0
ファイル: UserDefinedUniverse.cs プロジェクト: rwentzel9/Lean
        /// <summary>
        /// Creates a user defined universe symbol
        /// </summary>
        /// <param name="securityType">The security</param>
        /// <param name="market">The market</param>
        /// <returns>A symbol for user defined universe of the specified security type and market</returns>
        public static Symbol CreateSymbol(SecurityType securityType, string market)
        {
            var ticker = $"qc-universe-userdefined-{market.ToLowerInvariant()}-{securityType}";
            SecurityIdentifier sid;

            switch (securityType)
            {
            case SecurityType.Base:
                sid = SecurityIdentifier.GenerateBase(null, ticker, market);
                break;

            case SecurityType.Equity:
                sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Option:
                var underlying = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlying, market, 0, 0, 0);
                break;

            case SecurityType.FutureOption:
                var underlyingFuture = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingFuture, market, 0, 0, 0);
                break;

            case SecurityType.IndexOption:
                var underlyingIndex = SecurityIdentifier.GenerateIndex(ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingIndex, market, 0, 0, OptionStyle.European);
                break;

            case SecurityType.Forex:
                sid = SecurityIdentifier.GenerateForex(ticker, market);
                break;

            case SecurityType.Cfd:
                sid = SecurityIdentifier.GenerateCfd(ticker, market);
                break;

            case SecurityType.Index:
                sid = SecurityIdentifier.GenerateIndex(ticker, market);
                break;

            case SecurityType.Future:
                sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Crypto:
                sid = SecurityIdentifier.GenerateCrypto(ticker, market);
                break;

            case SecurityType.Commodity:
            default:
                throw new NotImplementedException($"The specified security type is not implemented yet: {securityType}");
            }

            return(new Symbol(sid, ticker));
        }