Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
16.013%
Drawdown
16.700%
Expectancy
0
Net Profit
25.035%
Sharpe Ratio
0.616
Sortino Ratio
0.834
Probabilistic Sharpe Ratio
42.565%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0
Beta
0.999
Annual Standard Deviation
0.142
Annual Variance
0.02
Information Ratio
-0.55
Tracking Error
0
Treynor Ratio
0.088
Total Fees
$1.31
Estimated Strategy Capacity
$1000000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
0.19%
# region imports
from AlgorithmImports import *
# endregion

class CustomBuyingPowerModelAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 6, 28)
        self.SetCash(100000)
        security = self.AddEquity("SPY", Resolution.Daily)
        security.SetBuyingPowerModel(MyBuyingPowerModel())

    def OnData(self, data: Slice):
        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)

class MyBuyingPowerModel(BuyingPowerModel):
    def __init__(self, 
        leverage: float = 2, 
        requiredFreeBuyingPowerPercent: float = 0):
        super().__init__(leverage, requiredFreeBuyingPowerPercent)

    def GetLeverage(self, security: Security) -> float: 
        return super().GetLeverage(security)

    def SetLeverage(self, security: Security, leverage: float) -> None: 
        super().SetLeverage(security, leverage)

    def GetInitialMarginRequiredForOrder(self,
         parameters: InitialMarginRequiredForOrderParameters) -> InitialMargin:
        return super().GetInitialMarginRequiredForOrder(parameters)

    def GetMaintenanceMargin(self,
         parameters: MaintenanceMarginParameters) -> MaintenanceMargin: 
        return super().GetMaintenanceMargin(parameters)

    def GetMarginRemaining(self,
         portfolio: SecurityPortfolioManager,
         security: Security,
         direction: OrderDirection) -> float: 
        return super().GetMarginRemaining(portfolio, security, direction)

    def GetInitialMarginRequirement(self,
         parameters: InitialMarginParameters) -> InitialMargin:
        return super().GetInitialMarginRequirement(parameters)

    def HasSufficientBuyingPowerForOrder(self, 
         parameters: HasSufficientBuyingPowerForOrderParameters
        ) -> HasSufficientBuyingPowerForOrderResult: 
        return super().HasSufficientBuyingPowerForOrder(parameters)

    def GetMaximumOrderQuantityForDeltaBuyingPower(self, 
         parameters: GetMaximumOrderQuantityForDeltaBuyingPowerParameters
        ) -> GetMaximumOrderQuantityResult:
        return super().GetMaximumOrderQuantityForDeltaBuyingPower(parameters)

    def GetMaximumOrderQuantityForTargetBuyingPower(self, 
         parameters: GetMaximumOrderQuantityForTargetBuyingPowerParameters
        ) -> GetMaximumOrderQuantityResult:
        return super().GetMaximumOrderQuantityForTargetBuyingPower(parameters)

    def GetReservedBuyingPowerForPosition(self, 
         parameters: ReservedBuyingPowerForPositionParameters
        ) -> ReservedBuyingPowerForPosition:
        return super().GetReservedBuyingPowerForPosition(parameters)

    def GetBuyingPower(self,
         parameters: BuyingPowerParameters) -> BuyingPower:
        return super().GetBuyingPower(parameters)