I need to add new columns called 'Volume % Change', and "Close % Change" for this dataframe in PYTHON. The data is from yahoo finance, so it's always changable depends on the days entered. the syntax...


I need to add new columns called 'Volume % Change', and "Close % Change" for this dataframe in PYTHON.


The data is from yahoo finance, so it's always changable depends on the days entered.


the syntax is below:


import pandas_datareader as pdr
import datetime
import pandas as pd


# Allow the full width of the data frame to show.
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)


def getStock(stk):
# Set and show dates.
dt = datetime.date.today()
dtPast = dt + datetime.timedelta(days=-5)
print(dt)
print(dtPast)


# Call Yahoo finance to get stock data for the stock provided.
df = pdr.get_data_yahoo(stk,
start= datetime.datetime(dtPast.year, dtPast.month, dtPast.day),
end = datetime.datetime(dt.year, dt.month, dt.day))


# Return a dataframe containing stock data to the calling instruction.
return df


dfMSFT = getStock("MSFT")
print(dfMSFT)


--------------------------------------------------------------------------


The formula for Volume % Change is(Current day volume-previous day volume)/previous day volume


The formula for Close % Change is (Current day Close - previous day)/previous day Close


The output is like the attached image.


Please assist!


Thanks


Close<br>Volume<br>Volume * Change<br>close Change<br>Date<br>2021-01-15<br>212.649994<br>31691500<br>0.0000<br>0.0000<br>2021-01-19<br>216.440002<br>30480900<br>-0.0382<br>0.0178<br>2021-01-20<br>224.339996<br>37777260<br>0.2394<br>0.0365<br>

Extracted text: Close Volume Volume * Change close Change Date 2021-01-15 212.649994 31691500 0.0000 0.0000 2021-01-19 216.440002 30480900 -0.0382 0.0178 2021-01-20 224.339996 37777260 0.2394 0.0365

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here