Overall Statistics |
Total Orders 108 Average Win 7.47% Average Loss -4.24% Compounding Annual Return 19.708% Drawdown 32.800% Expectancy 1.294 Start Equity 1000000 End Equity 15109866.50 Net Profit 1410.987% Sharpe Ratio 0.773 Sortino Ratio 0.831 Probabilistic Sharpe Ratio 19.731% Loss Rate 17% Win Rate 83% Profit-Loss Ratio 1.76 Alpha 0 Beta 0 Annual Standard Deviation 0.17 Annual Variance 0.029 Information Ratio 0.876 Tracking Error 0.17 Treynor Ratio 0 Total Fees $8324.64 Estimated Strategy Capacity $570000000.00 Lowest Capacity Asset GOOCV VP83T1ZUHROL Portfolio Turnover 0.51% |
from AlgorithmImports import * from random import random def add_months(current_date, months_to_add): year = current_date.year month = current_date.month + months_to_add while month > 12: year += 1 month -= 12 new_date = datetime(year,month,1) while new_date.weekday() >= 5: # Adjust for weekdays new_date += timedelta(days=1) return new_date class MyAlgorithm(QCAlgorithm): def change(self, before, after): diff = after-before return diff/before def OnEndOfAlgorithm(self): self.Liquidate() def Initialize(self): self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE, AccountType.Cash) self.tickers = ["MSFT", "AAPL", "SPY", "GOOG"] self.holdMonths = 12 self.END_YEAR = 2025 self.set_start_date(2010, 1, 1) self.set_end_date(self.END_YEAR, 2, 1) self.set_cash(1000000) for ticker in self.tickers: self.AddEquity(ticker, Resolution.DAILY, leverage=1) # Get Data for 6 years before the start of calculations self.nextSellTime = self.Time self.nextBuyTime = self.Time def on_data(self, data: Slice): if self.Time.weekday() >= 5: return # During the weekend if self.Time > DateTime(self.END_YEAR,1,1): # One month before the "end" of the algorithm self.Liquidate() elif self.nextSellTime <= self.Time: self.Liquidate() self.nextSellTime = add_months(self.Time, self.holdMonths) self.nextBuyTime = self.Time + timedelta(days=5) elif self.nextBuyTime <= self.Time: # Should buy again randomAllocations = dict() for ticker in self.tickers: randomAllocations[ticker] = random() randomAllocations = dict([(ticker, percentage/sum(randomAllocations.values()) * 0.99) for ticker, percentage in randomAllocations.items()]) self.log(str(sum(randomAllocations.values())) + " " + str(randomAllocations)) holdings = [PortfolioTarget(ticker, percentage) for ticker, percentage in randomAllocations.items()] self.set_holdings(holdings) self.nextBuyTime += timedelta(days=100000) #never