/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { SetStartDate(2013, 10, 07); //Set Start Date SetEndDate(2013, 10, 11); //Set End Date SetCash(100000); //Set Strategy Cash // Find more symbols here: http://quantconnect.com/data AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute); // events are scheduled using date and time rules // date rules specify on what dates and event will fire // time rules specify at what time on thos dates the event will fire // schedule an event to fire at a specific date/time Schedule.On(DateRules.On(2013, 10, 7), TimeRules.At(13, 0), () => { Log("SpecificTime: Fired at : " + Time); }); // schedule an event to fire every trading day for a security // the time rule here tells it to fire 10 minutes after SPY's market open Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", 10), () => { Log("EveryDay.SPY 10 min after open: Fired at: " + Time); }); // schedule an event to fire every trading day for a security // the time rule here tells it to fire 10 minutes before SPY's market close Schedule.On(DateRules.EveryDay("SPY"), TimeRules.BeforeMarketClose("SPY", 10), () => { Log("EveryDay.SPY 10 min before close: Fired at: " + Time); }); // schedule an event to fire on certain days of the week Schedule.On(DateRules.Every(DayOfWeek.Monday, DayOfWeek.Friday), TimeRules.At(12, 0), () => { Log("Mon/Fri at 12pm: Fired at: " + Time); }); // the scheduling methods return the ScheduledEvent object which can be used for other things // here I set the event up to check the portfolio value every 10 minutes, and liquidate if we have too many losses Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromMinutes(10)), () => { // if we have over 1000 dollars in unrealized losses, liquidate if (Portfolio.TotalUnrealizedProfit < -1000) { Log("Liquidated due to unrealized losses at: " + Time); Liquidate(); } }); // schedule an event to fire at the beginning of the month, the symbol is optional if // specified, it will fire the first trading day for that symbol of the month, if not specified // it will fire on the first day of the month Schedule.On(DateRules.MonthStart("SPY"), TimeRules.AfterMarketOpen("SPY"), () => { // good spot for rebalancing code? }); }
public override void Initialize() { SetStartDate(2014, 6, 5); SetEndDate(2014, 6, 9); _twx = AddEquity("TWX", Resolution.Minute, extendedMarketHours: true).Symbol; Schedule.On(DateRules.EveryDay(_twx), TimeRules.Every(TimeSpan.FromHours(1)), PlotPrice); }
public override void Initialize() { SetStartDate(2013, 10, 07); //Set Start Date SetEndDate(2013, 10, 11); //Set End Date SetCash(2500000); SetCash("TRY", 111000, 1); //Set Strategy Cash security = AddSecurity(SecurityType.Equity, BIST_SECURITY_NAME, Resolution.Second); Schedule.On(DateRules.On(2016, 05, 11), TimeRules.At(11, 38), () => { Log("SpecificTime: Fired at : " + Time); }); // schedule an event to fire every trading day for a security // the time rule here tells it to fire 10 minutes after SPY's market open Schedule.On(DateRules.EveryDay(BIST_SECURITY_NAME), TimeRules.AfterMarketOpen(BIST_SECURITY_NAME, 10), () => { Log("EveryDay.GARAN 10 min after open: Fired at: " + Time); }); // schedule an event to fire every trading day for a security // the time rule here tells it to fire 10 minutes before SPY's market close Schedule.On(DateRules.EveryDay(BIST_SECURITY_NAME), TimeRules.BeforeMarketClose(BIST_SECURITY_NAME, 10), () => { Log("EveryDay.GARAN 10 min before close: Fired at: " + Time); }); // schedule an event to fire on certain days of the week Schedule.On(DateRules.Every(DayOfWeek.Monday, DayOfWeek.Friday), TimeRules.At(12, 0), () => { Log("Mon/Fri at 12pm: Fired at: " + Time); }); // the scheduling methods return the ScheduledEvent object which can be used for other things // here I set the event up to check the portfolio value every 10 minutes, and liquidate if we have too many losses Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromMinutes(10)), () => { Log("EveryDay 10 min Fired at: " + Time); // if we have over 1000 dollars in unrealized losses, liquidate if (Portfolio.TotalUnrealizedProfit < -1000) { Log("Liquidated due to unrealized losses at: " + Time); Liquidate(); } }); //SetBrokerageModel(BrokerageName.TEB); //QuantConnect.Securities.Security sec = AddSecurity(SecurityType.Equity, SECURITY_NAME, Resolution.Second); //security.DataFilter = new CustomDataFilter(); //Securities[securityName].DataFilter = new CustomDataFilter(); //sec.FeeModel = new QuantConnect.Orders.Fees.TEBFeeModel(0); //sec.FillModel = new QuantConnect.Orders.Fills.TEBFillModel(); //sec.MarginModel = new QuantConnect.Securities.TEBSecurityMarginModel(1m); //sec.SlippageModel = new QuantConnect.Orders.Slippage.TEBSlippageModel(0m); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { SetStartDate(2013, 10, 07); SetEndDate(2013, 10, 09); SetCash(100000); AddEquity("SPY", Resolution.Minute, extendedMarketHours: true, fillDataForward: false); Schedule.On("RunHistoryCall", DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), RunHistoryCall); }
public override void Initialize() { SetStartDate(2018, 3, 26); SetEndDate(2018, 4, 10); foreach (var symbol in _symbols) { AddSecurity(symbol, Resolution.Minute); } Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall); }
public override void Initialize() { SetStartDate(2011, 1, 1); SetEndDate(2018, 1, 1); SetCash(100000); AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute); foreach (int period in Enumerable.Range(0, 100)) { Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", period), Rebalance); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.BeforeMarketClose("SPY", period), Rebalance); } Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromSeconds(5)), Rebalance); }
public override void Initialize() { SetStartDate(2013, 10, 07); SetEndDate(2013, 10, 11); SetCash(100000); foreach (var underlying in _underlyings) { AddEquity(underlying, Resolution.Minute); } // Every 15 min scan. Schedule.On(DateRules.EveryDay("SPY"), TimeRules.Every(TimeSpan.FromMinutes(15)), Scan); }
public override void Initialize() { SetStartDate(2013, 10, 8); SetEndDate(2013, 10, 9); SetCash(1000000); foreach (var root in roots) { // set our expiry filter for this futures chain AddFuture(root, Resolution.Minute).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182)); } SetBenchmark(d => 1000000); Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall); }
public override void Initialize() { UniverseSettings.Resolution = Resolution.Hour; SetStartDate(2017, 01, 01); SetEndDate(2017, 02, 01); // selection will run on mon/tues/thurs at 00:00/12:00 SetUniverseSelection(new ScheduledUniverseSelectionModel( DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Thursday), TimeRules.Every(TimeSpan.FromHours(12)), SelectSymbols )); SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1))); SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); }
public override void Initialize() { SetStartDate(2017, 01, 01); SetEndDate(2017, 02, 01); SetUniverseSelection(new ScheduledUniverseSelectionModel( DateRules.EveryDay(), TimeRules.At(9, 31), SelectSymbolsAt )); Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(6)), () => { _scheduleEventEveryCallCount++; if (Time.Hour != 0 && Time.Hour != 6 && Time.Hour != 12 && Time.Hour != 18) { throw new Exception($"Unexpected every 6 hours scheduled event time: {Time}"); } }); Schedule.On(DateRules.EveryDay(), TimeRules.Noon, () => { _scheduleEventNoonCallCount++; if (Time.Hour != 12) { throw new Exception($"Unexpected Noon scheduled event time: {Time}"); } }); Schedule.On(DateRules.EveryDay(), TimeRules.Midnight, () => { _scheduleEventMidnightCallCount++; if (Time.Hour != 0) { throw new Exception($"Unexpected Midnight scheduled event time: {Time}"); } }); }
public override void Initialize() { SetStartDate(2020, 9, 1); SetEndDate(2020, 9, 2); SetCash(100000); numberOfSymbols = 2000; numberOfSymbolsFine = 1000; SetUniverseSelection(new FineFundamentalUniverseSelectionModel(CoarseSelectionFunction, FineSelectionFunction)); SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); SetExecution(new ImmediateExecutionModel()); queue = new Queue <Symbol>(); dequeueSize = 100; AddEquity("SPY", Resolution.Minute); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(0, 0), FillQueue); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.Every(TimeSpan.FromMinutes(60)), TakeFromQueue); }
public override void Initialize() { UniverseSettings.Resolution = Resolution.Hour; // Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees. // Commented so regression algorithm is more sensitive //Settings.MinimumOrderMarginPortfolioPercentage = 0.005m; SetStartDate(2017, 01, 01); SetEndDate(2017, 02, 01); // selection will run on mon/tues/thurs at 00:00/12:00 SetUniverseSelection(new ScheduledUniverseSelectionModel( DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Thursday), TimeRules.Every(TimeSpan.FromHours(12)), SelectSymbols )); SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1))); SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); }