コード例 #1
0
        public static void Generate(DateTime start)
        {
            var allContractsCTD = FutureContractsFactory.CreateFutureCTDContracts();
            var contractsToRun = UserSpecifiedContracts != null ? allContractsCTD.Where(c => UserSpecifiedContracts.Select(x => x.ToUpper()).Contains(c.Ric)) : allContractsCTD;

            var rollSetting = new RollSettings
            {
                RollType = RollType.CTD,
                CTDSource = GenType,
                Ctdoverrides = GetCTDOverrideFromFile(),
            };

            var ctddataResult = new List<Tuple<string, CTDItem[]>>();
            foreach (var contract in contractsToRun)
            {
                var rollLogic = RollFactory.CreateRollLogic(contract, rollSetting);
                var futureRollLogic = rollLogic as FirstNoticeCTDRollLogic;
                if (futureRollLogic != null)
                {
                    var futstat = futureRollLogic.FetchFutureStaticFromCarbon().Where(x => x.FirstNoticeDate > start.AddMonths(-6)).OrderBy(d => d.FirstNoticeDate).ToArray();
                    var generator = RollFactory.CreateCtdGenerator(GenType);                  
                    generator.CTDOverrides = rollSetting.Ctdoverrides;
                    generator.IsSmoothStart = false;     // this is hardcoded to false because we do not want to look at past CTD in the CTD generation process
                    generator.StartDate = start;

                    var ctddata = generator.CreateCTDSeries(futstat, AsOf());

                    ctddataResult.Add(new Tuple<string, CTDItem[]>(contract.BbgBase.Market(), ctddata));
                }

            }


            var ctdresultPerGroup = ctddataResult.GroupBy(c => c.Item1)
                                        .Select(g =>
                                        {
                                            var result = g.SelectMany(x => x.Item2).ToArray();  
      

                                            bool successful = false;
                                            if (!IsTopup)
                                            {
                                                var newFrame = result.FutureStaticToFrame();
                                                newFrame.Print();
                                                successful = CarbonModel.SaveFrameToCarbon(CarbonFutureStaticAdaptor.GetFutureStaticMoniker(g.Key), newFrame).Result.Successful;
                                            }
                                            else
                                                successful = CarbonFutureStaticAdaptor.InsertDataToCarbonFrame(result, g.Key).Result.Successful;

                                            return successful;
                                        });

           
            if(ctdresultPerGroup.Any(r => !r))
                    throw new Exception("Unsuccessfully saving results to carbon");

            
        }
コード例 #2
0
 public static RollCache CreateRollCache(RollSettings setting)
 {
     switch (setting.RollType)
     {
         case RollType.CT:
             return new CTCache(setting.DataSource);
         case RollType.Future:                    
         case RollType.CTD:
             return new FutureRollCache(setting);
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
コード例 #3
0
        public HistSeriesChartViewModel()
        {
            var rollsetting = new RollSettings {DataSource = RollDataSource.CarbonLive};
            futureRollCache = new FutureRollCache(rollsetting);   // we use carbon live for this.
            futureContracts = FutureContractsFactory.CreateFutureContracts();

            var task = new Task(() =>
            {
                try
                {
                    var bonds = Generator.Go(Generator.CashBondRolling.Monthly);
                            var dictionary = new Dictionary<BondCurves, List<CTDLine<BondSpreads>>>
                      {
                        {BondCurves.USD3mLibor, Generator.GetSpreads(bonds, BondCurves.USD3mLibor)}
                      };

                      m_cd = new ChartDataSource(chartComponents_: new[]
                                {
                                new ChartComponent(),
                                new ChartComponent(),
                                new ChartComponent()
                                },
                                            bonds_: bonds,
                                            spreads_: dictionary
                                            );
                        
                      // subscribe to live curve and live bonds
                      m_live = new LiveDataModel(bonds.Last());
                    
                }
                catch (Exception ex_)
                {
                    Logger.Error("Error building CTD data for seasonality application", typeof(HistSeriesChartViewModel), ex_);
                }
            });

            task.ContinueWith( t =>
            {
                // hook up carbon and live data result
                m_live.SubscribeForLiveCurveAndBondPrices();                
            });

            task.ContinueWith(t => m_live.BondSpreadModel().BondSpreadResultObservable().Where(b => b != null)
                                .ObserveOn(SynchronizationContext.Current)
                                .Subscribe(LiveChartUpdate), TaskScheduler.FromCurrentSynchronizationContext());
            task.Start();

        }
コード例 #4
0
ファイル: RollFactory.cs プロジェクト: heimanhon/researchwork
        public static IRollLogic CreateRollLogic(IContract future, RollSettings rollsettings)
        {
            var futureContract = future as FutureContract;
            if (futureContract == null) return null;

            var rollcontrol = rollsettings.RollMethod ?? futureContract.ContractEnd;    // if not roll method set use default
            switch (rollcontrol)
            {
                case RollControl.FirstNotice:                    
                    return futureContract.HasCTD ? new FirstNoticeCTDRollLogic(future, CreateCtdGenerator(rollsettings.CTDSource)) : new FirstIssueFutureRollLogic(future);
                case RollControl.DeliveryDate:
                    break;
                case RollControl.LastTrade:
                    break;
                case RollControl.MonthEnd:
                    return new MonthEndFutureRollLogic(future);                
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return null;
        }