Overall Statistics |
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return 22.822% Drawdown 0.500% Expectancy 0 Net Profit 0% Sharpe Ratio 3.101 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha NaN Beta NaN Annual Standard Deviation 0.055 Annual Variance 0.003 Information Ratio NaN Tracking Error NaN Treynor Ratio NaN Total Fees $2.00 |
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 VolatilityETN : QCAlgorithm { string shortTerm = "XIV"; string longTerm = "ZIV"; decimal diff = 0; DateTime sampledToday; //Initialize the data and resolution you require for your strategy: public override void Initialize() { // Code Automaticly Generated SetStartDate(2015,8,10); SetEndDate(2015,9,30); SetCash(10000); // Code Automaticly Generated AddSecurity(SecurityType.Equity, "ZIV", Resolution.Daily); // Code Automaticly Generated AddSecurity(SecurityType.Equity, "XIV", Resolution.Daily); } public void OnData(TradeBars data) { diff = data[shortTerm].Close - data[longTerm].Close; // add logic to have orders placed once / day Log("XIV " + data[shortTerm].Close + " ZIV = " + data[longTerm].Close + " diff is " + diff); // Add buy/sell logic int count = new int(); if (diff > -5){ count = 4; } else if (diff < -5 && diff > -9) { count = 2; } else if (diff < -9) { count = 1; } switch (count) { case 1: SetHoldings(longTerm, 0); SetHoldings(shortTerm, 0.95); break; case 2: SetHoldings(shortTerm, 0.25); SetHoldings(longTerm, 0); break; case 3: //SetHoldings(shortTerm, -.25); //SetHoldings(longTerm, .75); break; case 4: //SetHoldings(shortTerm, -.10); //SetHoldings(longTerm, .90); SetHoldings(shortTerm, 0); SetHoldings(longTerm, 0.95); break; default: Log("there is an error"); break; } sampledToday = Time; } } }