Jul-16-2017, 07:35 PM
Dear Python Users,
Please, can you help me with the following issue. I downloaded a stock price from google. Sorted the prices. What I need to do now is to pick 8 prices starting at the beginning of the consecutive months (the closest date, since not all times stocks trade on the 1st of the month). Say, if the randomly assigned starting month is January then the 2nd price is picked from February, 3rd from March, etc. This should be random. Once, the prices are picked they should be allocated to excel file. I attach the code I have below. Please, advise me this issue
Please, can you help me with the following issue. I downloaded a stock price from google. Sorted the prices. What I need to do now is to pick 8 prices starting at the beginning of the consecutive months (the closest date, since not all times stocks trade on the 1st of the month). Say, if the randomly assigned starting month is January then the 2nd price is picked from February, 3rd from March, etc. This should be random. Once, the prices are picked they should be allocated to excel file. I attach the code I have below. Please, advise me this issue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import pandas as pd import datetime #import pandas.io.data as web import pandas_datareader.data as web from matplotlib import style style.use( 'ggplot' ) start = datetime.datetime( 2010 , 1 , 1 ) end = datetime.datetime.today().strftime( "%m/%d/%Y" ) stock = web.DataReader( "AMZN" , "google" , start, end) stock1 = stock[ 'Close' ] #pick the column - close price stock1 = stock1.resample( 'BMS' , how = 'first' ) #sort the data following the calendar dates |