| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Orders;
using QuantConnect.Orders.Fees;
using QuantConnect.Orders.Fills;
using QuantConnect.Orders.Slippage;
using QuantConnect.Securities;
using QuantConnect.Securities.Option;
namespace QuantConnect.Algorithm.CSharp
{
public class AutomatonTrade : QCAlgorithm
{
// Universe symbols.
private static readonly string[] SYMBOLS = {
"TSLA"
};
// Historical storage.
private Dictionary<string, RollingWindow<decimal>> dailyCloses = new Dictionary<string, RollingWindow<decimal>>();
public override void Initialize()
{
// Initialize.
this.SetStartDate(2020, 9, 1);
this.SetEndDate(2020, 9, 2);
this.SetCash(10000);
this.SetTimeZone(TimeZones.NewYork);
this.SetWarmUp(50, Resolution.Daily);
// Setup brokerage.
this.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);
// Add everything.
foreach (string symbol in AutomatonTrade.SYMBOLS)
{
// Setup the equity and options.
Equity equity = this.AddEquity(symbol, Resolution.Minute);
equity.SetDataNormalizationMode(DataNormalizationMode.Raw);
Option option = this.AddOption(symbol, Resolution.Minute);
option.PriceModel = OptionPriceModels.CrankNicolsonFD();
option.SetFilter(u => u.WeeklysOnly().Strikes(-5, 1).Expiration(TimeSpan.Zero, TimeSpan.FromDays(14)));
// Consolidator.
var dailyConsolidator = TradeBarConsolidator.FromResolution(Resolution.Daily);
dailyConsolidator.DataConsolidated += this.OnDailyConsolidatedData;
this.SubscriptionManager.AddConsolidator(symbol, dailyConsolidator);
}
}
private void OnDailyConsolidatedData(object sender, TradeBar bar)
{
// Store 3 points of daily changes, current price - previous.
Symbol symbol = bar.Symbol;
decimal close = bar.Close;
if (!this.dailyCloses.ContainsKey(symbol))
{
this.dailyCloses.Add(symbol, new RollingWindow<decimal>(4));
}
this.dailyCloses[symbol].Add(close);
}
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// Slice object keyed by symbol containing the stock data.
public override void OnData(Slice data)
{
// Splits can occur during warm-up and must be processed.
foreach (var splitKvp in data.Splits)
{
Symbol symbol = splitKvp.Key;
Split split = splitKvp.Value;
this.Debug("SPLIT DETECTED (" + Math.Round(split.SplitFactor, 4) + "), wiping historical data...");
this.dailyCloses[symbol] = new RollingWindow<decimal>(4);
}
// Ignore warm-up data.
if (this.IsWarmingUp)
{
return;
}
var differences = this.dailyCloses["TSLA"].Zip(this.dailyCloses["TSLA"].Skip(1), (x, y) => x - y).ToArray();
this.Debug(string.Join(",", differences));
//IEnumerable<TradeBar> history = this.History(underlyingSymbol, 4, Resolution.Daily);
}
}
}