public double SharpeRatio(double RiskFreeRate) { int Days = Solution.Performance.PnLSeries.Count; TimeSeries ReturnSeries = new TimeSeries(); double Portfolio0 = Solution.Cash; double Portfolio1; for (int t = 0; t < Days; ++t) { DateTime date = Solution.Performance.PnLSeries.GetDateTime(t); Portfolio1 = Solution.Performance.PnLSeries[t] + Portfolio0; double DailyReturn = Portfolio1 / Portfolio0 - 1; Portfolio0 = Portfolio1; ReturnSeries.Add(date, DailyReturn); } double Mean = ReturnSeries.GetMean(0, Days - 1); double Std = ReturnSeries.GetStdDev(0, Days - 1); //年化收益均值、波动率 Mean = Mean * 250; Std = Std * Math.Sqrt(250); double SR = (Mean - RiskFreeRate) / Std; return SR; }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 },2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; UpSeries = new TimeSeries("Up"); DownSeries = new TimeSeries("Down"); RangeSeries = new TimeSeries("Range"); int n = N; if (StrategyType.OpenRangeBreak == strategyType) { n = 1; } bars86400 = GetBars(BarType.Time, 86400); HH = new PC(bars86400, n, BarData.High, PC.CalcType.Max, PC.UseLast.Yes); HC = new PC(bars86400, n, BarData.Close, PC.CalcType.Max, PC.UseLast.Yes); LC = new PC(bars86400, n, BarData.Close, PC.CalcType.Min, PC.UseLast.Yes); LL = new PC(bars86400, n, BarData.Low, PC.CalcType.Min, PC.UseLast.Yes); Draw(UpSeries, 0); Draw(DownSeries, 0); Draw(RangeSeries, 2); }
protected KDJ(BarSeries series, K_Fast rsv, int length) : base(series) { this.length = length; this.rsv = rsv; this.K = new TimeSeries("K"); this.D = new TimeSeries("D"); this.Name = "KDJ(" + length + ")"; }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 }, 2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; bars86400 = GetBars(BarType.Time, 86400); smd30 = new SMD(bars86400, 30); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); dbbu = new DynamicBBU(lbd, bars86400, bolBandTrig, BarData.Close); Draw(smd30, 2); Draw(lbd, 3); Draw(dbbu.SMA, 0); Draw(dbbu.BBL, 0); Draw(dbbu, 0); upBandSeries = new TimeSeries("upBandSeries"); dnBandSeries = new TimeSeries("dnBandSeries"); buyPointSeries = new TimeSeries("buyPointSeries"); sellPointSeries = new TimeSeries("sellPointSeries"); upBandSeries.Color = Color.Red; dnBandSeries.Color = Color.Red; Draw(upBandSeries, 0); Draw(dnBandSeries, 0); Draw(buyPointSeries, 0); Draw(sellPointSeries, 0); base.OnStrategyStart(); }
public override void OnStrategyStart() { if (Instrument1 == Instrument) { //Strategy1 = this; BarSeries1 = GetBars(BarType.Time, barSize); } else if (Instrument2 == Instrument) { //Strategy2 = this; BarSeries2 = GetBars(BarType.Time, barSize); } else { Console.WriteLine("合约错误!" + Instrument); } spreadSeries = new TimeSeries("spread"); _bars = new Dictionary<string, double>(); sma = new SMA(spreadSeries, Length); Draw(spreadSeries, 2); Draw(sma, 2); }
public virtual bool CrossesBelow(TimeSeries series, DateTime dateTime) { return(((FreeQuant.Series.TimeSeries) this.indicator).CrossesBelow((FreeQuant.Series.TimeSeries)series.series, dateTime)); }
///<summary> /// Checks if this indicator crosses a bar series above at specified dateTime ///</summary> public virtual Cross Crosses(TimeSeries series, DateTime dateTime) { return(EnumConverter.Convert(((FreeQuant.Series.TimeSeries) this.indicator).Crosses((FreeQuant.Series.TimeSeries)series.series, dateTime))); }
public double GetCorrelation(TimeSeries timeSeries) { return(this.series.GetCorrelation(timeSeries.series)); }
public CCI(TimeSeries series, int length, Color color) { this.indicator = new FreeQuant.Indicators.CCI(series.series, length, color); }
public virtual Cross Crosses(TimeSeries series, DateTime dateTime) { return(EnumConverter.Convert(this.series.Crosses(series.series, dateTime))); }
public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime) { return this.series.CrossesAbove(series.series, dateTime); }
public double GetCovariance(TimeSeries timeSeries) { return this.series.GetCovariance(timeSeries.series); }
public WMA(TimeSeries series, int length, Color color) { this.indicator = new FreeQuant.Indicators.WMA((FreeQuant.Series.TimeSeries)(series.series), length); }
public override void OnStrategyStart() { UpSeries = new TimeSeries("Up"); DownSeries = new TimeSeries("Down"); RangeSeries = new TimeSeries("Range"); int n = N; if (StrategyType.OpenRangeBreak == strategyType) { n = 1; } bars86400 = GetBars(BarType.Time, 86400); HH = new PC(bars86400, n, BarData.High, PC.CalcType.Max, PC.UseLast.Yes); HC = new PC(bars86400, n, BarData.Close, PC.CalcType.Max, PC.UseLast.Yes); LC = new PC(bars86400, n, BarData.Close, PC.CalcType.Min, PC.UseLast.Yes); LL = new PC(bars86400, n, BarData.Low, PC.CalcType.Min, PC.UseLast.Yes); Draw(UpSeries, 0); Draw(DownSeries, 0); Draw(RangeSeries, 2); }
public double GetCovariance(TimeSeries timeSeries) { return(this.series.GetCovariance((FreeQuant.Series.TimeSeries)timeSeries.series)); }
public double GetCorrelation(TimeSeries timeSeries) { return(this.series.GetCorrelation((FreeQuant.Series.TimeSeries)timeSeries.series)); }
public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime) { return(this.series.CrossesAbove((FreeQuant.Series.TimeSeries)series.series, dateTime)); }
public BBU(TimeSeries series, int length, double k, Color color) { this.indicator = new FreeQuant.Indicators.BBU(series.series, length, k, color); }
public void Add(TimeSeries series) { series.series.Draw(); }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 }, 2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; // 自动得到当时时间窗口大小 foreach (BarRequest barRequest in DataRequests.BarRequests) { barSize = Math.Min(barSize, barRequest.BarSize); } Console.WriteLine("barSize = {0}", barSize); Update6Line(); ssetup = new TimeSeries("观察卖出价", Color.Green); bsetup = new TimeSeries("观察买入价", Color.Green); bbreak = new TimeSeries("突破买入价", Color.Red); sbreak = new TimeSeries("突破卖出价", Color.Red); senter = new TimeSeries("反转卖出价", Color.Black); benter = new TimeSeries("反转买入价", Color.Black); S1 = new TimeSeries("S1", Color.Blue); B1 = new TimeSeries("B1", Color.Blue); Draw(ssetup, 0); Draw(bsetup, 0); Draw(bbreak, 0); Draw(sbreak, 0); Draw(senter, 0); Draw(benter, 0); Draw(S1, 2); Draw(B1, 2); }
public double GetCorrelation(TimeSeries timeSeries) { return this.series.GetCorrelation(timeSeries.series); }
public virtual Cross Crosses(TimeSeries series, DateTime dateTime) { return EnumConverter.Convert(this.series.Crosses(series.series, dateTime)); }
internal Performance(Portfolio portfolio) { this.portfolio = portfolio; this.equitySeries = new TimeSeries(portfolio.portfolio.Performance.EquitySeries); this.coreEquitySeries = new TimeSeries(portfolio.portfolio.Performance.CoreEquitySeries); this.pnLSeries = new TimeSeries(portfolio.portfolio.Performance.PnLSeries); this.drawdownSeries = new TimeSeries(portfolio.portfolio.Performance.DrawdownSeries); this.drawdownPercentSeries = new TimeSeries(portfolio.portfolio.Performance.DrawdownPercentSeries); }
public MOM(TimeSeries series, int length) { this.indicator = new FreeQuant.Indicators.MOM(series.series, length); }
public SMD(TimeSeries series, int length, BarData option, Color color) { this.indicator = new FreeQuant.Indicators.SMD(series.series, length, EnumConverter.Convert(option), color); }
public MACD(TimeSeries series, int length1, int length2, Color color) { this.indicator = new FreeQuant.Indicators.MACD(series.series, length1, length2, color); }
public override void OnStrategyStart() { // 自动得到当时时间窗口大小 foreach (BarRequest barRequest in DataRequests.BarRequests) { barSize = Math.Min(barSize, barRequest.BarSize); } Console.WriteLine("barSize = {0}", barSize); Update6Line(); ssetup = new TimeSeries("观察卖出价", Color.Green); bsetup = new TimeSeries("观察买入价", Color.Green); bbreak = new TimeSeries("突破买入价", Color.Red); sbreak = new TimeSeries("突破卖出价", Color.Red); senter = new TimeSeries("反转卖出价", Color.Black); benter = new TimeSeries("反转买入价", Color.Black); S1 = new TimeSeries("S1", Color.Blue); B1 = new TimeSeries("B1", Color.Blue); Draw(ssetup, 0); Draw(bsetup, 0); Draw(bbreak, 0); Draw(sbreak, 0); Draw(senter, 0); Draw(benter, 0); Draw(S1, 0); Draw(B1, 0); }
public override void OnStrategyStart() { bars86400 = GetBars(BarType.Time, 86400); smd30 = new SMD(bars86400, 30); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); dbbu = new DynamicBBU(lbd, bars86400, bolBandTrig, BarData.Close); Draw(smd30, 2); Draw(lbd, 3); Draw(dbbu.SMA, 0); Draw(dbbu.BBL, 0); Draw(dbbu, 0); upBandSeries = new TimeSeries("upBandSeries"); dnBandSeries = new TimeSeries("dnBandSeries"); buyPointSeries = new TimeSeries("buyPointSeries"); sellPointSeries = new TimeSeries("sellPointSeries"); upBandSeries.Color = Color.Red; dnBandSeries.Color = Color.Red; Draw(upBandSeries, 0); Draw(dnBandSeries, 0); Draw(buyPointSeries, 0); Draw(sellPointSeries, 0); }
public AD(TimeSeries series) { this.indicator = new FreeQuant.Indicators.AD(series.series); }
public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime) { return(this.series.CrossesAbove(series.series, dateTime)); }
public AD(TimeSeries series, Color color) { this.indicator = new FreeQuant.Indicators.AD(series.series, color); }
public double GetCovariance(TimeSeries timeSeries) { return(this.series.GetCovariance(timeSeries.series)); }
public AroonL(TimeSeries series, int length) { this.indicator = new FreeQuant.Indicators.AroonL(series.series, length); }
public BBL(TimeSeries series, int length, double k) { this.indicator = new FreeQuant.Indicators.BBL(series.series, length, k); }