Monthly Stock Returns

Monthly Stock Returns

Storing daily stock returns is easy with Yahoo finance. But sometimes you need monthly stock returns. This sql code will show you how to turn daily data into monthly data. The stock data is stored in a MySQL database and is retrieved from Yahoo. To compute the monthly returns from the daily returns, this mysql query is used:

SELECT trade_date,adj_close
from stock_data
where trade_date BETWEEN '2011-06-27' AND '2014-06-24'
and symbol = 'FVDKX'

and trade_date in
select min(trade_date) from stock_data
where trade_date BETWEEN '2011-06-27' AND '2014-06-24'
and symbol = 'FVDKX'
group by month(trade_date),year(trade_date)
order by trade_date
order by trade_date;

You can also convert daily data into monthly data in python. If you have a dataframe with an index that is a date column, you can do this with the dataframe:

Stocks = Stocks.resample("M", how='mean')

Where “Stocks” is your dataframe which contains your date index and columns of your return data.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 − 1 =