Esempio n. 1
0
 /// <summary>
 /// Create a simple JSON holdings from a Security holding class.
 /// </summary>
 /// <param name="holding"></param>
 public Holding(Securities.SecurityHolding holding)
 {
     this.Symbol       = holding.Symbol;
     this.Quantity     = holding.Quantity;
     this.AveragePrice = holding.AveragePrice;
     this.MarketPrice  = holding.Price;
 }
Esempio n. 2
0
 /// <summary>
 /// Create a simple JSON holdings from a Security holding class.
 /// </summary>
 /// <param name="holding"></param>
 public Holding(Securities.SecurityHolding holding)
 {
     Symbol       = holding.Symbol;
     Quantity     = holding.Quantity;
     AveragePrice = holding.AveragePrice;
     MarketPrice  = holding.Price;
 }
Esempio n. 3
0
        /********************************************************
         * CONSTRUCTOR/DELEGATE DEFINITIONS
         *********************************************************/
        /// <summary>
        /// Construct the Market Vehicle
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours)
        {
            //Set Basics:
            this._symbol                = symbol;
            this._type                  = type;
            this._resolution            = resolution;
            this._isFillDataForward     = fillDataForward;
            this._leverage              = leverage;
            this._isExtendedMarketHours = extendedMarketHours;

            //Holdings for new Vehicle:
            Cache    = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();

            //Cannot initalise a default model.
            Model = null;

            //Set data type:
            if (resolution == Resolution.Minute || resolution == Resolution.Second)
            {
                _dataType = typeof(TradeBar);
            }
            else
            {
                _dataType = typeof(Tick);
            }
        }
Esempio n. 4
0
        /********************************************************
         * CONSTRUCTOR/DELEGATE DEFINITIONS
         *********************************************************/
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours, bool useQuantConnectData = false)
        {
            //Set Basics:
            _symbol                = symbol;
            _type                  = type;
            _resolution            = resolution;
            _isFillDataForward     = fillDataForward;
            _leverage              = leverage;
            _isExtendedMarketHours = extendedMarketHours;
            _isQuantConnectData    = useQuantConnectData;

            //Setup Transaction Model for this Asset
            switch (type)
            {
            case SecurityType.Equity:
                Model      = new EquityTransactionModel();
                DataFilter = new EquityDataFilter();
                break;

            case SecurityType.Forex:
                Model      = new ForexTransactionModel();
                DataFilter = new ForexDataFilter();
                break;

            case SecurityType.Base:
                Model      = new SecurityTransactionModel();
                DataFilter = new SecurityDataFilter();
                break;
            }

            //Holdings for new Vehicle:
            Cache    = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();
        }
Esempio n. 5
0
        /********************************************************
         * CONSTRUCTOR/DELEGATE DEFINITIONS
         *********************************************************/
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(string symbol, SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false)
        {
            //Set Basics:
            _symbol = symbol;
            _config = config;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            //Setup Transaction Model for this Asset
            switch (config.Security)
            {
            case SecurityType.Equity:
                Model      = new EquityTransactionModel();
                DataFilter = new EquityDataFilter();
                break;

            case SecurityType.Forex:
                Model      = new ForexTransactionModel();
                DataFilter = new ForexDataFilter();
                break;

            case SecurityType.Base:
                Model      = new SecurityTransactionModel();
                DataFilter = new SecurityDataFilter();
                break;
            }

            //Holdings for new Vehicle:
            Cache    = new SecurityCache();
            Holdings = new SecurityHolding(symbol, _config.Security, leverage, Model);
            Exchange = new SecurityExchange();
        }
Esempio n. 6
0
        /********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct the Market Vehicle
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours)
        {
            //Set Basics:
            this._symbol = symbol;
            this._type = type;
            this._resolution = resolution;
            this._isFillDataForward = fillDataForward;
            this._leverage = leverage;
            this._isExtendedMarketHours = extendedMarketHours;

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();

            //Cannot initalise a default model.
            Model = null;

            //Set data type:
            if (resolution == Resolution.Minute || resolution == Resolution.Second) {
                _dataType = typeof(TradeBar);
            } else {
                _dataType = typeof(Tick);
            }
        }
        /********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct the Market Vehicle
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours, bool useQuantConnectData = false)
        {
            //Set Basics:
            this._symbol = symbol;
            this._type = type;
            this._resolution = resolution;
            this._isFillDataForward = fillDataForward;
            this._leverage = leverage;
            this._isExtendedMarketHours = extendedMarketHours;
            this._isQuantConnectData = useQuantConnectData;

            //Setup Transaction Model for this Asset
            switch (type)
            {
                case SecurityType.Equity:
                    Model = new EquityTransactionModel();
                    break;
                case SecurityType.Forex:
                    Model = new ForexTransactionModel();
                    break;
                case SecurityType.Base:
                    Model = new SecurityTransactionModel();
                    break;
            }

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();
        }
 /// <summary>
 /// Create a new holding class instance copying the initial properties
 /// </summary>
 /// <param name="holding">The security being held</param>
 protected SecurityHolding(SecurityHolding holding)
 {
     _security        = holding._security;
     _averagePrice    = holding._averagePrice;
     _quantity        = holding._quantity;
     _price           = holding._price;
     _totalSaleVolume = holding._totalSaleVolume;
     _profit          = holding._profit;
     _lastTradeProfit = holding._lastTradeProfit;
     _totalFees       = holding._totalFees;
 }
Esempio n. 9
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage)
        {
            _config = config;

            Cache = new SecurityCache();
            Exchange = new SecurityExchange(exchangeHours);
            DataFilter = new SecurityDataFilter();
            PortfolioModel = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel = new SecurityMarginModel(leverage);
            Holdings = new SecurityHolding(this);
        }
Esempio n. 10
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage)
        {
            _config = config;

            Cache            = new SecurityCache();
            Exchange         = new SecurityExchange(exchangeHours);
            DataFilter       = new SecurityDataFilter();
            PortfolioModel   = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel      = new SecurityMarginModel(leverage);
            Holdings         = new SecurityHolding(this);
        }
Esempio n. 11
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           IBuyingPowerModel buyingPowerModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel,
                           ICurrencyConverter currencyConverter,
                           IRegisteredSecurityDataTypesProvider registeredTypesProvider
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException(nameof(symbolProperties), "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            this._currencyConverter = currencyConverter;

            Symbol              = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            BuyingPowerModel    = buyingPowerModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this, currencyConverter);
            Data              = new DynamicSecurityData(registeredTypesProvider);
            Cache.DataStored += (sender, args) => Data.StoreData(args.DataType, args.Data);

            UpdateSubscriptionProperties();
        }
Esempio n. 12
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false)
        {
            _config = config;
            _symbol = config.Symbol;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            Cache = new SecurityCache();
            Exchange = new SecurityExchange();
            DataFilter = new SecurityDataFilter();
            PortfolioModel = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel = new SecurityMarginModel(leverage);
            Holdings = new SecurityHolding(this);
        }
Esempio n. 13
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false)
        {
            _config = config;
            _symbol = config.Symbol;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            Cache            = new SecurityCache();
            Exchange         = new SecurityExchange(exchangeHours);
            DataFilter       = new SecurityDataFilter();
            PortfolioModel   = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel      = new SecurityMarginModel(leverage);
            Holdings         = new SecurityHolding(this);
        }
Esempio n. 14
0
        /// <summary>
        /// Create a simple JSON holdings from a Security holding class.
        /// </summary>
        /// <param name="holding">Holdings object we'll use to initialize the transport</param>
        /// <param name="type">Type of the asset holding</param>
        public Holding(Securities.SecurityHolding holding, SecurityType type)
        {
            Symbol   = holding.Symbol;
            Quantity = holding.Quantity;

            var rounding = 2;

            if (type == SecurityType.Forex)
            {
                rounding = 4;
            }

            AveragePrice = Math.Round(holding.AveragePrice, rounding);
            MarketPrice  = Math.Round(holding.Price, rounding);
        }
Esempio n. 15
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           IBuyingPowerModel buyingPowerModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            Symbol              = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            BuyingPowerModel    = buyingPowerModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this);

            UpdateSubscriptionProperties();
        }
Esempio n. 16
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           ISecurityMarginModel marginModel,
                           ISecurityDataFilter dataFilter
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config          = config;
            QuoteCurrency    = quoteCurrency;
            SymbolProperties = symbolProperties;
            IsTradable       = !config.IsInternalFeed;
            Cache            = cache;
            Exchange         = exchange;
            DataFilter       = dataFilter;
            PortfolioModel   = portfolioModel;
            MarginModel      = marginModel;
            FillModel        = fillModel;
            FeeModel         = feeModel;
            SlippageModel    = slippageModel;
            SettlementModel  = settlementModel;
            VolatilityModel  = volatilityModel;
            Holdings         = new SecurityHolding(this);
        }
Esempio n. 17
0
        /// <summary>
        /// Create a simple JSON holdings from a Security holding class.
        /// </summary>
        /// <param name="holding">Holdings object we'll use to initialize the transport</param>
        public Holding(Securities.SecurityHolding holding)
            : this()
        {
            Symbol   = holding.Symbol;
            Type     = holding.Type;
            Quantity = holding.Quantity;

            var rounding = 2;

            if (holding.Type == SecurityType.Forex)
            {
                rounding = 5;
                string basec, quotec;
                Forex.DecomposeCurrencyPair(holding.Symbol, out basec, out quotec);
                CurrencySymbol = Forex.CurrencySymbols[quotec];
                ConversionRate = ((ForexHolding)holding).ConversionRate;
            }

            AveragePrice = Math.Round(holding.AveragePrice, rounding);
            MarketPrice  = Math.Round(holding.Price, rounding);
        }
Esempio n. 18
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    ISecurityMarginModel marginModel,
                    ISecurityDataFilter dataFilter
                    )
 {
     _config         = config;
     Cache           = cache;
     Exchange        = exchange;
     DataFilter      = dataFilter;
     PortfolioModel  = portfolioModel;
     MarginModel     = marginModel;
     FillModel       = fillModel;
     FeeModel        = feeModel;
     SlippageModel   = slippageModel;
     SettlementModel = settlementModel;
     Holdings        = new SecurityHolding(this);
 }
Esempio n. 19
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
     SecurityExchange exchange,
     SecurityCache cache,
     ISecurityPortfolioModel portfolioModel,
     IFillModel fillModel,
     IFeeModel feeModel,
     ISlippageModel slippageModel,
     ISettlementModel settlementModel,
     ISecurityMarginModel marginModel,
     ISecurityDataFilter dataFilter
     )
 {
     _config = config;
     Cache = cache;
     Exchange = exchange;
     DataFilter = dataFilter;
     PortfolioModel = portfolioModel;
     MarginModel = marginModel;
     FillModel = fillModel;
     FeeModel = feeModel;
     SlippageModel = slippageModel;
     SettlementModel = settlementModel;
     Holdings = new SecurityHolding(this);
 }
Esempio n. 20
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            IVolatilityModel volatilityModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter,
            IPriceVariationModel priceVariationModel
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _symbol = symbol;
            SubscriptionsBag = new ConcurrentBag<SubscriptionDataConfig>();
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            IsTradable = true;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            VolatilityModel = volatilityModel;
            Holdings = new SecurityHolding(this);
        }
Esempio n. 21
0
        /********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours, bool isDynamicallyLoadedData = false)
        {
            //Set Basics:
            _symbol = symbol;
            _type = type;
            _resolution = resolution;
            _isFillDataForward = fillDataForward;
            _leverage = leverage;
            _isExtendedMarketHours = extendedMarketHours;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            //Setup Transaction Model for this Asset
            switch (type)
            {
                case SecurityType.Equity:
                    Model = new EquityTransactionModel();
                    DataFilter = new EquityDataFilter();
                    break;
                case SecurityType.Forex:
                    Model = new ForexTransactionModel();
                    DataFilter = new ForexDataFilter();
                    break;
                case SecurityType.Base:
                    Model = new SecurityTransactionModel();
                    DataFilter = new SecurityDataFilter();
                    break;
            }

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, type, Model);
            Exchange = new SecurityExchange();
        }
Esempio n. 22
0
        /// <summary>
        /// Create a simple JSON holdings from a Security holding class.
        /// </summary>
        /// <param name="holding">Holdings object we'll use to initialize the transport</param>
        public Holding(SecurityHolding holding)
             : this()
        {
            Symbol = holding.Symbol;
            Type = holding.Type;
            Quantity = holding.Quantity;

            var rounding = 2;
            if (holding.Type == SecurityType.Forex)
            {
                rounding = 5;
                string basec, quotec;
                Forex.DecomposeCurrencyPair(holding.Symbol.Value, out basec, out quotec);
                CurrencySymbol = Forex.CurrencySymbols[quotec];
                ConversionRate = ((ForexHolding) holding).ConversionRate;
            }

            AveragePrice = Math.Round(holding.AveragePrice, rounding);
            MarketPrice = Math.Round(holding.Price, rounding);
        }
Esempio n. 23
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config = config;
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            Holdings = new SecurityHolding(this);
        }
Esempio n. 24
0
        public Sig10Strategy(SecurityHolding sym, Indicator priceIdentity, int trendPeriod, decimal lossThreshhold, decimal tolerance, decimal revertPct)
        {

            trendArray = new decimal[trendPeriod + 1];       // initialized to 0.  Add a period for Deserialize to make IsReady true

            symbol = sym.Symbol;
            _holding = sym;
            _price = priceIdentity;
            _period = trendPeriod;
            _lossThreshhold = lossThreshhold;
            _tolerance = tolerance;
            RevPct = revertPct;
            Trend = new InstantaneousTrend(sym.Symbol.Value, 7, .24m).Of(priceIdentity);
            TrendMomentum = new Momentum(2).Of(Trend);
            MomentumWindow = new RollingWindow<decimal>(2);
            ActualSignal = OrderSignal.doNothing;

            Trend.Updated += (object sender, IndicatorDataPoint updated) =>
            {
                Barcount++;
                UpdateTrendArray(Trend.Current.Value);
                nTrig = Trend.Current.Value;
                if (Trend.IsReady)
                {
                    TrendMomentum.Update(Trend.Current);
                }
                if (TrendMomentum.IsReady) 
                    MomentumWindow.Add(TrendMomentum.Current.Value);
                if (MomentumWindow.IsReady) 
                    CheckSignal();
            };
        }