Statistics of stock gains over a period of time

Source: Internet
Author: User

#-*-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.