/// <summary> /// Initializes a new instance of the <see cref="ITrendStrategy"/> class. /// </summary> /// <param name="period">The period of the Instantaneous trend.</param> public ITrendStrategy(Indicator price, int period, decimal tolerance = 0.001m, decimal revetPct = 1.0015m, RevertPositionCheck checkRevertPosition = RevertPositionCheck.vsTrigger) { _price = price; ITrend = new InstantaneousTrend(period).Of(price); ITrendMomentum = new Momentum(2).Of(ITrend); MomentumWindow = new RollingWindow <decimal>(2); Position = StockState.noInvested; EntryPrice = null; ActualSignal = OrderSignal.doNothing; _tolerance = tolerance; _revertPCT = revetPct; _checkRevertPosition = checkRevertPosition; //Sig9 sig9 = new Sig9(); ITrendMomentum.Updated += (object sender, IndicatorDataPoint updated) => { if (ITrendMomentum.IsReady) { MomentumWindow.Add(ITrendMomentum.Current.Value); } if (MomentumWindow.IsReady) { CheckSignal(); } }; }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //mylog.Debug(transheader); mylog.Debug("Mean Reversion Algorithm"); mylog.Debug(ondataheader); dailylog.Debug("Mean Reversion Algorithm"); dailylog.Debug(dailyheader); //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(22000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); Price = new RollingWindow <IndicatorDataPoint>(14); trendHistory = new RollingWindow <IndicatorDataPoint>(14); trend = new InstantaneousTrend(10); ema10 = new ExponentialMovingAverage(10); sma10 = new SimpleMovingAverage(10); madiff = new RollingWindow <IndicatorDataPoint>(390); stddev = new StandardDeviation(390); emaHistory = new RollingWindow <IndicatorDataPoint>(10); smaHistory = new RollingWindow <IndicatorDataPoint>(10); }
/// <summary> /// Constuctor /// </summary> /// <param name="symbol">the symbol to track</param> public Sig5(Symbol _symbol) { symbol = _symbol; orderFilled = true; maketrade = true; trendArray = new decimal[] { 0, 0, 0 }; Id = 5; trend = new InstantaneousTrend("InSig", period, 2.0m / ((decimal)period + 1.0m)); }
/// <summary> /// Constuctor /// </summary> /// <param name="symbol">the symbol to track</param> public Sig4(Symbol _symbol) { symbol = _symbol; orderFilled = true; maketrade = true; trendArray = new decimal[] { 0, 0, 0 }; Id = 4; trend = new InstantaneousTrend("InSig", period, 2.0m / ((decimal)period + 1.0m)); }
/// <summary> /// Initializes a new instance of the <see cref="ITrendStrategy"/> class. /// </summary> /// <param name="period">The period of the Instantaneous trend.</param> public ITrendSignal(int period, decimal tolerance = 0.001m, decimal revetPct = 1.0015m, RevertPositionCheck checkRevertPosition = RevertPositionCheck.vsTrigger) { ITrend = new InstantaneousTrend(period); ITrendMomentum = new Momentum(2).Of(ITrend); MomentumWindow = new RollingWindow<decimal>(2); _tolerance = tolerance; _revertPCT = revetPct; _checkRevertPosition = checkRevertPosition; }
public void InstantaneousTrendComputesCorrectly() { int _period = 5; DateTime time = DateTime.Now; decimal[] actualValues = new decimal[20]; InstantaneousTrend iTrend = new InstantaneousTrend(_period); # region Arrays inputs
/// <summary> /// Initializes a new instance of the <see cref="ITrendStrategy"/> class. /// </summary> /// <param name="period">The period of the Instantaneous trend.</param> public ITrendSignal(int period, decimal tolerance = 0.001m, decimal revetPct = 1.0015m, RevertPositionCheck checkRevertPosition = RevertPositionCheck.vsTrigger) { ITrend = new InstantaneousTrend(period); ITrendMomentum = new Momentum(2).Of(ITrend); MomentumWindow = new RollingWindow <decimal>(2); _tolerance = tolerance; _revertPCT = revetPct; _checkRevertPosition = checkRevertPosition; }
public TripleMovingAverageStrategy(Symbol sym, Indicator priceIdentity, MeanReversionAlgorithm algorithm, decimal minBarSize, decimal barDifferenceTolerance) { Algorithm = algorithm; symbol = sym; trend = new InstantaneousTrend(10).Of(_price); ema10 = new ExponentialMovingAverage(10).Of(_price); sma10 = new SimpleMovingAverage(10).Of(_price); Position = StockState.noInvested; EntryPrice = null; ActualSignal = OrderSignal.doNothing; }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List <OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow <IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategy(symbol, 14, this); for (int i = 0; i < signals.Length; i++) { signals[i] = OrderSignal.doNothing; } _ticketsQueue = new ConcurrentQueue <OrderTicket>(); #region lists #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
public void ResetsProperly() { int _period = 5; DateTime time = DateTime.Now; InstantaneousTrend iTrend = new InstantaneousTrend(_period); for (int i = 0; i < 6; i++) { iTrend.Update(new IndicatorDataPoint(time, 1m)); time.AddMinutes(1); } Assert.IsTrue(iTrend.IsReady, "Instantaneous Trend ready"); iTrend.Reset(); TestHelper.AssertIndicatorIsInDefaultState(iTrend); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Daily); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history trendHistory = new RollingWindow <IndicatorDataPoint>(14); // ITrend trend = new InstantaneousTrend(7); _ticketsQueue = new List <OrderTicket>(); #region lists signalInfos.Add(new SignalInfo { Id = 8, IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); foreach (SignalInfo s in signalInfos) { s.IsActive = false; if (s.Id == LiveSignalIndex) { s.IsActive = true; } } #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.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> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Daily); // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history trendHistory = new RollingWindow<IndicatorDataPoint>(14); // ITrend trend = new InstantaneousTrend(7); _ticketsQueue = new List<OrderTicket>(); #region lists signalInfos.Add(new SignalInfo { Id = 8, IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); foreach (SignalInfo s in signalInfos) { s.IsActive = false; if (s.Id == LiveSignalIndex) { s.IsActive = true; } } #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.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> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List <OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow <IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategyOriginal(symbol, 14, this); iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod; #region lists #endregion var security = Securities[symbol]; security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
/// <summary> /// Initializes a new instance of the <see cref="ITrendStrategy"/> class. /// </summary> /// <param name="period">The period of the Instantaneous trend.</param> public ITrendStrategyJJ(Indicator price, int period, decimal tolerance = 0.001m, decimal revetPct = 1.0015m, RevertPositionCheck checkRevertPosition = RevertPositionCheck.vsTrigger) { _price = price; ITrend = new InstantaneousTrend(period).Of(price); ITrendMomentum = new Momentum(2).Of(ITrend); MomentumWindow = new RollingWindow<decimal>(2); Position = StockState.noInvested; EntryPrice = null; ActualSignal = OrderSignal.doNothing; _tolerance = tolerance; _revertPCT = revetPct; _checkRevertPosition = checkRevertPosition; ITrendMomentum.Updated += (object sender, IndicatorDataPoint updated) => { if (ITrendMomentum.IsReady) MomentumWindow.Add(ITrendMomentum.Current.Value); if (MomentumWindow.IsReady) CheckSignal(); }; }
public void InstantaneousTrendComputesCorrectly() { int _period = 5; DateTime time = DateTime.Now; decimal[] actualValues = new decimal[20]; InstantaneousTrend iTrend = new InstantaneousTrend(_period); # region Arrays inputs decimal[] prices = new decimal[20] { /* * Formula: * prices[i] = 10 * sin(2 * pi / 20 * i) + 15 * i = [0, 1, 2,..., 19] */ 15m, 18.09m, 20.88m, 23.09m, 24.51m, 25m, 24.51m, 23.09m, 20.88m, 18.09m, 15m, 11.91m, 9.12m, 6.91m, 5.49m, 5m, 5.49m, 6.91m, 9.12m, 11.91m }; decimal[] expectedValues = new decimal[20] { // Estimated with Python: http://tinyurl.com/nbt4ud3 15m, 18.09m, 18.015m, 20.735m, 22.8925m, 24.2775m, 24.755m, 24.3836m, 23.0445m, 20.8039m, 17.8648m, 14.5236m, 11.1232m, 8.0166m, 5.5265m, 3.911m, 3.3413m, 3.8832m, 5.4906m, 8.0133m }; # endregion for (int i = 0; i < prices.Length; i++) { iTrend.Update(new IndicatorDataPoint(time, prices[i])); actualValues[i] = Math.Round(iTrend.Current.Value, 4); time.AddMinutes(1); } Assert.AreEqual(expectedValues, actualValues, "Estimation ITrend(5)"); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //mylog.Debug(transheader); mylog.Debug("Mean Reversion Algorithm"); mylog.Debug(ondataheader); dailylog.Debug("Mean Reversion Algorithm"); dailylog.Debug(dailyheader); //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(22000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); Price = new RollingWindow<IndicatorDataPoint>(14); trendHistory = new RollingWindow<IndicatorDataPoint>(14); trend = new InstantaneousTrend(10); ema10 = new ExponentialMovingAverage(10); sma10 = new SimpleMovingAverage(10); madiff = new RollingWindow<IndicatorDataPoint>(390); stddev = new StandardDeviation(390); emaHistory = new RollingWindow<IndicatorDataPoint>(10); smaHistory = new RollingWindow<IndicatorDataPoint>(10); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List<OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) File.Delete(filepath); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow<IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategy(symbol, 14, this); for (int i = 0; i < signals.Length; i++) signals[i] = OrderSignal.doNothing; _ticketsQueue = new ConcurrentQueue<OrderTicket>(); #region lists #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
//private string sig7comment; //private TradeBarConsolidator fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15)); //private InstantaneousTrend trend15Min; //private bool CanMakeTrade = true; //private bool MinuteDataActivated = false; #endregion /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _proformatransactions = new List <OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); symbol = new Symbol("AAPL"); #region "Read Symbols from File" /********************************************** * THIS SECTION IS FOR READING SYMBOLS FROM A FILE ************************************************/ string symbols; var filename = AssemblyLocator.ExecutingDirectory() + "symbols.txt"; using (StreamReader sr = new StreamReader(filename)) { symbols = sr.ReadLine(); sr.Close(); } //symbol = new Symbol(symbols); #endregion minuteReturns.AppendFormat("{0},{1}", symbol, _startDate.ToShortDateString()); minuteHeader.AppendFormat("Symbol,Date"); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend("Main", 7, .24m); _orderTransactionProcessor = new OrderTransactionProcessor(); _transactions = new List <OrderTransaction>(); _ticketsQueue = new List <OrderTicket>(); #region ITrend iTrendSignal = new ITrendSignal(7); LastOrderSent.Add(symbol, OrderSignal.doNothing); #endregion #region lists signalInfos.Add(new SignalInfo { Id = 0, Name = "Minutes_001", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); //signalInfos.Add(new SignalInfo //{ // Id = 1, // Name = "ITrend", // IsActive = true, // SignalJson = string.Empty, // Value = OrderSignal.doNothing, // InternalState = string.Empty, // SignalType = typeof(ITrendSignal) //}); //foreach (SignalInfo s in signalInfos) //{ // s.IsActive = false; // if (s.Id == LiveSignalIndex) // { // s.IsActive = true; // } //} #endregion #region "15 Minute" // define our 15 minute consolidator //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15)); // if we want to make decisions every 15 minutes as well, we can add an event handler // to the DataConsolidated event //fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL; //trend15Min = new InstantaneousTrend(3); //RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close); //int fast = 15; //int slow = 30; //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)' //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast); //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow); //// register our indicator and consolidator together. this will wire the consolidator up to receive //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
private IndicatorDataPoint CalculateNewTrendHistoryValue(int barcount, DateTime time, RollingWindow <IndicatorDataPoint> price, InstantaneousTrend tr) { if (!trendHistory.IsReady) { return(idp(time, price[0].Value)); } return(idp(time, tr.Current.Value)); //add last iteration value for the cycle }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); ondataheader += _scig5C.GetNames(); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List <OrderTransaction>(); _proformatransactions = new List <OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Daily); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow <IndicatorDataPoint>(14); _ticketsQueue = new List <OrderTicket>(); #region lists sigDictionary = new Dictionary <int, ISigSerializable>(); signalInfos.Add(new SignalInfo { Id = 0, Name = "Minutes_001", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); //foreach (SignalInfo s in signalInfos) //{ // s.IsActive = false; // if (s.Id == LiveSignalIndex) // { // s.IsActive = true; // } //} #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.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> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _proformatransactions = new List<OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) File.Delete(filepath); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); symbol = new Symbol("AAPL"); #region "Read Symbols from File" /********************************************** THIS SECTION IS FOR READING SYMBOLS FROM A FILE ************************************************/ string symbols; var filename = AssemblyLocator.ExecutingDirectory() + "symbols.txt"; using (StreamReader sr = new StreamReader(filename)) { symbols = sr.ReadLine(); sr.Close(); } //symbol = new Symbol(symbols); #endregion minuteReturns.AppendFormat("{0},{1}", symbol, _startDate.ToShortDateString()); minuteHeader.AppendFormat("Symbol,Date"); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend("Main", 7, .24m); _orderTransactionProcessor = new OrderTransactionProcessor(); _transactions = new List<OrderTransaction>(); _ticketsQueue = new List<OrderTicket>(); #region ITrend iTrendSignal = new ITrendSignal(7); LastOrderSent.Add(symbol, OrderSignal.doNothing); #endregion #region lists signalInfos.Add(new SignalInfo { Id = 0, Name = "Minutes_001", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); //signalInfos.Add(new SignalInfo //{ // Id = 1, // Name = "ITrend", // IsActive = true, // SignalJson = string.Empty, // Value = OrderSignal.doNothing, // InternalState = string.Empty, // SignalType = typeof(ITrendSignal) //}); //foreach (SignalInfo s in signalInfos) //{ // s.IsActive = false; // if (s.Id == LiveSignalIndex) // { // s.IsActive = true; // } //} #endregion #region "15 Minute" // define our 15 minute consolidator //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15)); // if we want to make decisions every 15 minutes as well, we can add an event handler // to the DataConsolidated event //fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL; //trend15Min = new InstantaneousTrend(3); //RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close); //int fast = 15; //int slow = 30; //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)' //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast); //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow); //// register our indicator and consolidator together. this will wire the consolidator up to receive //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); #endregion // for use with Tradier. Default is IB. //var security = Securities[symbol]; //security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
private IndicatorDataPoint CalculateNewTrendHistoryValue(int barcount, DateTime time, RollingWindow<IndicatorDataPoint> price, InstantaneousTrend tr) { if (barcount < 7 && barcount > 2) { return (idp(time, (price[0].Value + 2 * price[1].Value + price[2].Value) / 4)); } else { return (idp(time, tr.Current.Value)); //add last iteration value for the cycle } }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List<OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) File.Delete(filepath); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow<IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategyOriginal(symbol, 14, this); iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod; #region lists #endregion var security = Securities[symbol]; security.TransactionModel = new ConstantFeeTransactionModel(1.0m); }
private IndicatorDataPoint CalculateNewTrendHistoryValue(int barcount, DateTime time, RollingWindow<IndicatorDataPoint> price, InstantaneousTrend tr) { //if (barcount < 7 && barcount > 2) //{ // return (idp(time, (price[0].Value + 2 * price[1].Value + price[2].Value) / 4)); //} //else //{ // return (idp(time, tr.Current.Value)); //add last iteration value for the cycle //} if (!trendHistory.IsReady) return idp(time, price[0].Value); return (idp(time, tr.Current.Value)); //add last iteration value for the cycle }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List<OrderTransaction>(); _proformatransactions = new List<OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) File.Delete(filepath); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow<IndicatorDataPoint>(14); //_ticketsQueue = new ConcurrentQueue<OrderTicket>(); _ticketsQueue = new List<OrderTicket>(); //sim = new BrokerSimulator(this); #region lists signalInfos.Add(new SignalInfo { Id = 0, Name = "Minutes_015", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); signalInfos.Add(new SignalInfo { Id = 1, Name = "Minutes_001", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); //foreach (SignalInfo s in signalInfos) //{ // s.IsActive = false; // if (s.Id == LiveSignalIndex) // { // s.IsActive = true; // } //} #endregion // define our 15 minute consolidator //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15)); // if we want to make decisions every 15 minutes as well, we can add an event handler // to the DataConsolidated event fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL; trend15Min = new InstantaneousTrend(3); RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close); //int fast = 15; //int slow = 30; //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)' //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast); //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow); //// register our indicator and consolidator together. this will wire the consolidator up to receive //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); // for use with Tradier. Default is IB. var security = Securities[symbol]; security.TransactionModel = new ConstantFeeTransactionModel(7.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> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List <OrderTransaction>(); var days = _endDate.Subtract(_startDate).TotalDays; MaxDailyProfit = new Maximum("MaxDailyProfit", (int)days); MinDailyProfit = new Minimum("MinDailyProfit", (int)days); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: //AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Initialize the Symbol indexed dictionaries foreach (string s in Symbols) { AddSecurity(SecurityType.Equity, s, Resolution.Minute); Strategy.Add(symbol, new MultiITStrategy(s, ITrendPeriod, this)); Tickets.Add(s, new List <OrderTicket>()); // Equal portfolio shares for every stock. ShareSize.Add(s, (maxLeverage * (1 - leverageBuffer)) / Symbols.Count()); LastOrderSent.Add(s, OrderSignal.doNothing); #region Logging stuff - Initializing Stock Logging //stockLogging.Add(new StringBuilder()); //stockLogging[i].AppendLine("Counter, Time, Close, ITrend, Trigger," + // "Momentum, EntryPrice, Signal," + // "TriggerCrossOverITrend, TriggerCrossUnderITrend, ExitFromLong, ExitFromShort," + // "StateFromStrategy, StateFromPorfolio, Portfolio Value"); //i++; #endregion Logging stuff - Initializing Stock Logging } // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend("Main", 7, .25m); trendHistory = new RollingWindow <IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategy(symbol, 14, this); iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod; #region lists // Initialize the lists for the strategies trendList = new Dictionary <int, InstantaneousTrend>(); trendHistoryList = new Dictionary <int, RollingWindow <IndicatorDataPoint> >(); strategyList = new Dictionary <int, MultiITStrategy>(); entryPriceList = new Dictionary <int, decimal>(); int listIndex = 0; for (decimal d = .25m; d < .26m; d += .01m) { trendList.Add(listIndex, new InstantaneousTrend("ITrend_" + d, 7, d)); // eg ITrend.25, period 7, alpha .25 trendHistoryList.Add(listIndex, new RollingWindow <IndicatorDataPoint>(4)); strategyList.Add(listIndex, new MultiITStrategy(symbol, 7, this)); entryPriceList.Add(listIndex, 0); listIndex++; } #endregion #region Proforma _brokerSimulator = new BrokerSimulator(this); #endregion }
private IndicatorDataPoint CalculateNewTrendHistoryValue(int barcount, DateTime time, RollingWindow<IndicatorDataPoint> price, InstantaneousTrend tr) { if (!trendHistory.IsReady) return idp(time, price[0].Value); return (idp(time, tr.Current.Value)); //add last iteration value for the cycle }
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(); }; }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List <OrderTransaction>(); _proformatransactions = new List <OrderTransaction>(); string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Indicators Price = new RollingWindow <IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend(7); trendHistory = new RollingWindow <IndicatorDataPoint>(14); //_ticketsQueue = new ConcurrentQueue<OrderTicket>(); _ticketsQueue = new List <OrderTicket>(); //sim = new BrokerSimulator(this); #region lists signalInfos.Add(new SignalInfo { Id = 0, Name = "Minutes_015", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); signalInfos.Add(new SignalInfo { Id = 1, Name = "Minutes_001", IsActive = true, SignalJson = string.Empty, Value = OrderSignal.doNothing, InternalState = string.Empty, SignalType = typeof(Sig9) }); //foreach (SignalInfo s in signalInfos) //{ // s.IsActive = false; // if (s.Id == LiveSignalIndex) // { // s.IsActive = true; // } //} #endregion // define our 15 minute consolidator //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15)); // if we want to make decisions every 15 minutes as well, we can add an event handler // to the DataConsolidated event fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL; trend15Min = new InstantaneousTrend(3); RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close); //int fast = 15; //int slow = 30; //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)' //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast); //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow); //// register our indicator and consolidator together. this will wire the consolidator up to receive //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close); // for use with Tradier. Default is IB. var security = Securities[symbol]; security.TransactionModel = new ConstantFeeTransactionModel(7.0m); }
private IndicatorDataPoint CalculateNewTrendHistoryValue(int barcount, DateTime time, RollingWindow <IndicatorDataPoint> price, InstantaneousTrend tr) { if (barcount < 7 && barcount > 2) { return(idp(time, (price[0].Value + 2 * price[1].Value + price[2].Value) / 4)); } else { return(idp(time, tr.Current.Value)); //add last iteration value for the cycle } }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { #region logging var algoname = this.GetType().Name; mylog.Debug(algoname); mylog.Debug(ondataheader); dailylog.Debug(algoname); dailylog.Debug(dailyheader); _transactions = new List<OrderTransaction>(); var days = _endDate.Subtract(_startDate).TotalDays; MaxDailyProfit = new Maximum("MaxDailyProfit", (int)days); MinDailyProfit = new Minimum("MinDailyProfit", (int)days); #endregion //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(_portfolioAmount); //Add as many securities as you like. All the data will be passed into the event handler: //AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Initialize the Symbol indexed dictionaries foreach (string s in Symbols) { AddSecurity(SecurityType.Equity, s, Resolution.Minute); Strategy.Add(symbol, new MultiITStrategy(s, ITrendPeriod, this)); Tickets.Add(s, new List<OrderTicket>()); // Equal portfolio shares for every stock. ShareSize.Add(s, (maxLeverage * (1 - leverageBuffer)) / Symbols.Count()); LastOrderSent.Add(s, OrderSignal.doNothing); #region Logging stuff - Initializing Stock Logging //stockLogging.Add(new StringBuilder()); //stockLogging[i].AppendLine("Counter, Time, Close, ITrend, Trigger," + // "Momentum, EntryPrice, Signal," + // "TriggerCrossOverITrend, TriggerCrossUnderITrend, ExitFromLong, ExitFromShort," + // "StateFromStrategy, StateFromPorfolio, Portfolio Value"); //i++; #endregion Logging stuff - Initializing Stock Logging } // Indicators Price = new RollingWindow<IndicatorDataPoint>(14); // The price history // ITrend trend = new InstantaneousTrend("Main", 7, .25m); trendHistory = new RollingWindow<IndicatorDataPoint>(14); // The ITrendStrategy iTrendStrategy = new InstantTrendStrategy(symbol, 14, this); iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod; #region lists // Initialize the lists for the strategies trendList = new Dictionary<int, InstantaneousTrend>(); trendHistoryList = new Dictionary<int, RollingWindow<IndicatorDataPoint>>(); strategyList = new Dictionary<int, MultiITStrategy>(); entryPriceList = new Dictionary<int, decimal>(); int listIndex = 0; for (decimal d = .25m; d < .26m; d += .01m) { trendList.Add(listIndex, new InstantaneousTrend("ITrend_" + d, 7, d)); // eg ITrend.25, period 7, alpha .25 trendHistoryList.Add(listIndex, new RollingWindow<IndicatorDataPoint>(4)); strategyList.Add(listIndex, new MultiITStrategy(symbol, 7, this)); entryPriceList.Add(listIndex, 0); listIndex++; } #endregion #region Proforma _brokerSimulator = new BrokerSimulator(this); #endregion }