Skip to content

Commit

Permalink
Trello QuantConnect#1862. Updated BasicTemplateOptionsAlgorithm to be…
Browse files Browse the repository at this point in the history
… less strict. New version of the algo should work with any symbol. Updated corresponding regression test.
  • Loading branch information
quant1729 committed Feb 8, 2017
1 parent 0e0e6a9 commit 90e926e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
27 changes: 12 additions & 15 deletions Algorithm.CSharp/BasicTemplateOptionsAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public override void Initialize()
{
SetStartDate(2015, 12, 24);
SetEndDate(2015, 12, 24);
SetCash(10000);
SetCash(100000);

var equity = AddEquity(UnderlyingTicker);
var option = AddOption(UnderlyingTicker);

// set our strike/expiry filter for this option chain
option.SetFilter(u => u.IncludeWeeklys()
.Strikes(-2, +2)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(10)));
option.SetFilter(u => u.Strikes(-2, +2)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));

// use the underlying equity as the benchmark
SetBenchmark(equity.Symbol);
Expand All @@ -63,19 +62,17 @@ public override void OnData(Slice slice)
OptionChain chain;
if (slice.OptionChains.TryGetValue(OptionSymbol, out chain))
{
// find the second call strike under market price expiring today
var contract = (
from optionContract in chain.OrderByDescending(x => x.Strike)
where optionContract.Right == OptionRight.Call
where optionContract.Expiry == Time.Date
where optionContract.Strike < chain.Underlying.Price
select optionContract
).Skip(2).FirstOrDefault();
// we find at the money (ATM) contract with farthest expiration
var atmContract = chain
.OrderByDescending(x => x.Expiry)
.ThenBy(x => Math.Abs(chain.Underlying.Price - x.Strike))
.FirstOrDefault();

if (contract != null)
if (atmContract != null)
{
MarketOrder(contract.Symbol, 1);
MarketOnCloseOrder(contract.Symbol, -1);
// if found, trade it
MarketOrder(atmContract.Symbol, 1);
MarketOnCloseOrder(atmContract.Symbol, -1);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/RegressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ private static TestCaseData[] GetRegressionTestParameters()
{
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "-3.86%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "3.900%"},
{"Average Loss", "-0.21%"},
{"Compounding Annual Return", "-68.001%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Net Profit", "-3.855%"},
{"Net Profit", "-0.210%"},
{"Sharpe Ratio", "0"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
Expand Down

0 comments on commit 90e926e

Please sign in to comment.