Overall Statistics
Total Trades
369
Average Win
0.94%
Average Loss
-0.25%
Compounding Annual Return
12.275%
Drawdown
6.500%
Expectancy
2.056
Net Profit
140.765%
Sharpe Ratio
1.064
Probabilistic Sharpe Ratio
53.834%
Loss Rate
36%
Win Rate
64%
Profit-Loss Ratio
3.77
Alpha
0.085
Beta
0.015
Annual Standard Deviation
0.082
Annual Variance
0.007
Information Ratio
-0.091
Tracking Error
0.173
Treynor Ratio
5.756
Total Fees
$1045.23
Estimated Strategy Capacity
$13000000.00
Lowest Capacity Asset
BIL TT1EBZ21QWKL
Portfolio Turnover
4.42%
from AlgorithmImports import *
from datetime import datetime, timedelta

class CustomDataWeighAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016,1, 1)
        self.SetEndDate(2023, 8, 1)
        self.SetCash(100000)

        # Define the symbol and "type" of our generic data:
        self.AddData(Weigh, "Weigh")
        self.symbols = "SPY", "SPXL", "UVXY", "SSO","BIL","TQQQ","QLD","UUP","SOXL"
 
        # Inizializza un dizionario per memorizzare le allocazioni iniziali degli asset
        #self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(0.10))
        
        # 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"]
        #self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(0.10))
        
        # Stampa i valori degli indici
        self.Debug(f"Data Time: {index_data.Time}, SPY: {index_data['SPY']}")
        self.Debug(f"Data Time: {index_data.Time}, SPXL: {index_data['SPXL']}")
        self.Debug(f"Data Time: {index_data.Time}, UVXY: {index_data['UVXY']}")
        self.Debug(f"Data Time: {index_data.Time}, SSO: {index_data['SSO']}")
        self.Debug(f"Data Time: {index_data.Time}, BIL: {index_data['BIL']}")
        self.Debug(f"Data Time: {index_data.Time}, TQQQ: {index_data['TQQQ']}")
        self.Debug(f"Data Time: {index_data.Time}, QLD: {index_data['QLD']}")
        self.Debug(f"Data Time: {index_data.Time}, USD: {index_data['USD']}")
        self.Debug(f"Data Time: {index_data.Time}, SOXL: {index_data['SOXL']}")
       
       
      
        
        
        #self.SetHoldings("MDY",index_data['QQQ'])
        self.SetHoldings("UVXY",index_data['UVXY']*0.95)
        self.SetHoldings("SPY",index_data['SSO']*0.95)
        self.SetHoldings("BIL",index_data['BIL']*0.95)
        self.SetHoldings("QQQ",index_data['QLD']*0.95)
        self.SetHoldings("SMH",index_data['USD']*0.95)


       # self.SetHoldings("QQQ",index_data['QQQ'])

    def BeforeClose(self):
        # Put the code you want to execute before market close here
        pass
       
        

        
class Weigh(PythonData):
    '''Weigh Custom Data Class'''
    def GetSource(self, config, date, isLiveMode):
        return SubscriptionDataSource("https://www.dropbox.com/scl/fi/c8fclsnt05pyxp5j6rzf0/Weightss_0.csv?rlkey=9259nmjn0xp2u6pnsui9ad1kt&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["SPY"] = float(data[1])
            index["SPXL"] = float(data[2])
            index["UVXY"] = float(data[3])
            index["SSO"] = float(data[4])
            index["BIL"] = float(data[5])
            index["TQQQ"] = float(data[6])
            index["QLD"] = float(data[7])
            index["USD"] = float(data[8])
            index["SOXL"] = float(data[9])
          #  index["QQQ"] = float(data[5])
            
        except ValueError as e:
            self.Debug(f"Errore nella lettura dei dati: {str(e)}")
            return None

        return index