本文整理汇总了C#中System.Threading.Tasks.Task.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Cast方法的具体用法?C# Task.Cast怎么用?C# Task.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.Cast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateForwardCTD
public static RollResults CalculateForwardCTD(IContract contract, bool smoothStart = false)
{
var market = AsFuture(contract).BbgBase.Market();
var computeTasks = new Task<RollResultContractItem>[5];
DateTime now = DateTime.Now;
//var curResult = CalculateCTDResult(contract, f => f.CurrentCTD, f => f.CurrentContract, f => f.CurrentFuture.Value * f.CurrentConvFactor, smoothStart, true, f => f.CurrentFuture);
//var prevResult = CalculateCTDResult(contract, f => f.PrevCTD, f => f.PrevContract, f => f.PrevFuture.Value * f.PrevConvFactor, smoothStart, true, f => f.PrevFuture);
//var ooResult = CalculateCTDResult(contract, f => f.OOCTD, f => f.OOContract, f => f.OoFuture.Value * f.OOConvFactor, smoothStart, true, f => f.OoFuture);
//var dResult = CalculateCTDResult(contract, f => f.dCTD, f => f.DContract, f => f.DFuture.Value * f.dConvFactor, smoothStart, true, f => f.DFuture);
//var d2Result = CalculateCTDResult(contract, f => f.d2CTD, f => f.D2Contract, f => f.D2Future.Value * f.d2ConvFactor, smoothStart, true, f => f.D2Future);
Log.InfoFormat("start computing forward ctd for {0}", contract.Ric);
RollResultContractItem curResult = null;
RollResultContractItem prevResult = null;
RollResultContractItem ooResult = null;
RollResultContractItem dResult = null;
RollResultContractItem d2Result = null;
computeTasks[0] = Task.Factory.StartNew(() => CalculateCTDResult(contract, f => f.CurrentCTD, f => f.CurrentContract, f => f.CurrentFuture.Value * f.CurrentConvFactor, smoothStart, true, f => f.CurrentFuture)).ContinueWith(r => curResult = r.Result);
computeTasks[1] = Task.Factory.StartNew(() => CalculateCTDResult(contract, f => f.PrevCTD, f => f.PrevContract, f => f.PrevFuture.Value * f.PrevConvFactor, smoothStart, true, f => f.PrevFuture)).ContinueWith(r => prevResult = r.Result);
computeTasks[2] = Task.Factory.StartNew(() => CalculateCTDResult(contract, f => f.OOCTD, f => f.OOContract, f => f.OoFuture.Value * f.OOConvFactor, smoothStart, true, f => f.OoFuture)).ContinueWith(r => ooResult = r.Result);
computeTasks[3] = Task.Factory.StartNew(() => CalculateCTDResult(contract, f => f.dCTD, f => f.DContract, f => f.DFuture.Value * f.dConvFactor, smoothStart, true, f => f.DFuture)).ContinueWith(r => dResult = r.Result);
computeTasks[4] = Task.Factory.StartNew(() => CalculateCTDResult(contract, f => f.d2CTD, f => f.D2Contract, f => f.D2Future.Value * f.d2ConvFactor, smoothStart, true, f => f.D2Future)).ContinueWith(r => d2Result = r.Result);
Task.WaitAll(computeTasks.Cast<Task>().ToArray());
Log.InfoFormat("Finish computing all forward ctd series for {0} in {1}s", contract.Ric, (DateTime.Now - now).TotalSeconds);
// get the last smooth result from carbon
var moniker = ("symapp.roll.fctd." + market + "." + AsFuture(contract).BbgBase).ToLower();
var smooth = SmoothAllResultSeries(curResult, prevResult, smoothStart, moniker, r => r.CurrentResult, r => r.OResult);
return new RollResults
{
Identifier = AsFuture(contract).BbgBase,
RollType = "fctd",
Market = market,
CurrentResult = curResult,
OResult = prevResult,
OOResult = ooResult,
SmoothResult = smooth,
DResult = dResult,
D2Result = d2Result,
};
}
示例2: ComputeRelevantDatesForForwards
public void ComputeRelevantDatesForForwards()
{
Today = CurrentLiveTime(BondMarket.US); // only works for US atm.
// move forward to the nearest quarterend
var frontDateTimeLong = Today.AddMonths((3 - (Today.Month%3))%3);
FrontDateLong = new DateTime(frontDateTimeLong.Year, frontDateTimeLong.Month, DateTime.DaysInMonth(frontDateTimeLong.Year, frontDateTimeLong.Month));
var backDateTimeLong = FrontDateLong.AddMonths(3);
BackDateLong = new DateTime(backDateTimeLong.Year, backDateTimeLong.Month, DateTime.DaysInMonth(backDateTimeLong.Year, backDateTimeLong.Month));
var prevFrontDateTimeLong = FrontDateLong.AddMonths(-3);
PrevFrontDateLong = new DateTime(prevFrontDateTimeLong.Year, prevFrontDateTimeLong.Month, DateTime.DaysInMonth(prevFrontDateTimeLong.Year, prevFrontDateTimeLong.Month));
var back2DateTimeLong = BackDateLong.AddMonths(3);
Back2DateLong = new DateTime(back2DateTimeLong.Year, back2DateTimeLong.Month, DateTime.DaysInMonth(back2DateTimeLong.Year, back2DateTimeLong.Month));
Task<DateTime>[] dateTasks = new Task<DateTime>[6];
dateTasks[0] = bondSpreadServiceModel.RollDate(Today, 1, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => CashSettleLive = r.Result.ToDateTime());
dateTasks[1] = bondSpreadServiceModel.RollDate(Today, noOfDaysForAsOfDay, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => AsOfDate = r.Result.ToDateTime());
var asOfDateTask = dateTasks[1].ContinueWith(t => bondSpreadServiceModel.RollDate(AsOfDate, 1, DateUnit.Bd, BusinessDayConvention.Following, calendar)).ContinueWith(r => CashSettleClose = r.Result.Result.ToDateTime());
//dateTasks[2] = bondSpreadServiceModel.RollDate(AsOfDate, 1, DateUnit.Bd, BusinessDayConvention.Following, calendar)
// .ContinueWith(r => CashSettleClose = r.Result.ToDateTime());
dateTasks[2] = bondSpreadServiceModel.RollDate(FrontDateLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => FrontDateShort = r.Result.ToDateTime());
dateTasks[3] = bondSpreadServiceModel.RollDate(BackDateLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => BackDateShort = r.Result.ToDateTime());
dateTasks[4] = bondSpreadServiceModel.RollDate(PrevFrontDateLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => PrevFrontDateShort = r.Result.ToDateTime());
dateTasks[5] = bondSpreadServiceModel.RollDate(Back2DateLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => Back2DateShort = r.Result.ToDateTime());
Task.WaitAll(dateTasks.Cast<Task>().ToArray());
asOfDateTask.Wait();
}
示例3: CalculateCT
public static RollResults CalculateCT(IContract contract, bool smoothStart)
{
var market = contract.Ric.Market();
RollResultContractItem curResult = null;
RollResultContractItem prevResult = null;
RollResultContractItem ooResult = null;
RollResultContractItem oooResult = null;
RollResultContractItem ooooResult = null;
var computeTasks = new Task<RollResultContractItem>[5];
DateTime now = DateTime.Now;
Log.InfoFormat("start computing ctd for {0}", contract.Ric);
computeTasks[0] = Task.Factory.StartNew(() => CalculateCTResult(contract, f => f.CurrentCT, f => f.CurrentContract, f => f.CurrentValue, smoothStart)).ContinueWith(r => curResult = r.Result);
computeTasks[1] = Task.Factory.StartNew(() => CalculateCTResult(contract, f => f.PrevCT, f => f.PrevContract, f => f.PrevValue, smoothStart)).ContinueWith(r => prevResult = r.Result);
computeTasks[2] = Task.Factory.StartNew(() => CalculateCTResult(contract, f => f.OOCT, f => f.OOContract, f => f.OOValue, smoothStart)).ContinueWith(r => ooResult = r.Result);
computeTasks[3] = Task.Factory.StartNew(() => CalculateCTResult(contract, f => f.OOOCT, f => f.OOOContract, f => f.OOOValue, smoothStart)).ContinueWith(r => oooResult = r.Result);
computeTasks[4] = Task.Factory.StartNew(() => CalculateCTResult(contract, f => f.OOOOCT, f => f.OOOOContract, f => f.OOOOValue, smoothStart)).ContinueWith(r => ooooResult = r.Result);
Task.WaitAll(computeTasks.Cast<Task>().ToArray());
//var curResult = CalculateCTResult(contract, f => f.CurrentCT, f => f.CurrentContract, f => f.CurrentValue, smoothStart);
//var prevResult = CalculateCTResult(contract, f => f.PrevCT, f => f.PrevContract, f => f.PrevValue, smoothStart);
//var ooResult = CalculateCTResult(contract, f => f.OOCT, f => f.OOContract, f => f.OOValue, smoothStart);
//var oooResult = CalculateCTResult(contract, f => f.OOOCT, f => f.OOOContract, f => f.OOOValue, smoothStart);
//var ooooResult = CalculateCTResult(contract, f => f.OOOOCT, f => f.OOOOContract, f => f.OOOOValue, smoothStart);
Log.InfoFormat("Finish computing all ct series for {0} in {1}s", contract.Ric, (DateTime.Now - now).TotalSeconds);
// get the last smooth result from carbon
var moniker = ("symapp.roll.ct." + market + "." + contract.Ric).ToLower();
var smooth = SmoothAllResultSeries(curResult, prevResult, smoothStart, moniker, r => r.CurrentResult, r => r.OResult);
return new RollResults
{
Identifier = contract.Ric,
RollType = "ct",
Market = market,
CurrentResult = curResult,
OResult = prevResult,
OOResult = ooResult,
OOOResult = oooResult,
OOOOResult = ooooResult,
SmoothResult = smooth,
};
}
示例4: ComputeRollDates
public void ComputeRollDates()
{
FrontRollLong = (rollControl == RollControl.FirstNotice && FrontDateLong.AddTenor(Tenor.FromString("-1m"), calendar) < CashSettleLive) ? BackDateLong : FrontDateLong;
var backrollLongTemp = FrontRollLong.AddMonths(3);
BackRollLong = new DateTime(backrollLongTemp.Year, backrollLongTemp.Month, DateTime.DaysInMonth(backrollLongTemp.Year, backrollLongTemp.Month));
var back2rollLongTemp = BackRollLong.AddMonths(3);
Back2RollLong = new DateTime(back2rollLongTemp.Year, back2rollLongTemp.Month, DateTime.DaysInMonth(back2rollLongTemp.Year, back2rollLongTemp.Month));
var prevFrontRollLongTemp = FrontRollLong.AddMonths(-3);
PrevFrontRollLong = new DateTime(prevFrontRollLongTemp.Year, prevFrontRollLongTemp.Month, DateTime.DaysInMonth(prevFrontRollLongTemp.Year, prevFrontRollLongTemp.Month));
Task<DateTime>[] dateTasks = new Task<DateTime>[4];
dateTasks[0] = bondSpreadServiceModel.RollDate(FrontRollLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => FrontRollShort = r.Result.ToDateTime());
dateTasks[1] = bondSpreadServiceModel.RollDate(BackRollLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => BackRollShort = r.Result.ToDateTime());
dateTasks[2] = bondSpreadServiceModel.RollDate(Back2RollLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => Back2RollShort = r.Result.ToDateTime());
dateTasks[3] = bondSpreadServiceModel.RollDate(PrevFrontRollLong, 3, DateUnit.Bd, BusinessDayConvention.Following, calendar).ContinueWith(r => PrevFrontRollShort = r.Result.ToDateTime());
Task.WaitAll(dateTasks.Cast<Task>().ToArray());
}