End-of-day prices

Category : Uncategorized

End-of-day prices

Please make sure you have the most updated mfd_dm and mfd_ta packages for Stata installed for this post.

*
net from "http://www.researchforprofit.com/stata/mfd_dm"
net from "http://www.researchforprofit.com/stata/mfd_ta"
* click on the blue mfd_dm package and then "click here to install" 
*

Stata code for downloading all available historic prices for Dow Jones Composite Index components:

Each company is downloaded and merged. Thus, this is a “wide” dataset: 

*
* Download historic prices for all NYSE listed stocks
clear all
cd "/Users/mfd/Desktop"

* Get the components of NYA Index
mfd_dm_components, symbol(^NYA)
drop if Symbol==""
sort Symbol
save NYA_components.dta, replace

* Get the prices of all NYA Index components as of 130906
use NYA_components.dta, clear
levelsof Symbol, local(tickers)
mfd_dm_prices `tickers', freq(d) chg(ln) field(o c h l v)
gen day=_n
tsset day
save NYA_historic_prices.dta, replace
*

This code updates the historic price data for the given day: 

*
clear all
cd "/Users/mfd/Desktop"

local tarih="130802"
local tarih_start=date("`tarih'","YMD", 2050)-150
local end: display %td date("`tarih'","YMD", 2050)
local start: display %td `tarih_start'

use components.dta, clear
levelsof Symbol, local(tickers)
mfd_dm_prices `tickers', freq(d) start("`end'") end("`end'")
append using historic_prices.dta
save historic_prices.dta, replace
*

Each company is downloaded and appended. Thus, this is a “long” dataset: 

*
* Download historic prices for all NYSE listed stocks
clear all
cd "/Users/mfd/Desktop"

mfd_dm_components, symbol(^NYA)
drop if Symbol==""
levelsof Symbol, local(tickers)

local counter=0
foreach aa of local tickers {
    capture: mfd_dm_prices `aa', freq(d)
    if (_rc==0) & (_N>10) {
        di "`aa'"
		rename adj* adjclose
		gen symbol="`aa'"
		if (`counter'==0) {
			qui: save NYA_historic_prices.dta, replace
			local counter=1
		}
		else {
			qui: append using NYA_historic_prices.dta
			qui: save NYA_historic_prices.dta, replace			
		}
	}

}
*