public double Price(ReturnData returnData)
        {
            double retval = (1 + returnData.Value) * previousPrice;
            previousPrice = retval;

            return retval;
        }
        public double Return(ReturnData price)
        {
            double retval = (price.Value - previousPrice) / previousPrice;
            previousPrice = price.Value;

            return retval;
        }
 public double RollingReturn(ReturnData returnData1, ReturnData returnData2)
 {
     return RollingReturn(returnData1, returnData2, 1);
 }
        public double RollingReturn(ReturnData returnData)
        {
            double retval = Math.Log(returnData.Value / previousPriceRR);
            previousPriceRR = returnData.Value;

            return retval;
        }
 public double RebaseReturn(ReturnData rtrn)
 {
     return RebaseReturn(rtrn.Value);
 }
 public double Drawdown(ReturnData price)
 {
     return Drawdown(price.Value);
 }
        public double RollingReturn(ReturnData returnData1, ReturnData returnData2, int years)
        {
            double retval = Math.Log(returnData1.Value / returnData2.Value) / years;

            return retval;
        }
예제 #8
0
        private void RollingReturnTest()
        {
            var ctx = new RepGenDataContext();
            ReturnCalculation calc = new ReturnCalculation();

            // calculate prices
            //ctx.ModelReturn("CO");
            var data = ctx.ModelReturn("CO", "HNW");

            var prices = from d in data
                         select new ReturnData {
                             Value = calc.Price(d),
                             Date = d.Date
                         };

            var p1 = prices.ToList();
            p1.Insert(0, new ReturnData() { Value = 100D });
            var p2 = p1.Skip(12 * 3);
            var p3 = new List<ReturnData>();
            int i = 0;

            foreach (var item in p2) {
                var rd = new ReturnData {
                    Value = calc.RollingReturn(item, p1.ElementAt(i++)),
                    Date = item.Date
                };
                p3.Add(rd);
            }

            foreach (var item in p3) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
        }
예제 #9
0
        private List<ReturnData> calulateRollingReturn(List<ReturnData> data, int years)
        {
            ReturnCalculation calc = new ReturnCalculation();

            var prices = from d in data
                         select new ReturnData
                         {
                             Value = calc.Price(d),
                             Date = d.Date
                         };

            // create the 'From' list, starting with index value of 100
            var from = prices.ToList();
            from.Insert(0, new ReturnData() { Value = 100D });

            // create the 'To' list, starting with a years * 12 offset
            var to = from.Skip(12 * years);

            // new list for return values
            var rv = new List<ReturnData>();
            int i = 0;

            foreach (var item in to) {
                var rd = new ReturnData
                {
                    Value = calc.RollingReturn(item, from.ElementAt(i++), years),
                    Date = item.Date
                };
                rv.Add(rd);
            }

            return rv;
        }
예제 #10
0
        private List<ReturnData> calculateTenYearReturn(List<ReturnData> data)
        {
            int months = data.Count;
            int startDate = data[months - 121].Date;

            ReturnCalculation rc = new ReturnCalculation();

            var rtrn = from d in data.Skip(months - 120)
                       select new ReturnData
                       {
                           Value = rc.RebaseReturn(d),
                           Date = d.Date
                       };

            var tyr = rtrn.ToList();
            var newItem = new ReturnData() { Date = startDate, Value = 0 };
            tyr.Insert(0, newItem);

            return tyr;
        }
예제 #11
0
        private List<ReturnData> calculateTenYearBenchmarkReturn(List<ReturnData> prices)
        {
            int months = prices.Count;
            //int startIndex = months - Math.Min(121, months);
            int startDate = prices[months - 121].Date;

            ReturnCalculation cr = new ReturnCalculation();
            ReturnCalculation cb = new ReturnCalculation();

            var rtrn = from p in prices.Skip(months - 120)
                       let r = cr.Return(p)
                       select new ReturnData
                       {
                           Value = cb.RebaseReturn(r),
                           Date = p.Date
                       };

            var tyr = rtrn.ToList();
            var newItem = new ReturnData() { Date = startDate, Value = 0 };
            tyr.Insert(0, newItem);

            return tyr;
        }