当前位置: 首页>>代码示例>>C#>>正文


C# Frame.SaveCsv方法代码示例

本文整理汇总了C#中Frame.SaveCsv方法的典型用法代码示例。如果您正苦于以下问题:C# Frame.SaveCsv方法的具体用法?C# Frame.SaveCsv怎么用?C# Frame.SaveCsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Frame的用法示例。


在下文中一共展示了Frame.SaveCsv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: setRollingFuturesPrices

        //------------------------------------------------------------------------------------------------
        public void setRollingFuturesPrices(string outputfilepath = "")
        //------------------------------------------------------------------------------------------------
        {
            Console.WriteLine("Setting Rolling Futures:");

            var clonedPrices = TimeSeriesUtilities.DeepDeedleClone<DateTime, string, double>(RawFuturesPrices);

            double offset = 0.0; // how much to shift the entire series by

            // Compute the differences instead 
            if (smoothingType_ != SmoothingTypes.None)
            {
                clonedPrices = interpolateRawPriceFrame(clonedPrices, InterpolationTypes.FlatForward);  // required to calculate differences correctly
                clonedPrices = clonedPrices.SortRowsByKey();
                clonedPrices = clonedPrices.Diff(1);                                                    // assume we do have all the required dates, as per calendar specified
            }

            // Init
            int i = 0;
            var rowList = new List<KeyValuePair<int/*id*/, Series<string, object>/*row*/>>();

            var contracts = getTypesOfFuturesContracts();

            foreach (string contract in contracts)
            {
                // Get only the statics for a particular type
                var contractSubset = FuturesStatic.Where(kvp => kvp.Value.GetAs<string>("type") == contract);

                // Start adding to builder
                foreach (DateTime dte in dateRange_)
                {
                    var contractsByMonth = getXMonthContracts(dte, contractSubset, rollMethod_); // roll on first notice date

                    Console.WriteLine("{0}: prevFM = {1}, FM = {2}, BM = {3}, BM2 = {4}", dte.ToShortDateString(), contractsByMonth[ContractMonths.PrevFrontMonth], contractsByMonth[ContractMonths.FrontMonth], contractsByMonth[ContractMonths.BackMonth], contractsByMonth[ContractMonths.SecondBackMonth]);

                    // Add an entry for each futures contract month
                    foreach (KeyValuePair<ContractMonths, string/*ticker*/> entry in contractsByMonth)
                    {
                        ContractMonths contractMonth = entry.Key;
                        string ticker = entry.Value;

                        if (ticker == "")
                        {
                            continue;
                        }

                        var priceRow = clonedPrices.TryGetRow<double>(dte).ValueOrDefault;
                        double price = (priceRow == null) ? double.NaN : priceRow.TryGet(ticker).ValueOrDefault;
                        
                        var staticRow = FuturesStatic.GetRow<string>(ticker);

                        // All formats here: 
                        if (price != 0.0 || smoothingType_ != SmoothingTypes.None) // so the flat forward bits get picked up
                        {
                            var sb = new SeriesBuilder<string>();
                            sb.Add("date", dte);
                            sb.Add("deliverydate", staticRow.Get(getRollField(RollMethods.DeliveryDate)));
                            sb.Add("rolldate", staticRow.Get(getRollField(rollMethod_)));
                            sb.Add("ticker", ticker);
                            sb.Add("type", staticRow.Get("type"));
                            sb.Add("contractmonth", contractMonth.ToString());
                            sb.Add("price", price);
                            sb.Add("convfact", staticRow.Get("fut_cnvs_factor"));
                            sb.Add("ctdisin", staticRow.Get("fut_ctd_isin"));
                            sb.Add("ctdmaturity", staticRow.Get("maturity"));
                            sb.Add("ctdcoupon", staticRow.Get("cpn"));

                            rowList.Add(KeyValue.Create(i, sb.Series));
                            ++i;
                        }
                    }
                }
            }

            RollingFuturesData = Frame.FromRows(rowList);

            
            // This needs to be reassembled in a different function
            
            Console.WriteLine("Rolled Series");
            RollingFuturesData.Print();

            if (outputfilepath != "")
            {
                RollingFuturesData.SaveCsv("RollingFuturesDump.csv");
                clonedPrices.SaveCsv("RawFutures.csv");
            }
        }
开发者ID:heimanhon,项目名称:researchwork,代码行数:89,代码来源:FuturesSeriesBuilder.cs


注:本文中的Frame.SaveCsv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。