Overall Statistics |
Total Trades 2 Average Win 58.61% Average Loss 0% Compounding Annual Return 11.349% Drawdown 18.400% Expectancy 0 Net Profit 121.798% Sharpe Ratio 0.906 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.084 Beta 0.333 Annual Standard Deviation 0.128 Annual Variance 0.016 Information Ratio 0.106 Tracking Error 0.182 Treynor Ratio 0.348 Total Fees $4.70 |
namespace QuantConnect { /* * QuantConnect University: Futures Example * * QuantConnect allows importing generic data sources! This example demonstrates importing a futures * data from the popular open data source Quandl. * * QuantConnect has a special deal with Quandl giving you access to Stevens Continuous Futurs (SCF) for free. * If you'd like to download SCF for local backtesting, you can download it through Quandl.com. */ public class QCUQuandlFutures : QCAlgorithm { string SPY = "SPY"; string ACWI = "ACWI"; string Tbill = "BIL"; string Bonds = "AGG"; Momentum _momSPY; Momentum _momACWI; Momentum _momTbill; DateTime sampledToday = DateTime.Now; public override void Initialize() { SetStartDate(2008, 6, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); SetCash(25000); AddSecurity(SecurityType.Equity, SPY, Resolution.Minute); Securities[SPY].SetDataNormalizationMode(DataNormalizationMode.TotalReturn); AddSecurity(SecurityType.Equity, ACWI, Resolution.Minute); Securities[ACWI].SetDataNormalizationMode(DataNormalizationMode.TotalReturn); AddSecurity(SecurityType.Equity, Tbill, Resolution.Minute); Securities[Tbill].SetDataNormalizationMode(DataNormalizationMode.TotalReturn); AddSecurity(SecurityType.Equity, Bonds, Resolution.Minute); Securities[Bonds].SetDataNormalizationMode(DataNormalizationMode.TotalReturn); _momSPY = MOM(SPY, 252, Resolution.Daily); _momACWI = MOM(ACWI, 252, Resolution.Daily); _momTbill = MOM(Tbill, 252, Resolution.Daily); } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(TradeBars data) { if (!_momSPY.IsReady) return; //One data point per m: if (sampledToday.Month == data.Time.Month) return; //Only take one data point per day (opening price) sampledToday = data.Time; decimal holdingPercent = .5m; string etf; decimal _momStrong; if (_momSPY >= _momACWI) { etf = SPY; _momStrong = _momSPY; } else { etf = ACWI; _momStrong = _momACWI; } if (_momStrong > _momTbill) { if(Portfolio[etf].Quantity > 0) return; Liquidate(); SetHoldings(etf, holdingPercent); Log("Set Holdings to " + Portfolio[etf].Quantity + "of " + etf); } else { if(Portfolio[Bonds].Quantity > 0) return; Liquidate(); SetHoldings(Bonds, holdingPercent); Log("Set Holdings to " + Portfolio[Bonds].Quantity + "of " + Bonds); } } } }