i'm a beginner in write code with python.
I wrote this simple script using Pandas and his DataReader to retrieve multiple stock results from yahoo finance:
import pandas as pd
from pandas.io.data import DataReader
from pandas import DataFrame
symbols_list = ['AAPL', 'TSLA', 'YHOO','GOOG', 'MSFT','GILD']
for ticker in symbols_list:
r = DataReader(ticker, "yahoo", '2015-01-20')
cell= r[['Open','High','Low','Adj Close','Volume']]
print cell
With this code i obtain the price stocks with the date + the others column that i specified in "cell= r[[...." as shown below:
Open High Low Adj Close Volume
Date
2015-01-20 107.84 108.97 106.50 108.72 49899900
2015-01-21 108.95 111.06 108.27 109.55 48575900
2015-01-22 110.26 112.47 109.72 112.40 53796400
2015-01-23 112.30 113.75 111.53 112.98 46464800
2015-01-26 113.74 114.36 112.80 113.10 55375900
Open High Low Adj Close Volume
Date
2015-01-20 193.87 194.12 187.04 191.93 4489400
2015-01-21 189.55 198.68 189.51 196.57 4144000
2015-01-22 197.00 203.24 195.20 201.62 4094100
2015-01-23 200.29 203.50 198.33 201.29 3438600
2015-01-26 201.83 208.62 201.05 206.55 3224500
My questions are: how can i include in the columns the tickers that i specified in the symbol_list? And a last thing: how can i invert the order of the dates? i want it to show the newest first (2015-01-26 in my example). Below i show you an example of what i want to obtain (the ticker name as first column and the date order inverted)
TSLA 2015-01-26 201.83 208.62 201.05 206.55 3224500
TSLA 2015-01-23 200.29 203.50 198.33 201.29 3438600
TSLA 2015-01-22 197.00 203.24 195.20 201.62 4094100
TSLA,2015-01-21 189.55 198.68 189.51 196.57 4144000
TSLA 2015-01-20 193.87 194.12 187.04 191.93 4489400
AAPL 2015-01-26 113.74 114.36 112.80 113.10 55375900
AAPL 2015-01-23 112.30 113.75 111.53 112.98 46464800
AAPL 2015-01-22 110.26 112.47 109.72 112.40 53796400
AAPL 2015-01-21 108.95 111.06 108.27 109.55 48575900
AAPL 2015-01-20 107.84 108.97 106.50 108.72 49899900
I tried a few things founded in forums, but none of that gave me any result. Thank you all for your consideration, hope that someone can give me an hand on this 2 issues.