예제 #1
0
        public override void RedoInsights()
        {
            TData = TTool.StrategyOutcome(cp);

            UptrendInvalid   = false;
            DowntrendInvalid = false;
            lastInsightTime  = MainPage.Year;
        }
예제 #2
0
        public override float UpdateInsights()
        {
            float ret = 0;
            //there is a price update

            //get the new prices
            List <StockPriceGraph> NewPrices = new List <StockPriceGraph>(cp.stockPrices.Skip(lastdatapoint));

            if (TData == null)
            {
                RedoInsights();
            }

            //bool UptrendInvalid = false, DowntrendInvalid = false;

            MainPage.inst.AddContinuousline(TData.DownTrend, new SolidColorBrush(Colors.Magenta));
            MainPage.inst.AddContinuousline(TData.UpTrend, new SolidColorBrush(Colors.Blue));

            foreach (var price in NewPrices)
            {
                if (TData.DownTrend != null)
                {
                    if (price.Close > (TData.DownTrend.Multiplier * price.Year + TData.DownTrend.Adder))
                    {
                        //trend invalid
                        DowntrendInvalid = true;
                    }
                }
                else
                {
                    DowntrendInvalid = true;
                }

                if (TData.UpTrend != null)
                {
                    if (price.Close < (TData.UpTrend.Multiplier * price.Year + TData.UpTrend.Adder))
                    {
                        //trend invalid
                        UptrendInvalid = true;
                    }
                }
                else
                {
                    UptrendInvalid = true;
                }
                if (!DowntrendInvalid && !UptrendInvalid)
                {
                    //if there is a double trend
                    // => watch market carefully

                    //buy differences
                    float UpDiff   = price.Close - (TData.UpTrend.Multiplier * price.Year + TData.UpTrend.Adder);
                    float DownDiff = (TData.DownTrend.Multiplier * price.Year + TData.DownTrend.Adder) - price.Close;
                    ret += UpDiff - DownDiff;
                }
                else
                {
                    if (!DowntrendInvalid)
                    {
                        //if only downtrend available => sell stocks
                        ret += 15;
                    }
                    if (!UptrendInvalid)
                    {
                        //if only uptrend available => buy stocks
                        ret -= 15;
                    }
                    if (UptrendInvalid && DowntrendInvalid)
                    {
                        //redo insights
                        TData = null;
                        return(ret);
                    }
                }
            }

            return(ret);
        }