| Overall Statistics |
|
Total Orders 2 Average Win 0% Average Loss 0% Compounding Annual Return -2.994% Drawdown 20.400% Expectancy 0 Start Equity 1000000 End Equity 970006.89 Net Profit -2.999% Sharpe Ratio -0.552 Sortino Ratio -0.57 Probabilistic Sharpe Ratio 9.041% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.017 Beta -0.399 Annual Standard Deviation 0.123 Annual Variance 0.015 Information Ratio -1.115 Tracking Error 0.177 Treynor Ratio 0.17 Total Fees $35.00 Estimated Strategy Capacity $260000000.00 Lowest Capacity Asset GOOCV VP83T1ZUHROL Portfolio Turnover 0.23% |
from AlgorithmImports import *
class ConditionalBuyAndHold(QCAlgorithm):
def Initialize(self):
# Basic setup
self.SetStartDate(2023, 6, 1)
self.SetEndDate(2024, 6, 1)
self.SetCash(1000000)
# Add securities with daily resolution
self.goog = self.AddEquity("GOOG", Resolution.Daily).Symbol
self.amzn = self.AddEquity("AMZN", Resolution.Daily).Symbol
self.orders_placed = False # making sure orders haven’t been placed yet when the algorithm starts
def OnData(self, data):
if not self.orders_placed and self.Time.date() == self.StartDate.date():
# Get first day's opening prices
goog_open = data[self.goog].Open
amzn_open = data[self.amzn].Open
# trigger prices (5% below/above opening)
goog_trigger = goog_open * 0.95
amzn_trigger = amzn_open * 1.05
# Place limit orders at trigger prices
self.LimitOrder(self.goog, 3000, goog_trigger) # Long GOOG when price drops 5%
self.LimitOrder(self.amzn, -4000, amzn_trigger) # Short AMZN when price rises 5%
self.orders_placed = True # making sure orders are placed only once