示例#1
0
        /* Weron California prices... */
        //private string _timeSeries = @"CA\Price_Hourly.json";
        //private string _exVarsPre = @"CA\";

        //TODO: add uniqueStructure only for non overlapping short contracts to take priority
        public JsonResult ForwardCurve(string region, bool nonOverlapping)
        {
            var dd = new Utils.NasdaqOMX.Downloader();
            var fc = dd.ForwardCurve(nonOverlapping);

            return(Json(fc, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public JsonResult ArbVals()
        {
            var dd = new Utils.NasdaqOMX.Downloader();
            var fc = dd.ForwardCurve(false);

            /* Find all overlapping contracts */
            var years    = fc.Where(c => c.Resolution == Resolution.Yearly).ToList();
            var quarters = fc.Where(c => c.Resolution == Resolution.Quarterly).ToList();
            var months   = fc.Where(c => c.Resolution == Resolution.Monthly).ToList();
            //Months in Quarters
            var mqs = quarters
                      .Where(quarter => months.Count(m => quarter.Begin <= m.Begin && m.End <= quarter.End) == 3)
                      .Select(quarter => new Tuple <ForwardContract, List <ForwardContract> >(quarter, months
                                                                                              .Where(month => quarter.Begin <= month.Begin && month.End <= quarter.End)
                                                                                              .ToList())
                              ).ToList();
            //Quarters in Years
            var qys = years
                      .Where(year => quarters.Count(quarter => quarter.Begin.Year == year.Begin.Year) == 4)
                      .Select(year => new Tuple <ForwardContract, List <ForwardContract> >(year, quarters
                                                                                           .Where(quarter => quarter.Begin.Year == year.Begin.Year)
                                                                                           .ToList())
                              ).ToList();
            var allPairs = new List <Tuple <ForwardContract, List <ForwardContract> > >();

            allPairs.AddRange(mqs);
            allPairs.AddRange(qys);

            /* Look for arbitrages */
            //Long
            var longs = allPairs.Select(p => new {
                Pair      = p.Item1.ContractS + " <-> " + string.Join(", ", p.Item2.Select(x => x.ContractS)),
                Direction = "Long",
                Leg1      = -p.Item1.Ask,
                Leg2      = +WA(p.Item2, f => f.Bid),
                PnL       = -p.Item1.Ask + WA(p.Item2, f => f.Bid)
            }).ToList();
            //Short
            var shorts = allPairs.Select(p => new
            {
                Pair      = p.Item1.ContractS + " <-> " + string.Join(", ", p.Item2.Select(x => x.ContractS)),
                Direction = "Short",
                Leg1      = +p.Item1.Bid,
                Leg2      = -WA(p.Item2, f => f.Ask),
                PnL       = +p.Item1.Bid - WA(p.Item2, f => f.Ask)
            }).ToList();

            var allPositions = new List <object>();

            allPositions.AddRange(longs);
            allPositions.AddRange(shorts);

            return(Json(allPositions, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public JsonResult ArbVals()
        {
            var dd = new Utils.NasdaqOMX.Downloader();
            var fc = dd.ForwardCurve(false);

            /* Find all overlapping contracts */
            var years = fc.Where(c => c.Resolution == Resolution.Yearly).ToList();
            var quarters = fc.Where(c => c.Resolution == Resolution.Quarterly).ToList();
            var months = fc.Where(c => c.Resolution == Resolution.Monthly).ToList();
            //Months in Quarters
            var mqs = quarters
                .Where(quarter => months.Count(m => quarter.Begin <= m.Begin && m.End <= quarter.End) == 3)
                .Select(quarter => new Tuple<ForwardContract, List<ForwardContract>>(quarter, months
                    .Where(month => quarter.Begin <= month.Begin && month.End <= quarter.End)
                    .ToList())
                ).ToList();
            //Quarters in Years
            var qys = years
                .Where(year => quarters.Count(quarter => quarter.Begin.Year == year.Begin.Year) == 4)
                .Select(year => new Tuple<ForwardContract, List<ForwardContract>>(year, quarters
                    .Where(quarter => quarter.Begin.Year == year.Begin.Year)
                    .ToList())
                ).ToList();
            var allPairs = new List<Tuple<ForwardContract, List<ForwardContract>>>();
            allPairs.AddRange(mqs);
            allPairs.AddRange(qys);

            /* Look for arbitrages */
            //Long
            var longs = allPairs.Select(p => new {
                Pair = p.Item1.ContractS + " <-> " + string.Join(", ", p.Item2.Select(x=>x.ContractS)),
                Direction = "Long",
                Leg1 = -p.Item1.Ask,
                Leg2 = + WA(p.Item2, f => f.Bid),
                PnL = -p.Item1.Ask + WA(p.Item2, f => f.Bid)
            }).ToList();
            //Short
            var shorts = allPairs.Select(p => new
            {
                Pair = p.Item1.ContractS + " <-> " + string.Join(", ", p.Item2.Select(x => x.ContractS)),
                Direction = "Short",
                Leg1 = +p.Item1.Bid,
                Leg2 = -WA(p.Item2, f => f.Ask),
                PnL = +p.Item1.Bid - WA(p.Item2, f => f.Ask)
            }).ToList();

            var allPositions = new List<object>();
            allPositions.AddRange(longs);
            allPositions.AddRange(shorts);

            return Json(allPositions, JsonRequestBehavior.AllowGet);
        }