Ejemplo n.º 1
0
 /// <summary>
 /// Constructor. </summary>
 /// <param name="series"> the time series </param>
 /// <param name="timeFrame"> the time frame </param>
 public CciIndicator(TimeSeries series, int timeFrame) : base(series)
 {
     _typicalPriceInd  = new TypicalPriceIndicator(series);
     _smaInd           = new SmaIndicator(_typicalPriceInd, timeFrame);
     _meanDeviationInd = new MeanDeviationIndicator(_typicalPriceInd, timeFrame);
     _timeFrame        = timeFrame;
 }
Ejemplo n.º 2
0
 public void setUp()
 {
     timeSeries            = new MockTimeSeries();
     typicalPriceIndicator = new TypicalPriceIndicator(timeSeries);
 }
Ejemplo n.º 3
0
 public void SetUp()
 {
     _timeSeries            = GenerateTimeSeries.WithArbitraryTicks();
     _typicalPriceIndicator = new TypicalPriceIndicator(_timeSeries);
 }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            /// <summary>
            /// Getting time series
            /// </summary>
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();

            /// <summary>
            /// Creating indicators
            /// </summary>
            // Close price
            ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
            // Typical price
            TypicalPriceIndicator typicalPrice = new TypicalPriceIndicator(series);
            // Price variation
            PriceVariationIndicator priceVariation = new PriceVariationIndicator(series);
            // Simple moving averages
            SMAIndicator shortSma = new SMAIndicator(closePrice, 8);
            SMAIndicator longSma  = new SMAIndicator(closePrice, 20);
            // Exponential moving averages
            EMAIndicator shortEma = new EMAIndicator(closePrice, 8);
            EMAIndicator longEma  = new EMAIndicator(closePrice, 20);
            // Percentage price oscillator
            PPOIndicator ppo = new PPOIndicator(closePrice, 12, 26);
            // Rate of change
            ROCIndicator roc = new ROCIndicator(closePrice, 100);
            // Relative strength index
            RSIIndicator rsi = new RSIIndicator(closePrice, 14);
            // Williams %R
            WilliamsRIndicator williamsR = new WilliamsRIndicator(series, 20);
            // Average true range
            AverageTrueRangeIndicator atr = new AverageTrueRangeIndicator(series, 20);
            // Standard deviation
            StandardDeviationIndicator sd = new StandardDeviationIndicator(closePrice, 14);

            /// <summary>
            /// Building header
            /// </summary>
            StringBuilder sb = new StringBuilder("timestamp,close,typical,variation,sma8,sma20,ema8,ema20,ppo,roc,rsi,williamsr,atr,sd\n");

            /// <summary>
            /// Adding indicators values
            /// </summary>
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nbTicks = series.getTickCount();
            int nbTicks = series.TickCount;

            for (int i = 0; i < nbTicks; i++)
            {
                sb.Append(series.getTick(i).EndTime.Millis / 1000d).Append(',').Append(closePrice.getValue(i)).Append(',').Append(typicalPrice.getValue(i)).Append(',').Append(priceVariation.getValue(i)).Append(',').Append(shortSma.getValue(i)).Append(',').Append(longSma.getValue(i)).Append(',').Append(shortEma.getValue(i)).Append(',').Append(longEma.getValue(i)).Append(',').Append(ppo.getValue(i)).Append(',').Append(roc.getValue(i)).Append(',').Append(rsi.getValue(i)).Append(',').Append(williamsR.getValue(i)).Append(',').Append(atr.getValue(i)).Append(',').Append(sd.getValue(i)).Append('\n');
            }

            /// <summary>
            /// Writing CSV file
            /// </summary>
            System.IO.StreamWriter writer = null;
            try
            {
                writer = new System.IO.StreamWriter("indicators.csv");
                writer.Write(sb.ToString());
            } catch (IOException ioe)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                Logger.getLogger(typeof(IndicatorsToCsv).FullName).log(Level.SEVERE, "Unable to write CSV file", ioe);
            } finally
            {
                try
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                } catch (IOException)
                {
                }
            }
        }