Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 12.416% Drawdown 33.700% Expectancy 0 Net Profit 101.892% Sharpe Ratio 0.7 Probabilistic Sharpe Ratio 18.583% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.134 Beta -0.15 Annual Standard Deviation 0.166 Annual Variance 0.028 Information Ratio -0.003 Tracking Error 0.252 Treynor Ratio -0.775 Total Fees $2.72 |
from typing import List from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Algorithm.Framework.Alphas import AlphaModel, Insight from QuantConnect.Algorithm.Framework.Execution import ImmediateExecutionModel from QuantConnect.Algorithm.Framework.Portfolio import InsightWeightingPortfolioConstructionModel from QuantConnect.Algorithm.Framework.Risk import NullRiskManagementModel from QuantConnect.Algorithm.Framework.Selection import NullUniverseSelectionModel from QuantConnect.Data import Slice from QuantConnect.Data.UniverseSelection import SecurityChanges from benchmark import InitBenchmark class MyAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 1, 1) self.SetCash(100_000) InitBenchmark(self, "SPY") self.AddUniverseSelection(NullUniverseSelectionModel()) self.AddAlpha(MyAlphaModel()) self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel()) class MyAlphaModel(AlphaModel): def Update(self, algorithm: QCAlgorithm, data: Slice) -> List[Insight]: insights = [] return insights def OnSecuritiesChanged(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None: for security in changes.AddedSecurities: continue for security in changes.RemovedSecurities: continue
from QuantConnect import Resolution from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Data import Slice from benchmark import InitBenchmark class MyAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.SetStartDate(2015, 1, 1) self.SetCash(100_000) InitBenchmark(self, "SPY") self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol def OnData(self, data: Slice) -> None: if not self.Portfolio.Invested: self.SetHoldings(self.spy, 1)
from typing import Union from QuantConnect import Series, Chart, SeriesType, SecurityType from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Benchmarks import SecurityBenchmark from System import DayOfWeek from System.Drawing import Color BENCHMARK_CHART_NAME = "Strategy Equity" class BenchmarkContext: benchmark_series_name: str benchmark_starting_price: float benchmark_starting_cash: float def InitBenchmark(algorithm: Union[QCAlgorithm, BenchmarkContext], symbol: str, security_type: SecurityType = SecurityType.Equity) -> None: algorithm.SetBenchmark(security_type, symbol) InitBenchmarkPlotting(algorithm) def InitBenchmarkPlotting(algorithm: Union[QCAlgorithm, BenchmarkContext]) -> None: algorithm.benchmark_series_name = None algorithm.benchmark_starting_price = None algorithm.benchmark_starting_cash = algorithm.Portfolio.Cash # Only plot once a week to avoid hitting the limit of 4000 data points algorithm.Schedule.On(algorithm.DateRules.Every(DayOfWeek.Monday), algorithm.TimeRules.Midnight, lambda: PlotBenchmark(algorithm)) def InitBenchmarkSeries(algorithm: Union[QCAlgorithm, BenchmarkContext]) -> None: benchmark = algorithm.Benchmark if isinstance(benchmark, SecurityBenchmark): algorithm.benchmark_series_name = f"Benchmark ({benchmark.Security.Symbol.Value})" else: algorithm.benchmark_series_name = "Benchmark" chart = Chart(BENCHMARK_CHART_NAME) chart.AddSeries(Series(algorithm.benchmark_series_name, SeriesType.Line, "$", Color.Black)) algorithm.AddChart(chart) def PlotBenchmark(algorithm: Union[QCAlgorithm, BenchmarkContext]) -> None: if algorithm.benchmark_series_name is None: InitBenchmarkSeries(algorithm) if algorithm.benchmark_starting_price is None or algorithm.benchmark_starting_price == 0: algorithm.benchmark_starting_price = algorithm.Benchmark.Evaluate(algorithm.Time) if algorithm.benchmark_starting_price == 0: algorithm.Plot(BENCHMARK_CHART_NAME, algorithm.benchmark_series_name, algorithm.benchmark_starting_cash) return benchmark_price = algorithm.Benchmark.Evaluate(algorithm.Time) benchmark_value = (benchmark_price / algorithm.benchmark_starting_price) * algorithm.benchmark_starting_cash algorithm.Plot(BENCHMARK_CHART_NAME, algorithm.benchmark_series_name, benchmark_value)
from typing import List from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Algorithm.Framework.Alphas import AlphaModel, Insight from QuantConnect.Algorithm.Framework.Execution import ImmediateExecutionModel from QuantConnect.Algorithm.Framework.Portfolio import InsightWeightingPortfolioConstructionModel from QuantConnect.Algorithm.Framework.Selection import NullUniverseSelectionModel from QuantConnect.Brokerages import AlphaStreamsBrokerageModel from QuantConnect.Data import Slice from QuantConnect.Data.UniverseSelection import SecurityChanges from benchmark import InitBenchmarkPlotting class MyAlgorithm(QCAlgorithm): def Initialize(self): # @formatter:off # The blocked section of code below is to remain UNCHANGED for the weekly competitions. # # Insight-weighting portfolio construction model: # - You can change the rebalancing date rules or portfolio bias # - For more info see https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Portfolio/InsightWeightingPortfolioConstructionModel.py # # Use the Alpha Streams Brokerage Model: # - Developed in conjunction with funds to model their actual fees, costs, etc. Please do not modify other models. ############################################################################################################################### self.SetStartDate(2015, 3, 1) # 5 years up to the submission date self.SetCash(1000000) # Set $1m Strategy Cash to trade significant AUM self.SetBenchmark('SPY') # SPY Benchmark self.SetBrokerageModel(AlphaStreamsBrokerageModel()) self.SetExecution(ImmediateExecutionModel()) self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel()) ############################################################################################################################### # Do not change the code above # @formatter:on InitBenchmarkPlotting(self) self.AddUniverseSelection(NullUniverseSelectionModel()) self.AddAlpha(MyAlphaModel()) class MyAlphaModel(AlphaModel): def Update(self, algorithm: QCAlgorithm, data: Slice) -> List[Insight]: insights = [] return insights def OnSecuritiesChanged(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None: for security in changes.AddedSecurities: continue for security in changes.RemovedSecurities: continue