Esempio n. 1
0
        private static bool IsValidNameCharacter(char c)
        {
            // Valid Characters:  a-z, A-Z, 0-9, /, \, (, ), _, -, ., sp
            const string ValidSymbols = @"/\()_-. ";

            return(char.IsLetterOrDigit(c) || ValidSymbols.Contains(c.ToString()));
        }
Esempio n. 2
0
        public void OnData(TradeBars slice)
        {
            if (tradedToday.Date != Time.Date)
            {
                // leave a small buffer of cash
                var targetPercentage = 1m / (_todaysResponse.Securities.Count + 1);

                foreach (var target in _todaysResponse.Securities.Where(x => ValidSymbols.Contains(x.Ticker)))
                {
                    // rebalance portfolio to equal weights
                    SetHoldings(target.Ticker, targetPercentage);
                }

                tradedToday = Time.Date;
            }
            else
            {
                foreach (var target in _todaysResponse.Securities.Where(x => ValidSymbols.Contains(x.Ticker)))
                {
                    // set stop loss / profit orders
                    var security = Securities[target.Ticker];
                    if (!security.Invested)
                    {
                        continue;
                    }

                    if (security.Close < target.StopLoss || security.Close > target.StopGain)
                    {
                        MarketOrder(target.Ticker, -security.Holdings.Quantity, true);
                    }
                }
            }
        }
Esempio n. 3
0
        public override void Initialize()
        {
            UniverseSettings.Resolution = Resolution.Hour;

            SetStartDate(2015, 01, 05);
            SetEndDate(2015, 11, 09);

            SetCash(1000 * 1000);


            AddUniverse("equities-lab-universe", date =>
            {
                using (var client = new WebClient())
                {
                    //2014-12-30
                    var file                   = client.DownloadString(String.Format(EquitiesLabUrlFormat, EquitiesLabKey, EquitiesLabScreener, date.ToString("yyyy-MM-dd")));
                    var response               = JsonConvert.DeserializeObject <EquitiesLabResponse>(file);
                    _todaysResponse            = new EquitiesLabResponse();
                    _todaysResponse.Securities = response.Securities.Where(x => ValidSymbols.Contains(x.Ticker)).ToList();
                    return(_todaysResponse.Securities.Select(x => x.Ticker));
                }
            });

            // cancell all orders at EOD
            Schedule.Event("Cancel Open Orders").EveryDay().At(TimeSpan.FromHours(16)).Run(() =>
            {
                foreach (var ticket in Transactions.GetOrderTickets(x => x.Status.IsOpen()))
                {
                    ticket.Cancel();
                }
            });
        }
Esempio n. 4
0
 public static bool IsValid(string symbol)
 {
     return(ValidSymbols.Contains(symbol));
 }