public ISignalSeries Generate( IPriceSeries referencePrices, IPriceSeries indicatorPoints ) { var signals = new List<TimedSignal>(); var prevPrice = referencePrices.First(); TimedValue<DateTime, double> prevIndicatorPoint = null; foreach ( var price in referencePrices.Skip( 1 ) ) { var indicatorPoint = indicatorPoints.TryGet( price.Time ); if ( indicatorPoint == null ) { signals.Add( new TimedSignal( price.Time, Signal.None ) ); continue; } if ( prevIndicatorPoint == null ) { prevIndicatorPoint = indicatorPoint; continue; } if ( prevPrice.Value < prevIndicatorPoint.Value && price.Value > indicatorPoint.Value ) { signals.Add( new TimedSignal( indicatorPoint.Time, new BuySignal() ) ); } else if ( prevPrice.Value > prevIndicatorPoint.Value && price.Value < indicatorPoint.Value ) { signals.Add( new TimedSignal( indicatorPoint.Time, new SellSignal() ) ); } prevPrice = price; } return new SignalSeries( referencePrices, indicatorPoints.Identifier, signals ); }
private IndicatorResult GenerateResult(IPriceSeries shortTermPoints, IPriceSeries longTermPoints) { var signals = Indicator.SignalGenerationStrategy.Generate(shortTermPoints, longTermPoints); var reportData = new GenericIndicatorReport.Data() { SignalOfDayUnderAnalysis = GetCurrentSignal(signals, longTermPoints), Prices = myPrices, Signals = signals }; reportData.Points[Indicator.ShortTerm.Name] = shortTermPoints; reportData.Points[Indicator.LongTerm.Name] = longTermPoints; var result = new IndicatorResult(Indicator.Name, Stock, reportData.SignalOfDayUnderAnalysis); if (Context.GenerateHistoricSignals) { result.Signals = signals; } result.Report = new DoubleCrossoverReport(Indicator, Stock, reportData); return(result); }
private IEnumerable <TimedValue <DateTime, double> > FillMissingDates(IPriceSeries series) { yield return(series.First()); var expectedPoint = series.First(); foreach (var point in series.Skip(1)) { while (true) { expectedPoint = new TimedValue <DateTime, double>(expectedPoint.Time.AddDays(1), expectedPoint.Value); if (expectedPoint.Time == point.Time) { break; } if (expectedPoint.Time.DayOfWeek == DayOfWeek.Saturday || expectedPoint.Time.DayOfWeek == DayOfWeek.Sunday) { // no trading at weekends usually continue; } // missing price at this date - take over the last one we have yield return(expectedPoint); } expectedPoint = point; yield return(point); } }
public StockPriceChart( string name, StockHandle stock, IPriceSeries prices ) { Name = name; Stock = stock; Prices = new PriceSeries( prices ); IndicatorPoints = new Dictionary<string, IPriceSeries>(); Signals = SignalSeries.Null; }
public StockPriceChart(string name, StockHandle stock, IPriceSeries prices) { Name = name; Stock = stock; Prices = new PriceSeries(prices); IndicatorPoints = new Dictionary <string, IPriceSeries>(); Signals = SignalSeries.Null; }
private IPriceSeries ApplyOperators(IPriceSeries series) { foreach (var op in Operators) { series = op.Apply(series); } return(series); }
private IPriceSeries ApplyOperators( IPriceSeries series ) { foreach ( var op in Operators ) { series = op.Apply( series ); } return series; }
public IndicatorResult Calculate() { myPrices = Indicator.Prices.ForStock(Stock); var points = CalculatePoints(); var result = GenerateResult(points); return(result); }
public IndicatorResult Calculate() { myPrices = Indicator.Prices.ForStock(Stock); var shortTermPoints = Indicator.ShortTerm.Calculate(myPrices); var longTermPoints = Indicator.LongTerm.Calculate(myPrices); var result = GenerateResult(shortTermPoints, longTermPoints); return(result); }
public SystemResult( string system, StockHandle stock, IPriceSeries prices, IndicatorResult indicatorResult ) { System = system; Stock = stock; Prices = prices; Signal = indicatorResult.Signal; ExpectedGain = indicatorResult.ExpectedGain; GainRiskRatio = indicatorResult.GainRiskRatio; Signals = indicatorResult.Signals; }
// expect: series already sorted by date public Curve AddCurve(string name, IPriceSeries points) { var curve = new Curve(name, points); curve.ViewPort = myViewPort; curve.PreRenderingOperators.AddRange(mySettings.CurvesPreRenderingOperators); myCurves.Add(curve); return(curve); }
public SystemResult(string system, StockHandle stock, IPriceSeries prices, IndicatorResult indicatorResult) { System = system; Stock = stock; Prices = prices; Signal = indicatorResult.Signal; ExpectedGain = indicatorResult.ExpectedGain; GainRiskRatio = indicatorResult.GainRiskRatio; Signals = indicatorResult.Signals; }
public IPriceSeries Apply(IPriceSeries series) { if (!series.Any()) { return(series); } var descriptor = new ObjectDescriptor("InterpolatedMissingDates"); var seriesId = series.Identifier.Modify(descriptor); return(PriceSeries.FromSortedSet(seriesId, FillMissingDates(series))); }
public IPriceSeries Apply( IPriceSeries series ) { double groupInterval = (double)series.Count / (double)myMaxPoints; if ( groupInterval <= 1 ) { return series; } var descriptor = new ObjectDescriptor( "ThinOut", ObjectDescriptor.Param( "MaxCount", myMaxPoints ) ); var seriesId = series.Identifier.Modify( descriptor ); return PriceSeries.FromSortedSet( seriesId, GroupPointsByAverage( series, (int)Math.Ceiling( groupInterval ) ) ); }
public IPriceSeries Apply(IPriceSeries series) { double groupInterval = (double)series.Count / (double)myMaxPoints; if (groupInterval <= 1) { return(series); } var descriptor = new ObjectDescriptor("ThinOut", ObjectDescriptor.Param("MaxCount", myMaxPoints)); var seriesId = series.Identifier.Modify(descriptor); return(PriceSeries.FromSortedSet(seriesId, GroupPointsByAverage(series, (int)Math.Ceiling(groupInterval)))); }
public IPriceSeries Calculate( IPriceSeries prices ) { var points = new List<SimplePrice>(); for ( int i = NumDays; i < prices.Count; ++i ) { var pricesRange = new PriceSeriesRange( prices, ClosedInterval.FromOffsetLength( i - NumDays, NumDays ) ); double value = pricesRange.Average( p => p.Value ); var point = new SimplePrice( prices[ i ].Time, value ); points.Add( point ); } var descriptor = new ObjectDescriptor( "SMA", ObjectDescriptor.Param( "NumDays", NumDays ) ); var seriesId = prices.Identifier.Derive( descriptor ); return new PriceSeries( seriesId, points ); }
public IPriceSeries Calculate(IPriceSeries prices) { var points = new List <SimplePrice>(); for (int i = NumDays; i < prices.Count; ++i) { var pricesRange = new PriceSeriesRange(prices, ClosedInterval.FromOffsetLength(i - NumDays, NumDays)); double value = pricesRange.Average(p => p.Value); var point = new SimplePrice(prices[i].Time, value); points.Add(point); } var descriptor = new ObjectDescriptor("SMA", ObjectDescriptor.Param("NumDays", NumDays)); var seriesId = prices.Identifier.Derive(descriptor); return(new PriceSeries(seriesId, points)); }
private static IEnumerable<TimedValue<DateTime, double>> GroupPointsByAverage( IPriceSeries series, int averageInterval ) { var pointGroup = new List<TimedValue<DateTime, double>>(); foreach ( var point in series ) { pointGroup.Add( point ); if ( pointGroup.Count == averageInterval ) { yield return Average( pointGroup ); pointGroup.Clear(); } } if ( pointGroup.Any() ) { yield return Average( pointGroup ); } }
protected Signal GetCurrentSignal(ISignalSeries signals, IPriceSeries indicatorPoints) { if (indicatorPoints.Last().Time < Context.DateUnderAnalysis) { // no data for the DUA return(Signal.None); } // we had data so default is "neutral" Signal currentSignal = new NeutralSignal(); var currentTimedSignal = signals.FirstOrDefault(s => s.Time == Context.DateUnderAnalysis); if (currentTimedSignal != null) { // found a "better" signal for the DUA - take this one currentSignal = currentTimedSignal.Value; } return(currentSignal); }
private IndicatorResult GenerateResult(IPriceSeries points) { var signals = Indicator.SignalGenerationStrategy.Generate(myPrices, points); var reportData = new GenericIndicatorReport.Data() { SignalOfDayUnderAnalysis = GetCurrentSignal(signals, points), Prices = myPrices, Signals = signals }; reportData.Points[Indicator.Name] = points; var result = new IndicatorResult(Indicator.Name, Stock, reportData.SignalOfDayUnderAnalysis); if (Context.GenerateHistoricSignals) { result.Signals = signals; } result.Report = new SmaReport(Indicator, Stock, reportData); return(result); }
public ISignalSeries Generate(IPriceSeries referencePrices, IPriceSeries indicatorPoints) { var signals = new List <TimedSignal>(); var prevPrice = referencePrices.First(); TimedValue <DateTime, double> prevIndicatorPoint = null; foreach (var price in referencePrices.Skip(1)) { var indicatorPoint = indicatorPoints.TryGet(price.Time); if (indicatorPoint == null) { signals.Add(new TimedSignal(price.Time, Signal.None)); continue; } if (prevIndicatorPoint == null) { prevIndicatorPoint = indicatorPoint; continue; } if (prevPrice.Value < prevIndicatorPoint.Value && price.Value > indicatorPoint.Value) { signals.Add(new TimedSignal(indicatorPoint.Time, new BuySignal())); } else if (prevPrice.Value > prevIndicatorPoint.Value && price.Value < indicatorPoint.Value) { signals.Add(new TimedSignal(indicatorPoint.Time, new SellSignal())); } prevPrice = price; } return(new SignalSeries(referencePrices, indicatorPoints.Identifier, signals)); }
public ISignalSeries Generate( IPriceSeries referencePrices, IPriceSeries indicatorPoints ) { var signals = new List<TimedSignal>(); var signalDaysInterval = ClosedInterval.FromOffsetLength( MinDaysAfterCutForSignal, KeepSignalForMaxDays ); var prevPrice = referencePrices.First(); TimedValue<DateTime,double> prevIndicatorPoint = null; TimedSignal activeSignal = null; foreach ( var price in referencePrices.Skip( 1 ) ) { var indicatorPoint = indicatorPoints.TryGet( price.Time ); if ( indicatorPoint == null ) { signals.Add( new TimedSignal( price.Time, Signal.None ) ); continue; } if ( prevIndicatorPoint == null ) { prevIndicatorPoint = indicatorPoint; continue; } if ( prevPrice.Value < prevIndicatorPoint.Value && price.Value > indicatorPoint.Value ) { var signal = new TimedSignal( indicatorPoint.Time, new BuySignal() ); if ( signalDaysInterval.IsEmpty ) { signals.Add( signal ); } else { activeSignal = signal; } } else if ( prevPrice.Value > prevIndicatorPoint.Value && price.Value < indicatorPoint.Value ) { var signal = new TimedSignal( indicatorPoint.Time, new SellSignal() ); if ( signalDaysInterval.IsEmpty ) { signals.Add( signal ); } else { activeSignal = signal; } } if ( activeSignal != null ) { // we have a cut signal -> handle it int daysSinceCut = (int)Math.Round( ( price.Time - activeSignal.Time ).TotalDays ); // if we are in defined range -> add the signal if ( signalDaysInterval.Includes( daysSinceCut ) ) { signals.Add( new TimedSignal( indicatorPoint.Time, activeSignal.Value ) ); } if ( daysSinceCut > signalDaysInterval.Max ) { // left the interval -> reset the signal activeSignal = null; } } prevPrice = price; prevIndicatorPoint = indicatorPoint; } return new SignalSeries( referencePrices, indicatorPoints.Identifier, signals ); }
public IPriceSeries Apply(IPriceSeries series) { return(PriceSeries.Null); }
public PriceSeries(IPriceSeries series) : base(series) { }
public StockPriceChart(StockHandle stock, IPriceSeries prices) : this("StockPrices", stock, prices) { }
public PriceSeriesRange(IPriceSeries series, ClosedInterval <int> interval) : this(series, interval.Min, interval.Max) { }
public bool ContainsEnoughData( IPriceSeries prices ) { return myCalculator.ContainsEnoughData( prices ); }
public IndicatorPointsSection( string name, IPriceSeries series ) : base(name) { Series = series; }
public ISignalSeries Generate(IPriceSeries referencePrices, IPriceSeries indicatorPoints) { var signals = new List <TimedSignal>(); var signalDaysInterval = ClosedInterval.FromOffsetLength(MinDaysAfterCutForSignal, KeepSignalForMaxDays); var prevPrice = referencePrices.First(); TimedValue <DateTime, double> prevIndicatorPoint = null; TimedSignal activeSignal = null; foreach (var price in referencePrices.Skip(1)) { var indicatorPoint = indicatorPoints.TryGet(price.Time); if (indicatorPoint == null) { signals.Add(new TimedSignal(price.Time, Signal.None)); continue; } if (prevIndicatorPoint == null) { prevIndicatorPoint = indicatorPoint; continue; } if (prevPrice.Value < prevIndicatorPoint.Value && price.Value > indicatorPoint.Value) { var signal = new TimedSignal(indicatorPoint.Time, new BuySignal()); if (signalDaysInterval.IsEmpty) { signals.Add(signal); } else { activeSignal = signal; } } else if (prevPrice.Value > prevIndicatorPoint.Value && price.Value < indicatorPoint.Value) { var signal = new TimedSignal(indicatorPoint.Time, new SellSignal()); if (signalDaysInterval.IsEmpty) { signals.Add(signal); } else { activeSignal = signal; } } if (activeSignal != null) { // we have a cut signal -> handle it int daysSinceCut = (int)Math.Round((price.Time - activeSignal.Time).TotalDays); // if we are in defined range -> add the signal if (signalDaysInterval.Includes(daysSinceCut)) { signals.Add(new TimedSignal(indicatorPoint.Time, activeSignal.Value)); } if (daysSinceCut > signalDaysInterval.Max) { // left the interval -> reset the signal activeSignal = null; } } prevPrice = price; prevIndicatorPoint = indicatorPoint; } return(new SignalSeries(referencePrices, indicatorPoints.Identifier, signals)); }
public IPriceSeries Calculate(IPriceSeries prices) { return(myCalculator.Calculate(prices)); }
public IndicatorPointsSection(string name, IPriceSeries series) : base(name) { Series = series; }
protected SignalSeries(IPriceSeries prices, SeriesIdentifier identifier, IEnumerable <TimedValue <DateTime, Signal> > set, bool sortRequired) : base(identifier, set, sortRequired) { Reference = prices; }
public bool ContainsEnoughData( IPriceSeries prices ) { return prices.Count() >= NumDays; }
public IPriceSeries Calculate( IPriceSeries prices ) { return myCalculator.Calculate( prices ); }
public StockPriceChart( StockHandle stock, IPriceSeries prices ) : this("StockPrices", stock, prices) { }
// expect: series already sorted by date public Curve AddCurve( string name, IPriceSeries points ) { var curve = new Curve( name, points ); curve.ViewPort = myViewPort; curve.PreRenderingOperators.AddRange( mySettings.CurvesPreRenderingOperators ); myCurves.Add( curve ); return curve; }
private static IEnumerable <TimedValue <DateTime, double> > GroupPointsByAverage(IPriceSeries series, int averageInterval) { var pointGroup = new List <TimedValue <DateTime, double> >(); foreach (var point in series) { pointGroup.Add(point); if (pointGroup.Count == averageInterval) { yield return(Average(pointGroup)); pointGroup.Clear(); } } if (pointGroup.Any()) { yield return(Average(pointGroup)); } }
public PriceSeriesRange(IPriceSeries series, int from, int to) : base(series, from, to) { }
public bool ContainsEnoughData(IPriceSeries prices) { return(prices.Count() >= NumDays); }
public SignalSeries(IPriceSeries prices, SeriesIdentifier identifier, IEnumerable <TimedValue <DateTime, Signal> > set) : this(prices, identifier, set, true) { }
public IPriceSeries Apply( IPriceSeries series ) { return PriceSeries.Null; }
public static ISignalSeries FromSortedSet(IPriceSeries prices, SeriesIdentifier identifier, IEnumerable <TimedValue <DateTime, Signal> > series) { return(new SignalSeries(prices, identifier, series, false)); }
public bool ContainsEnoughData(IPriceSeries prices) { return(myCalculator.ContainsEnoughData(prices)); }