コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: KDJ.cs プロジェクト: ForTrade/OpenQuant
 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 + ")";
 }
コード例 #4
0
        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();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: Indicator.cs プロジェクト: zhuzhenping/FreeOQ
 public virtual bool CrossesBelow(TimeSeries series, DateTime dateTime)
 {
     return(((FreeQuant.Series.TimeSeries) this.indicator).CrossesBelow((FreeQuant.Series.TimeSeries)series.series, dateTime));
 }
コード例 #7
0
ファイル: Indicator.cs プロジェクト: zhuzhenping/FreeOQ
 ///<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)));
 }
コード例 #8
0
 public double GetCorrelation(TimeSeries timeSeries)
 {
     return(this.series.GetCorrelation(timeSeries.series));
 }
コード例 #9
0
ファイル: CCI.cs プロジェクト: heber/FreeOQ
		public CCI(TimeSeries series, int length, Color color)
		{
			this.indicator = new FreeQuant.Indicators.CCI(series.series, length, color);
		}
コード例 #10
0
 public virtual Cross Crosses(TimeSeries series, DateTime dateTime)
 {
     return(EnumConverter.Convert(this.series.Crosses(series.series, dateTime)));
 }
コード例 #11
0
ファイル: BarSeries.cs プロジェクト: houzhongxu/OpenQuant.API
		public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime)
		{
			return this.series.CrossesAbove(series.series, dateTime);
		}
コード例 #12
0
		public double GetCovariance(TimeSeries timeSeries)
		{
			return this.series.GetCovariance(timeSeries.series);
		}
コード例 #13
0
ファイル: WMA.cs プロジェクト: heber/FreeOQ
		public WMA(TimeSeries series, int length, Color color)
		{
			this.indicator = new FreeQuant.Indicators.WMA((FreeQuant.Series.TimeSeries)(series.series), length);
		}
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: TimeSeries.cs プロジェクト: zhuzhenping/FreeOQ
 public double GetCovariance(TimeSeries timeSeries)
 {
     return(this.series.GetCovariance((FreeQuant.Series.TimeSeries)timeSeries.series));
 }
コード例 #16
0
ファイル: TimeSeries.cs プロジェクト: zhuzhenping/FreeOQ
 public double GetCorrelation(TimeSeries timeSeries)
 {
     return(this.series.GetCorrelation((FreeQuant.Series.TimeSeries)timeSeries.series));
 }
コード例 #17
0
ファイル: TimeSeries.cs プロジェクト: zhuzhenping/FreeOQ
 public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime)
 {
     return(this.series.CrossesAbove((FreeQuant.Series.TimeSeries)series.series, dateTime));
 }
コード例 #18
0
ファイル: BBU.cs プロジェクト: heber/FreeOQ
		public BBU(TimeSeries series, int length, double k, Color color)
		{
			this.indicator = new FreeQuant.Indicators.BBU(series.series, length, k, color);
		}
コード例 #19
0
ファイル: Canvas.cs プロジェクト: heber/FreeOQ
		public void Add(TimeSeries series)
		{
			series.series.Draw();
		}
コード例 #20
0
ファイル: RBreaker_code.cs プロジェクト: vcfriend/OpenQuant
        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);
        }
コード例 #21
0
		public double GetCorrelation(TimeSeries timeSeries)
		{
			return this.series.GetCorrelation(timeSeries.series);
		}
コード例 #22
0
ファイル: BarSeries.cs プロジェクト: houzhongxu/OpenQuant.API
		public virtual Cross Crosses(TimeSeries series, DateTime dateTime)
		{
			return EnumConverter.Convert(this.series.Crosses(series.series, dateTime));
		}
コード例 #23
0
		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);
		}
コード例 #24
0
ファイル: MOM.cs プロジェクト: heber/FreeOQ
		public MOM(TimeSeries series, int length)
		{
			this.indicator = new FreeQuant.Indicators.MOM(series.series, length);
		}
コード例 #25
0
ファイル: SMD.cs プロジェクト: heber/FreeOQ
		public SMD(TimeSeries series, int length, BarData option, Color color)
		{
			this.indicator = new FreeQuant.Indicators.SMD(series.series, length, EnumConverter.Convert(option), color);
		}
コード例 #26
0
ファイル: MACD.cs プロジェクト: heber/FreeOQ
		public MACD(TimeSeries series, int length1, int length2, Color color)
		{
			this.indicator = new FreeQuant.Indicators.MACD(series.series, length1, length2, color);
		}
コード例 #27
0
        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);
        }
コード例 #28
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);
        }
コード例 #29
0
ファイル: AD.cs プロジェクト: heber/FreeOQ
		public AD(TimeSeries series)
		{
			this.indicator = new FreeQuant.Indicators.AD(series.series);
		}
コード例 #30
0
 public virtual bool CrossesAbove(TimeSeries series, DateTime dateTime)
 {
     return(this.series.CrossesAbove(series.series, dateTime));
 }
コード例 #31
0
ファイル: AD.cs プロジェクト: heber/FreeOQ
		public AD(TimeSeries series, Color color)
		{
			this.indicator = new FreeQuant.Indicators.AD(series.series, color);
		}
コード例 #32
0
 public double GetCovariance(TimeSeries timeSeries)
 {
     return(this.series.GetCovariance(timeSeries.series));
 }
コード例 #33
0
ファイル: AroonL.cs プロジェクト: heber/FreeOQ
		public AroonL(TimeSeries series, int length)
		{
			this.indicator = new FreeQuant.Indicators.AroonL(series.series, length);
		}
コード例 #34
0
ファイル: Canvas.cs プロジェクト: zhuzhenping/OpenQuant.API
 public void Add(TimeSeries series)
 {
     series.series.Draw();
 }
コード例 #35
0
ファイル: BBL.cs プロジェクト: heber/FreeOQ
		public BBL(TimeSeries series, int length, double k)
		{
			this.indicator = new FreeQuant.Indicators.BBL(series.series, length, k);
		}