本文整理汇总了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");
}
}