Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 16.459% Drawdown 17.800% Expectancy 0 Net Profit 117.196% Sharpe Ratio 0.906 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.037 Beta 6.649 Annual Standard Deviation 0.187 Annual Variance 0.035 Information Ratio 0.8 Tracking Error 0.187 Treynor Ratio 0.026 Total Fees $1.00 |
namespace QuantConnect.Algorithm.CSharp { public class buythedip : QCAlgorithm { //Member variables private static Symbol _google = QuantConnect.Symbol.Create("GOOGL", SecurityType.Equity, Market.USA); private int ForwardLookingPeriod = 25; private int BackwardLookingPeriod = 25; private decimal fallAmount = Convert.ToDecimal(0.1); private decimal riseAmount = Convert.ToDecimal(0.05); private int minutesToExecute = 10; private decimal relevantPrice; private RollingWindow<decimal> _close_window; public Boolean cash; public Boolean buyTrigger; public Boolean sellTrigger; public override void Initialize() { SetStartDate(2013,01,01); SetEndDate(2018,02,01); SetCash(30000); AddEquity(_google, Resolution.Daily); _close_window = new RollingWindow<decimal>(BackwardLookingPeriod); IEnumerable<TradeBar> slices = History(_google, BackwardLookingPeriod); foreach (TradeBar bar in slices) { _close_window.Add(bar.Close); } Debug(_close_window[0]); Console.WriteLine("Hugo Lu"); Schedule.On(DateRules.EveryDay(_google), TimeRules.AfterMarketOpen(_google,minutesToExecute), //Execute the function at the start of the day // x minutes in.... EveryDayOnMarketOpen); } public void EveryDayOnMarketOpen(){ //Define the bad boy //Sanity Check; are there open orders? if (Transactions.GetOpenOrders().Count > 0) { return; } //Get information about however many periods ago IEnumerable<TradeBar> slices = History(_google,BackwardLookingPeriod) ; TradeBar BarOfInterest = slices.First(); decimal relevantClose = BarOfInterest.Close; decimal yestClose = slices.Last().Close; decimal fallPercent = 1 - (yestClose/relevantClose); relevantPrice = yestClose; //Is it time to buy? if(fallPercent > fallAmount && Portfolio.Cash > 100 ) { buyTrigger = true; } else { buyTrigger = false; } if(buyTrigger) { SetHoldings(_google,1); } //Is it time to sell? if(((yestClose / relevantPrice)-1)> riseAmount) { Log("inside"); sellTrigger = true; } else { sellTrigger = false; } if(sellTrigger) { Liquidate(); }; } } }