Esempio n. 1
0
        public Dictionary<int, ReturnData> GetStrategyPrices(string status)
        {
            if (strategyPrices == null)
            {
                var ctx = new RepGenDataContext();
                var returns = ctx.ModelReturn(this.ID, status);
                var calc = new ReturnCalculation();
                var prices = from p in returns
                             select new ReturnData
                             {
                                 Date = p.Date,
                                 Value = calc.Price(p)
                             };

                strategyPrices = prices.ToDictionary(p => p.Date);
            }

            return strategyPrices;
        }
Esempio n. 2
0
        private void TenYearTest()
        {
            var ctx = new RepGenDataContext();
            var data = ctx.ModelReturn("CO", "HNW");
            //            var data = ctx.AssetClassReturn(new DateTime(1999, 9, 30), "GLEQ");

            ReturnCalculation calc = new ReturnCalculation();
            var match = from d in data
                        select new ReturnData {
                            Value = calc.RebaseReturn(d),
                            Date = d.Date
                        };

            foreach (var item in match) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
            Thread.Sleep(500000);
        }
Esempio n. 3
0
        private void TenYearBenchTest()
        {
            var ctx = new RepGenDataContext();
            var prices = ctx.BenchmarkPrice("CAMA");

            ReturnCalculation cr = new ReturnCalculation();
            ReturnCalculation cp = new ReturnCalculation();

            var tyr = from p in prices
                      let rtrn = cr.Return(p)
                      select new ReturnData {
                          Value = cp.RebaseReturn(rtrn),
                          Date = p.Date
                      };
            foreach (var item in tyr) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
        }
Esempio n. 4
0
        private void StressTest()
        {
            var ctx = new RepGenDataContext();

            var hd = ctx.HistoricPrice("UKGB").ToDictionary(d => d.Date);
            var last = hd.Last();

            // Ten Year Return
            var frm = hd.ElementAt(hd.Count() - 121);
            double retval = Math.Log(last.Value.Value / frm.Value.Value);

            // Bull Run Mar-03 to Mar-06

            int fromDate = (int)(new DateTime(2003, 3, 31).ToOADate());
            int toDate = (int)(new DateTime(2006, 3, 31).ToOADate());

            //var start = hd.Single(h => h.  .Date.Equals(fromDate-2));
            //var end = hd.Single(h => h.Date.Equals(toDate -2));
            var start = hd[fromDate - 2];
            var end = hd[toDate - 2];
            double bull = (end.Value - start.Value) / start.Value;

            // Model
            var returns = ctx.ModelReturn("CO", "HNW");
            var calc = new ReturnCalculation();
            int rn = 0;
            var prices = from p in returns
                         select new RankedReturnData {
                             RankNumber = rn++,
                             Date = p.Date,
                             Value = calc.Price(p)
                         };

            // Ten Year Return
            var pd = prices.ToDictionary(p => p.Date);
            var lastPrice = pd.Last();
            var fromMod = pd.ElementAt(pd.Count() - 121);
            double tyrMod = Math.Log(lastPrice.Value.Value / fromMod.Value.Value);

            // Bull
            int fromInt = ReturnData.IntegerDate(new DateTime(2003, 3, 31));
            int toInt = ReturnData.IntegerDate(new DateTime(2006, 3, 31));
            var startMod = pd[fromInt];
            var endMod = pd[toInt];
            double bullMod = (endMod.Value - startMod.Value) / startMod.Value;
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        private void PriceTest()
        {
            var ctx = new RepGenDataContext();
            //ctx.ModelReturn("CO");
            var data = ctx.ModelReturn("CO", "HNW");

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

            foreach (var item in match) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
            Thread.Sleep(500000);
        }
Esempio n. 7
0
        private void DrawdownTest3()
        {
            var ctx = new RepGenDataContext();
            var data = ctx.ModelReturn("CO", "HNW");

            ReturnCalculation calcPrice = new ReturnCalculation();
            ReturnCalculation calcDrawdown = new ReturnCalculation();

            var match = from d in data
                        let price = calcPrice.Price(d)
                        select new ReturnData {
                            Value = calcDrawdown.Drawdown(price, d.Value) - 1,
                            Date = d.Date
                        };

            foreach (var item in match) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
        }
Esempio n. 8
0
        private void DrawdownTest2()
        {
            var ctx = new RepGenDataContext();
            var data = ctx.HistoricPrice("UKGB");

            ReturnCalculation calc = new ReturnCalculation();

            var match = from d in data
                        select new ReturnData {
                            Value = calc.Drawdown(d) - 1,
                            Date = d.Date
                        };

            foreach (var item in match) {
                Console.WriteLine("{0}\t{1}", item.Date, item.Value);
            }
            //Thread.Sleep(500000);
        }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 12
0
        private Dictionary<int, ReturnData> calculateModelPrices()
        {
            if (modelPrices == null) {
                var returns = getModelReturn();
                var calc = new ReturnCalculation();
                var prices = from p in returns
                             select new ReturnData
                             {
                                 Date = p.Date,
                                 Value = calc.Price(p)
                             };

                modelPrices = prices.ToDictionary(p => p.Date);
            }

            return modelPrices;
        }
Esempio n. 13
0
        private List<ReturnData> calculateModelDrawdown(string strategyId, string status)
        {
            var returns = getModelReturn();

            ReturnCalculation cp = new ReturnCalculation();
            ReturnCalculation cd = new ReturnCalculation();

            var dd = from r in returns
                     let price = cp.Price(r)
                     select new ReturnData
                     {
                         Value = cd.Drawdown(price, r.Value) - 1,
                         Date = r.Date
                     };

            return dd.ToList();
        }
Esempio n. 14
0
        private Dictionary<int, ReturnData> calculateClientAssetPrices()
        {
            var returns = getClientAssetReturn();

            var calc = new ReturnCalculation();
            var prices = from p in returns
                         select new ReturnData
                         {
                             Date = p.Date,
                             Value = calc.Price(p)
                         };

            return prices.ToDictionary(p => p.Date);
        }
Esempio n. 15
0
        private List<ReturnData> calculateClientAssetDrawdown()
        {
            var returns = getClientAssetReturn();

            ReturnCalculation cp = new ReturnCalculation();
            ReturnCalculation cd = new ReturnCalculation();

            var dd = from r in returns
                     let price = cp.Price(r)
                     select new ReturnData
                     {
                         Value = cd.Drawdown(price, r.Value) - 1,
                         Date = r.Date
                     };

            return dd.ToList();
        }
Esempio n. 16
0
        private List<ReturnData> calculateAssetClassDrawdown(string assetclassId)
        {
            var returns = getAssetClassReturn(assetclassId);

            ReturnCalculation cp = new ReturnCalculation();
            ReturnCalculation cd = new ReturnCalculation();

            var dd = from r in returns
                     let price = cp.Price(r)
                     select new ReturnData
                     {
                         Value = cd.Drawdown(price, r.Value) - 1,
                         Date = r.Date
                     };

            //ReturnCalculation calc = new ReturnCalculation();

            //var dd = from p in returns
            //         select new ReturnData
            //         {
            //             Value = calc.Drawdown(p) - 1,
            //             Date = p.Date
            //         };

            return dd.ToList();
        }