| Overall Statistics |
|
Total Orders 10 Average Win 0% Average Loss 0% Compounding Annual Return 19.619% Drawdown 30.100% Expectancy 0 Start Equity 5000 End Equity 29055.76 Net Profit 481.115% Sharpe Ratio 0.711 Sortino Ratio 0.748 Probabilistic Sharpe Ratio 23.594% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.026 Beta 1.046 Annual Standard Deviation 0.171 Annual Variance 0.029 Information Ratio 0.426 Tracking Error 0.07 Treynor Ratio 0.117 Total Fees $10.00 Estimated Strategy Capacity $500000000.00 Lowest Capacity Asset BRKB R735QTJ8XC9X Portfolio Turnover 0.03% Drawdown Recovery 568 |
# # region imports
# from AlgorithmImports import *
# # endregion
# class SleepyFluorescentOrangeViper(QCAlgorithm):
# def initialize(self):
# self.set_start_date(2016, 2, 8)
# self.set_cash(5000)
# self.add_equity("SPY", Resolution.MINUTE)
# self.add_equity("BND", Resolution.MINUTE)
# self.add_equity("AAPL", Resolution.MINUTE)
# def on_data(self, data: Slice):
# if not self.portfolio.invested:
# self.set_holdings("SPY", 0.33)
# self.set_holdings("BND", 0.33)
#
# self.set_holdings("AAPL", 0.33)
# region imports
from AlgorithmImports import *
from collections import OrderedDict
# endregion
class NeuroFundCoinHold(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2016, 2, 4)
self.SetCash(5000)
self.weights = OrderedDict([
("AAPL", 0.10037),
("GOOG", 0.10083),
("MSFT", 0.10100),
("XOM", 0.09916),
("AMZN", 0.10167),
("BRK.B",0.09786),
("GE", 0.10070),
("META", 0.10131),
("JNJ", 0.09557),
("WFC", 0.10154)
])
self.symbols = []
for ticker in self.weights:
equity = self.AddEquity(ticker, Resolution.Daily)
equity.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
self.symbols.append(equity.Symbol)
self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
self.spy_start_price = None
self.rebalanced = False
def OnData(self, data: Slice):
# ---------- SPY synthetic benchmark (runs every bar) ----------
if self.spy in data:
bar = data[self.spy]
if bar is not None:
if self.spy_start_price is None:
self.spy_start_price = bar.Close
else:
spy_return = bar.Close / self.spy_start_price
spy_equity = 5000 * spy_return
self.Plot("Comparison", "SPY Buy&Hold", spy_equity)
self.Plot("Comparison", "My Strategy", self.Portfolio.TotalPortfolioValue)
# ---------- One-time rebalance logic ----------
if self.rebalanced:
return
# Ensure all prices are available before investing
if not all(data.ContainsKey(sym) for sym in self.symbols):
return
for ticker, weight in self.weights.items():
self.SetHoldings(ticker, weight)
self.rebalanced = True
# from AlgorithmImports import *
# from collections import OrderedDict
# class NeuroFundCoinHold(QCAlgorithm):
# def Initialize(self):
# self.SetStartDate(2016, 2, 4)
# self.SetCash(5000)
# # ================= PARAMETERS =================
# self.TRAILING_STOP_PCT = 0.06
# self.REENTER_PCT = 0.06
# self.weights = OrderedDict([
# ("AAPL", 0.10037),
# ("GOOG", 0.10083),
# ("MSFT", 0.10100),
# ("XOM", 0.09916),
# ("AMZN", 0.10167),
# ("BRK.B",0.09786),
# ("GE", 0.10070),
# ("META", 0.10131),
# ("JNJ", 0.09557),
# ("WFC", 0.10154)
# ])
# self.symbols = []
# self.state = {} # per-asset state container
# for ticker in self.weights:
# equity = self.AddEquity(ticker, Resolution.Daily)
# equity.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
# symbol = equity.Symbol
# self.symbols.append(symbol)
# # ---------- PER-ASSET STATE ----------
# self.state[symbol] = {
# "highest_price": None,
# "stop_price": None,
# "stopout_price": None,
# "reenter_price": None,
# "stopped_out": False
# }
# # Benchmark
# self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
# self.spy_start_price = None
# self.rebalanced = False
# def OnData(self, data: Slice):
# # ---------- SPY synthetic benchmark ----------
# if self.spy in data:
# bar = data[self.spy]
# if bar:
# if self.spy_start_price is None:
# self.spy_start_price = bar.Close
# else:
# spy_return = bar.Close / self.spy_start_price
# spy_equity = 5000 * spy_return
# self.Plot("Comparison", "SPY Buy&Hold", spy_equity)
# self.Plot("Comparison", "My Strategy", self.Portfolio.TotalPortfolioValue)
# # ---------- Initial allocation ----------
# if not self.rebalanced:
# if not all(data.ContainsKey(sym) for sym in self.symbols):
# return
# for ticker, weight in self.weights.items():
# self.SetHoldings(ticker, weight)
# self.rebalanced = True
# return
# # ---------- Stop / Re-entry logic ----------
# for symbol in self.symbols:
# bar = data.Bars.get(symbol)
# if bar is None:
# continue
# price = bar.Close
# s = self.state[symbol]
# invested = self.Portfolio[symbol].Invested
# # ===== IF INVESTED: TRAILING STOP =====
# if invested and not s["stopped_out"]:
# # Initialize on first bar
# if s["highest_price"] is None:
# s["highest_price"] = price
# s["stop_price"] = price * (1 - self.TRAILING_STOP_PCT)
# continue
# # Update trailing high
# if price > s["highest_price"]:
# s["highest_price"] = price
# s["stop_price"] = price * (1 - self.TRAILING_STOP_PCT)
# # Stop hit
# if price <= s["stop_price"]:
# self.Liquidate(symbol)
# s["stopped_out"] = True
# s["stopout_price"] = price
# s["reenter_price"] = price * (1 - self.REENTER_PCT)
# # reset trailing values
# s["highest_price"] = None
# s["stop_price"] = None
# # ===== IF STOPPED OUT: RE-ENTER =====
# elif s["stopped_out"] and not invested:
# if price <= s["reenter_price"]:
# self.SetHoldings(symbol, self.weights[symbol.Value])
# # reset state after re-entry
# s["stopped_out"] = False
# s["highest_price"] = price
# s["stop_price"] = price * (1 - self.TRAILING_STOP_PCT)
# s["stopout_price"] = None
# s["reenter_price"] = None