Overall Statistics |
Total Trades 1512 Average Win 0.67% Average Loss -0.70% Compounding Annual Return 4.804% Drawdown 24.000% Expectancy 0.062 Net Profit 31.348% Sharpe Ratio 0.408 Probabilistic Sharpe Ratio 6.056% Loss Rate 46% Win Rate 54% Profit-Loss Ratio 0.96 Alpha 0.016 Beta 0.166 Annual Standard Deviation 0.092 Annual Variance 0.008 Information Ratio -0.579 Tracking Error 0.154 Treynor Ratio 0.226 Total Fees $15394.53 Estimated Strategy Capacity $370000.00 Lowest Capacity Asset TMF UBTUG7D0B7TX Portfolio Turnover 25.22% |
from AlgorithmImports import * from datetime import datetime, timedelta class CustomDataWeighAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2016, 1, 1) # self.SetEndDate(2023, 2, 1) self.SetCash(100000) # Define the symbol and "type" of our generic data: self.AddData(Weigh, "Weigh") self.symbols = [ "SHY", "VIXM", "BND", "BIL", "TLT", "TECL", "TQQQ", "UPRO", "TMF", "QID", "TBF", "USDU", "IEI", "GLD", "TIP", "BSV", "SPY" ] # Inizializza un dizionario per memorizzare le allocazioni iniziali degli asset # Aggiungi tutti gli asset con risoluzione giornaliera (daily) for symbol in self.symbols: self.AddEquity(symbol, Resolution.Daily) def OnData(self, data): if not data.ContainsKey("Weigh"): return index_data = data["Weigh"] # Stampa i valori degli indici self.Debug(f"Data Time: {index_data.Time}, SHY: {index_data['SHY']}") self.Debug(f"Data Time: {index_data.Time}, VIXM: {index_data['VIXM']}") self.Debug(f"Data Time: {index_data.Time}, BND: {index_data['BND']}") self.Debug(f"Data Time: {index_data.Time}, BIL: {index_data['BIL']}") self.Debug(f"Data Time: {index_data.Time}, TLT: {index_data['TLT']}") self.Debug(f"Data Time: {index_data.Time}, TECL: {index_data['TECL']}") self.Debug(f"Data Time: {index_data.Time}, TQQQ: {index_data['TQQQ']}") self.Debug(f"Data Time: {index_data.Time}, UPRO: {index_data['UPRO']}") self.Debug(f"Data Time: {index_data.Time}, TMF: {index_data['TMF']}") self.Debug(f"Data Time: {index_data.Time}, QID: {index_data['QID']}") self.Debug(f"Data Time: {index_data.Time}, USDU: {index_data['USDU']}") self.Debug(f"Data Time: {index_data.Time}, IEI: {index_data['IEI']}") self.Debug(f"Data Time: {index_data.Time}, GLD: {index_data['GLD']}") self.Debug(f"Data Time: {index_data.Time}, BSV: {index_data['BSV']}") self.Debug(f"Data Time: {index_data.Time}, SPY: {index_data['SPY']}") if index_data['QID'] > 0: self.SetHoldings("QID",index_data['QID']) else: self.Liquidate() if index_data['USDU'] > 0: self.SetHoldings("USDU",index_data['USDU']) else: self.Liquidate() if index_data['TBF'] > 0: self.SetHoldings("TBF",index_data['TBF']) else: self.Liquidate() if index_data['SHY'] > 0: self.SetHoldings("SHY",index_data['SHY']) else: self.Liquidate() if index_data['TQQQ'] > 0: self.SetHoldings("TQQQ",index_data['TQQQ']) else: self.Liquidate() if index_data['TECL'] > 0: self.SetHoldings("TECL",index_data['TECL']) else: self.Liquidate() if index_data['IEI'] > 0: self.SetHoldings("IEI",index_data['IEI']) else: self.Liquidate() if index_data['GLD'] > 0: self.SetHoldings("GLD",index_data['GLD']) else: self.Liquidate() if index_data['BSV'] > 0: self.SetHoldings("BSV",index_data['BSV']) else: self.Liquidate() if index_data['UPRO'] > 0: self.SetHoldings("UPRO",index_data['UPRO']) else: self.Liquidate() if index_data['TMF'] > 0: self.SetHoldings("TMF",index_data['TMF']) else: self.Liquidate() class Weigh(PythonData): '''Weigh Custom Data Class''' def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/scl/fi/potp7czdbwk0erwjbybq2/Weights_.csv?rlkey=2c60wr2ulqs4by7kdhnj61nk3&dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLiveMode): if not (line.strip() and line[0].isdigit()): return None index = Weigh() index.Symbol = config.Symbol try: # Example File Format: data = line.split(',') index.Time = datetime.strptime(data[0], "%Y-%m-%d") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["SHY"] = float(data[1]) index["VIXM"] = float(data[2]) index["BND"] = float(data[3]) index["BIL"] = float(data[4]) index["TLT"] = float(data[5]) index["TECL"] = float(data[6]) index["TQQQ"] = float(data[7]) index["UPRO"] = float(data[8]) index["TMF"] = float(data[9]) index["QID"] = float(data[10]) index["TBF"] = float(data[11]) index["USDU"] = float(data[12]) index["IEI"] = float(data[13]) index["GLD"] = float(data[14]) index["TIP"] = float(data[15]) index["BSV"] = float(data[16]) index["SPY"] = float(data[17]) except ValueError as e: self.Debug(f"Errore nella lettura dei dati: {str(e)}") return None return index