예제 #1
0
        public StreamingStrategy(double outcomeCodePercent, long outcomeTimeframe, MarketModul mm, OrderMachine om, double minPercentThreshold, int learningIndicatorSteps, List <string> okayIndicators, string cachePath = null)
        {
            this.learningIndicatorSteps = learningIndicatorSteps;

            this.outcomeCodePercent = outcomeCodePercent;
            this.outcomeTimeframe   = outcomeTimeframe;

            this.minPercentThreshold = minPercentThreshold;
            this.cachePath           = cachePath;

            if (cachePath != null && Directory.Exists(cachePath) == false)
            {
                Directory.CreateDirectory(cachePath);
                Logger.log("Created log directory: " + cachePath);
            }

            this.okayIndicators = okayIndicators;

            this.orderMachine = om;
        }
예제 #2
0
 public FirstOrderMachine(MarketModul mm, double outcomeCodePercentage, long outcomeCodeTimestpan) : base(mm)
 {
     this.outcomeCodePercentage = outcomeCodePercentage;
     this.outcomeCodeTimestpan  = outcomeCodeTimestpan;
 }
        private void button1_Click(object sender, EventArgs e)
        {
            DataLoader dl = new DataLoader(Config.DataPath + pair);

            double[][] priceData = dl.getArray(0,
                                               31l * 24l * 60l * 60l * 1000l * monthsToTest + updateLookback,
                                               minTimestep);

            MarketModul  mm = new MarketModul(pair);
            OrderMachine om = new FirstOrderMachine(mm, outcomeCodePercent, outcomeTimeframe);

            List <string> okayIndicators;
            string        okayIndicatorsFile = "okayIndicators" + outcomeTimeframe + ".txt";

            if (File.Exists(okayIndicatorsFile))
            {
                okayIndicators = File.ReadAllText(okayIndicatorsFile).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList <string>();
            }
            else
            {
                throw new Exception("Okay indicators not found!");
            }

            StreamingStrategy strategy = new StreamingStrategy(outcomeCodePercent, outcomeTimeframe, mm, om, minPercentThreshold, samplingSteps, okayIndicators, "#cache");

            Logger.log("Getting market stopps...");
            long lastStop          = 0;
            long lastSeenTimestamp = Convert.ToInt64(priceData[0][(int)PriceDataIndeces.Date]);

            for (int i = 0; i < priceData.Length; i++)
            {
                long timestampNow = Convert.ToInt64(priceData[i][(int)PriceDataIndeces.Date]);
                if (timestampNow - lastSeenTimestamp > 1000 * 60 * 60l)
                {
                    Logger.log("Found stop: " + (lastSeenTimestamp - lastStop) / 1000 / 60 / 60 / 24l + " Days open");
                    strategy.addMarketStop(lastSeenTimestamp);
                    lastStop = lastSeenTimestamp;
                }
                lastSeenTimestamp = timestampNow;
            }
            Logger.log("Done");

            string lastMessage = "";

            long beginningTimestamp  = Convert.ToInt64(priceData[0][(int)PriceDataIndeces.Date]);
            long lastUpdateTimestamp = 0;

            for (int i = 0; i < priceData.Length; i++)
            {
                long timestampNow = Convert.ToInt64(priceData[i][(int)PriceDataIndeces.Date]);
                mm.pushPrice(priceData[i]);
                strategy.pushPrice(priceData[i]);

                if (lastUpdateTimestamp == 0)
                {
                    lastUpdateTimestamp = timestampNow - updateFrequency + updateLookback;
                }

                if (timestampNow - updateFrequency > lastUpdateTimestamp)
                {
                    Logger.log("Updateing indicators...");
                    strategy.updateIndicators(updateLookback,
                                              indicatorInitTime,
                                              new StDIndicatorSelector(indicatorsToChooseCount));

                    strategy.getSignalMachine().visualize(1500, 2).Save("SignalMachineVis" + timestampNow + ".png");
                    //Todo: save that somehow

                    lastUpdateTimestamp = timestampNow;
                    Logger.log("End updateing indicators.");
                }

                double percent = Convert.ToDouble(i) / priceData.Length * 100d;

                string msg = "Progress: " + Math.Round(percent, 0) + "%";
                if (lastMessage != msg)
                {
                    this.Text = msg;
                    Logger.log(msg);
                    lastMessage = msg;
                }
            }

            mm.flatAll(Convert.ToInt64(priceData[priceData.Length - 1][(int)PriceDataIndeces.Date]));

            string report = mm.getStatisticsString() + Environment.NewLine
                            + om.getStatistics() + Environment.NewLine
                            + mm.getProfitabilityByInfoString();

            Clipboard.SetText(report);

            MessageBox.Show(report);

            this.BackgroundImage = mm.getCapitalCurveVisualization(this.Width, this.Height);
        }
예제 #4
0
 public OrderMachine(MarketModul mm)
 {
     this.mm = mm;
 }