Overall Statistics
Total Trades
540
Average Win
0.00%
Average Loss
-1.24%
Compounding Annual Return
0%
Drawdown
200.000%
Expectancy
-0.764
Net Profit
-200.045%
Sharpe Ratio
-0.181
Probabilistic Sharpe Ratio
0.322%
Loss Rate
76%
Win Rate
24%
Profit-Loss Ratio
0.00
Alpha
-3.531
Beta
2.058
Annual Standard Deviation
5.529
Annual Variance
30.573
Information Ratio
-0.404
Tracking Error
5.522
Treynor Ratio
-0.486
Total Fees
$0.00
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from datetime import timedelta
import pandas as pd
from io import StringIO
import datetime

 
class main(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019,1,1)  # Set Start Date
        #self.SetEndDate(2020,12,31)# Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        
        # If using dropbox remember to add the &dl=1 to trigger a download
        csv = self.Download("https://www.dropbox.com/s/9zspyj9sdc7pyct/test_2.csv?dl=1")
        
        
        # csv = self.Download("https://www.dropbox.com/s/2hlxb85lo7y10i3/test.csv?dl=1")
        # read file (which needs to be a csv) to a pandas DataFrame. include following imports above
    
        self.df = pd.read_csv(StringIO(csv))
        
        self.SetExecution(ImmediateExecutionModel())
        self.AveragePrice = None

        for i in range(len(self.df)) :
            self.security=str(self.df.iloc[i,0]).replace(" ", "")
            #self.quantity=self.df.iloc[i,1]
            self.AddEquity(self.security,Resolution.Minute).SetDataNormalizationMode(DataNormalizationMode.Raw)

        ############## SLIPPAGE & FEE MODEL####################################################################
            self.Securities[self.security].FeeModel = ConstantFeeModel(0)
            self.Securities[self.security].SlippageModel = ConstantSlippageModel(0)
        
    
    def OnData(self, slice):

        
        for i in range(len(self.df)):
                if slice.Time.hour==self.df.iloc[i,4] and slice.Time.minute==self.df.iloc[i,5]:    
                    self.MarketOrder(str(self.df.iloc[i,0]).replace(" ", ""),self.df.iloc[i,1])
                    self.df.iloc[i, 8] = self.Portfolio[str(self.df.iloc[i,0]).replace(" ", "")].AveragePrice
                    

        for i in range(len(self.df)):
            if not slice.Bars.ContainsKey(str(self.df.iloc[i,0]).replace(" ", "")): return
        
            if self.df.iloc[i,8] != None :
                    if (slice[str(self.df.iloc[i,0]).replace(" ", "")].Price > self.df.iloc[i,8] * self.df.iloc[i,3]):
                        self.Liquidate(str(self.df.iloc[i,0]).replace(" ", "")," TAKE PROFIT @ " + str(slice[str(self.df.iloc[i,0]).replace(" ", "")].Price) +" AverageFillPrice " +str(self.df.iloc[i,8]))
                    if (slice[str(self.df.iloc[i,0]).replace(" ", "")].Price < self.df.iloc[i,8] * self.df.iloc[i,2]):
                        self.Liquidate(str(self.df.iloc[i,0]).replace(" ", "")," STOP LOSS @ " + str(slice[str(self.df.iloc[i,0]).replace(" ", "")].Price) +" AverageFillPrice " +str(self.df.iloc[i,8]))
        
        for i in range(len(self.df)):
                if slice.Time.hour==self.df.iloc[i,6] and slice.Time.minute==self.df.iloc[i,7]:
                    self.Liquidate(str(self.df.iloc[i,0]).replace(" ", ""))