#-*-coding:utf-8-*-"""statistics of stock gains over a period of time"""" "Import Module" "ImportOSImportSQLAlchemyImportPandas" "Clear Screen" "CLS=os.system ('CLS')" "connecting to a database" "engine= Sqlalchemy.create_engine ('Mssql+pyodbc://sa:[email protected]') Connection=Engine.connect ()" "Stock code List" "Codelist= Pandas.read_sql ('Codelist', Engine)" "calculates the gain of each stock for a period of time by a list of stock codes" "Rise= [] forIinchRange (0, Len (codelist)-1): Dataframe= Pandas.read_sql (codelist['Code'][i], engine)" "Note that the original database date sorting is from large to small" " forJinchRange (0, Len (dataframe)-1): ifdataframe['Date'][J] = ='2016-02-15': A= dataframe['Open'][j]ifdataframe['Date'][J] = ='2016-01-15': b= dataframe['Open'][j]" "not yet. When the stock data is 0 or null for the date of the transaction, then again, it's just a rough test." " if not(A = = 0) and not(b = =0): C= (A-B)/b Break Else: C=0 Break " "What a row of data should include" "rise.append ((codelist['Code'][i], C,'2016-02-15','2016-01-15'))" "List Turn Dataframe" "Rise=Pandas. DataFrame (Rise)" "Modify column names" "Rise.columns= ['Code','Rise','date_to','Date_from']" "Sort by gains" "Rise= Rise.sort (columns ='Rise', ascending =False)" "Write Library" "Rise.to_sql ('Rise', engine, if_exists ='Replace', index = False)
Statistics of stock gains over a period of time