Wednesday 30 May 2012

EOD and Historical data downloader for NSE & BSE

Getbhavcopy is a freeware data source provider for NSE & BSE . No Intermediate server is presented like yahoo & google etc. It downloads directly from NSE and BSE servers.


Getbhavcopy downloads following data from NSE and BSE servers:




NSE data downloadedBSE data downloaded
NSE Equity BhavcopyBSE Equity Bhavcopy
NSE Equity Open Interest
NSE Indices data downloadedBSE Indices data downloaded
NSENIFTYSENSEX
NIFTYJUNIORMIDCAP
BANKNIFTYSMLCAP
NSE100BSE-100
NSEMIDCAPBSE-200
NSEITBSE-500
NSE500AUTO
NSEDEFTYBANKEX
CONSDURBL
CAPGOODS
FMGC
HLTHCARE
IT
METAL
OILGAS
POWER
PSU
REALTY
TECK
DOL30
DOL100
DOL200



Download latest stable versions from following mirrors:












Tuesday 29 May 2012

NSE Free Data Downloader

Today I found one free data down loader for different free sources.It supports Intraday stock quotes and EOD stock quotes.

It supports following sources:
  • Google Intraday Stock Quotes Backfill
  • Yahoo Intraday Stock Quotes Backfill
  • MCX EOD Futures Data
  • NSE EOD Stock Data (Bhavcopy and Indices)
  • NSE Futures and Options Data


Download the Software from here
Find the online tutorial from here


Data Downloader is built on .Net framework. If you don't have .Net framework installed download and install it from here 

Free 1min Intraday Data for Amibroker using AmiQuote

Here I will explain how to take realtime intraday data from yahoo without any 3rd party program and plugins.
First we need to take the backup of Amibroker database this is very important.First we need to make the symbol list(which are we required) in the .tls file.I explained in another post how to make the .tls file.Recent amiquote has an option to allow yahoo cookies after u are logged in yahoo finance.so that was an hidden additional feature which many didn’t took it seriously but it is the same thing what other softwares made here in INDIA which many are using it for realtime data from yahoo.Minimum tick is 1min in yahoo.Bcz it doesn't contain the timestamp less than 1 min.
step 1 :

we need to make new database in amibroker as the name amitry.

Set the Base Time interval as  1 Tick.

After this click the Intraday settings.

a)  In this window select 24hours trading
b) Start Time : 9:30
c) End Time : 15:30
d) Select the Exchange Time in the daily time compression uses.
e) At last  set the time shifting as 10.(hours)But usually we should set 9:30 but they didn't give the option for minutes.Anyway we have to bear with this BUG after all we are going to get free data in RT mode.We need to save the above settings,Close the amibroker and openit again. We can the see the setting not saved properly.we need to Change the Timeshift once again from 0 to 10 and again save it.







Step 3:
          Chage the aqd.format file content to below content
aqd.format file presented in the format folder which is under installed amibroker folder.

Before proceed plz take the backup of this file.

New Content:

# AmiQuote daily download format (.AQD extension)
# Revision 1.1 (previous version had missing Date_MDY field)
# Revision 1.2 (added $STRICT 1)
# Revised for RT data from yahoo in Rt mode 
$FORMAT Ticker,FullName,Close,Date_MDY,Time,Skip,Skip,Skip ,Skip,Volume
$SKIPLINES 0
$SEPARATOR ,
$DEBUG 1
$AUTOADD 1
$CONT 1
$GROUP 254
$BREAKONERR 0
$STRICT 1

Final Step:

Before the Indian market start,login to the yahoo finanace and start the amibroker and the database.

In the Amiquote select the yahoo current and start it(using green color icon)
After this in the autotimportbox set 1min interval for auto update.


ONLY THING IS YAHOO DON’T GIVE BARWISE VOLS 
SO U HAVE TO MAKE AN AFL FOR VOLUME TO DEDUCT THE PREVIOUS BARS VOLUME FROM CURRENT AR VOLUME TO GET THE TRUE BAR WISE VOLUME
My SUGGESTION IS TO USE ANY TIMEFRAME GREATER THAN 3 MINUTE BARS TO GET A REAL TRUE PICTURE

Monday 28 May 2012

What is Adjustment close in yahoo financial Data

What is the adjusted close?
                  
                  The historical prices feature includes notations for all splits and dividend distributions during the date range selected in the yahoo finance(URL : http://finance.yahoo.com). Open, high, low, and close values are not adjusted for splits or dividends. An additional column, Adjusted Close, is provided in the same page forthe close price adjusted for all splits and dividends.




Example: Adjusted Close Calculations

    2/13/03 Close = 46.99
    2/14/03 Close = 48.30
    2/18/03 Split = 2:1
    2/18/03 Close = 24.96
    2/19/03 Cash Dividend = 0.08 (ex-date)
    2/19/03 Close = 24.53

    Split Multiplier = 0.5
    Dividend Multiplier = 1 - (0.08/24.96) = 0.9968

    2/13/03 Adj. Close = 0.5 * 0.9968 * 46.99 = 23.42
    2/14/03 Adj. Close = 0.5 * 0.9968 * 48.30 = 24.07
    2/18/03 Adj. Close = 0.9968 * 24.96 = 24.88
    2/19/03 Adj. Close = 24.53



                     For Technical analysis we are taking the Adjusted close value.

Yahoo Real time Data Feed

Every one want to know how to fetch the yahoo realtime data feed from yahoo finance.
Here we will see how to get the url for the same.

Sample Url : http://ichart.finance.yahoo.com/table.csv?s=ACC&a=07&b=16&c=2004&d=04&e=28&f=2012&g=w&ignore=.csv

s => Symbol
a => Starting month (start from zero for eg: For August we need to give 07)
b => Starting Date
c => starting year
d => Ending month(Starting from zero)
e => Ending date
f => Ending year
g => Here we need to mention daily,weekly,monthly,yearly
        daily = d,weekly = w,monthly = m, yearly = y

Go to http://finance.yahoo.com link and type any one of the stock quote.In the left side panel you can find the historical prices.just click this link.

At the bottom of the Historical price you can find the link for Download data.





How To fetch Yahoo Finanacial data using YQL

Compare to Google,  yahoo provides more basic analysis data with 15 min delay input.One question that the YQL(Yahoo query language)and Pipes teams get asked is “how can I get stock quotes? There isn’t an API for it on developer.yahoo.com”. Interestingly, while there isn’t a more traditional web service API, Yahoo finance does provide a very nice way to get a lot of well structured information on a given company. Following is the sample YQL uel for fetching the Stock data fro "ACC"


url : http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20("ACC")&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys



<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2012-05-28T11:02:11Z" yahoo:lang="en-US">
<results>
<quote symbol="ACC">
<Ask/>
<AverageDailyVolume>715119</AverageDailyVolume>
<Bid/>
<AskRealtime>44.85</AskRealtime>
<BidRealtime>43.03</BidRealtime>
<BookValue>19.326</BookValue>
<Change_PercentChange>-0.09 - -0.20%</Change_PercentChange>
<Change>-0.09</Change>
<Commission/>
<ChangeRealtime>-0.09</ChangeRealtime>
<AfterHoursChangeRealtime>N/A - N/A</AfterHoursChangeRealtime>
<DividendShare>1.352</DividendShare>
<LastTradeDate>5/25/2012</LastTradeDate>
<TradeDate/>
<EarningsShare>0.814</EarningsShare>
<ErrorIndicationreturnedforsymbolchangedinvalid/>
<EPSEstimateCurrentYear>2.02</EPSEstimateCurrentYear>
<EPSEstimateNextYear>2.26</EPSEstimateNextYear>
<EPSEstimateNextQuarter>0.41</EPSEstimateNextQuarter>
<DaysLow>43.7001</DaysLow>
<DaysHigh>44.41</DaysHigh>
<YearLow>32.57</YearLow>
<YearHigh>45.75</YearHigh>
<HoldingsGainPercent>- - -</HoldingsGainPercent>
<AnnualizedGain/>
<HoldingsGain/>
<HoldingsGainPercentRealtime>N/A - N/A</HoldingsGainPercentRealtime>
<HoldingsGainRealtime/>
<MoreInfo>cnprmiIed</MoreInfo>
<OrderBookRealtime/>
<MarketCapitalization>3.285B</MarketCapitalization>
<MarketCapRealtime/>
<EBITDA>191.6M</EBITDA>
<ChangeFromYearLow>+11.40</ChangeFromYearLow>
<PercentChangeFromYearLow>+35.00%</PercentChangeFromYearLow>
<LastTradeRealtimeWithTime>N/A - <b>43.97</b></LastTradeRealtimeWithTime>
<ChangePercentRealtime>N/A - -0.20%</ChangePercentRealtime>
<ChangeFromYearHigh>-1.78</ChangeFromYearHigh>
<PercebtChangeFromYearHigh>-3.89%</PercebtChangeFromYearHigh>
<LastTradeWithTime>May 25 - <b>43.97</b></LastTradeWithTime>
<LastTradePriceOnly>43.97</LastTradePriceOnly>
<HighLimit/>
<LowLimit/>
<DaysRange>43.7001 - 44.41</DaysRange>
<DaysRangeRealtime>N/A - N/A</DaysRangeRealtime>
<FiftydayMovingAverage>44.132</FiftydayMovingAverage>
<TwoHundreddayMovingAverage>41.422</TwoHundreddayMovingAverage>
<ChangeFromTwoHundreddayMovingAverage>+2.548</ChangeFromTwoHundreddayMovingAverage>
<PercentChangeFromTwoHundreddayMovingAverage>+6.15%</PercentChangeFromTwoHundreddayMovingAverage>
<ChangeFromFiftydayMovingAverage>-0.162</ChangeFromFiftydayMovingAverage>
<PercentChangeFromFiftydayMovingAverage>-0.37%</PercentChangeFromFiftydayMovingAverage>
<Name>American Campus C</Name>
<Notes/>
<Open>44.20</Open>
<PreviousClose>44.06</PreviousClose>
<PricePaid/>
<ChangeinPercent>-0.20%</ChangeinPercent>
<PriceSales>8.17</PriceSales>
<PriceBook>2.28</PriceBook>
<ExDividendDate>Feb 9</ExDividendDate>
<PERatio>54.13</PERatio>
<DividendPayDate>May 29</DividendPayDate>
<PERatioRealtime/>
<PEGRatio>2.25</PEGRatio>
<PriceEPSEstimateCurrentYear>21.81</PriceEPSEstimateCurrentYear>
<PriceEPSEstimateNextYear>19.50</PriceEPSEstimateNextYear>
<Symbol>ACC</Symbol>
<SharesOwned/>
<ShortRatio>5.30</ShortRatio>
<LastTradeTime>4:00pm</LastTradeTime>
<TickerTrend>&nbsp;=-+==+&nbsp;</TickerTrend>
<OneyrTargetPrice>45.45</OneyrTargetPrice>
<Volume>313271</Volume>
<HoldingsValue/>
<HoldingsValueRealtime/>
<YearRange>32.57 - 45.75</YearRange>
<DaysValueChange>- - -0.20%</DaysValueChange>
<DaysValueChangeRealtime>N/A - N/A</DaysValueChangeRealtime>
<StockExchange>NYSE</StockExchange>
<DividendYield>3.07</DividendYield>
<PercentChange>-0.20%</PercentChange>
</quote>
</results>
</query>
<!-- total: 985 -->
<!-- engine1.yql.ird.yahoo.com -->



C# Code for format the URL:

 public static void Fetch()
        {



// quotes list contains the symbol list...
            string symbolList = String.Join("%2C", quotes.Select(w => "%22" + w.Symbol + "%22").ToArray());
            string url = string.Format(BASE_URL,symbolList);
            
            XDocument doc = XDocument.Load(url);
            Parse(quotes,doc);
        }


        private static void Parse(ObservableCollection<YahooQuote> quotes, XDocument doc)
        {
            XElement results = doc.Root.Element("results");

            foreach (YahooQuote quote in quotes)
            {
                XElement q = results.Elements("quote").First(w => w.Attribute("symbol").Value == quote.Symbol);

                quote.Ask = GetDecimal(q.Element("Ask").Value);
                quote.Bid = GetDecimal(q.Element("Bid").Value);
                quote.AverageDailyVolume = GetDecimal(q.Element("AverageDailyVolume").Value);
                quote.BookValue = GetDecimal(q.Element("BookValue").Value);
                quote.Change = GetDecimal(q.Element("Change").Value);
                quote.DividendShare = GetDecimal(q.Element("DividendShare").Value);
                quote.LastTradeDate = GetDateTime(q.Element("LastTradeDate") + " " + q.Element("LastTradeTime").Value);
                quote.EarningsShare = GetDecimal(q.Element("EarningsShare").Value);
                quote.EpsEstimateCurrentYear = GetDecimal(q.Element("EPSEstimateCurrentYear").Value);
                quote.EpsEstimateNextYear = GetDecimal(q.Element("EPSEstimateNextYear").Value);
                quote.EpsEstimateNextQuarter = GetDecimal(q.Element("EPSEstimateNextQuarter").Value);
                quote.DailyLow = GetDecimal(q.Element("DaysLow").Value);
                quote.DailyHigh = GetDecimal(q.Element("DaysHigh").Value);
                quote.YearlyLow = GetDecimal(q.Element("YearLow").Value);
                quote.YearlyHigh = GetDecimal(q.Element("YearHigh").Value);
                quote.MarketCapitalization = GetDecimal(q.Element("MarketCapitalization").Value);
                quote.Ebitda = GetDecimal(q.Element("EBITDA").Value);
                quote.ChangeFromYearLow = GetDecimal(q.Element("ChangeFromYearLow").Value);
                quote.PercentChangeFromYearLow = GetDecimal(q.Element("PercentChangeFromYearLow").Value);
                quote.ChangeFromYearHigh = GetDecimal(q.Element("ChangeFromYearHigh").Value);
                quote.LastTradePrice = GetDecimal(q.Element("LastTradePriceOnly").Value);
                quote.PercentChangeFromYearHigh = GetDecimal(q.Element("PercebtChangeFromYearHigh").Value); //missspelling in yahoo for field name
                quote.FiftyDayMovingAverage = GetDecimal(q.Element("FiftydayMovingAverage").Value);
                quote.TwoHunderedDayMovingAverage = GetDecimal(q.Element("TwoHundreddayMovingAverage").Value);
                quote.ChangeFromTwoHundredDayMovingAverage = GetDecimal(q.Element("ChangeFromTwoHundreddayMovingAverage").Value);
                quote.PercentChangeFromTwoHundredDayMovingAverage = GetDecimal(q.Element("PercentChangeFromTwoHundreddayMovingAverage").Value);
                quote.PercentChangeFromFiftyDayMovingAverage = GetDecimal(q.Element("PercentChangeFromFiftydayMovingAverage").Value);
                quote.Name = q.Element("Name").Value;
                quote.Open = GetDecimal(q.Element("Open").Value);
                quote.PreviousClose = GetDecimal(q.Element("PreviousClose").Value);
                quote.ChangeInPercent = GetDecimal(q.Element("ChangeinPercent").Value);
                quote.PriceSales = GetDecimal(q.Element("PriceSales").Value);
                quote.PriceBook = GetDecimal(q.Element("PriceBook").Value);
                quote.ExDividendDate = GetDateTime(q.Element("ExDividendDate").Value);
                quote.PeRatio = GetDecimal(q.Element("PERatio").Value);
                quote.DividendPayDate = GetDateTime(q.Element("DividendPayDate").Value);
                quote.PegRatio = GetDecimal(q.Element("PEGRatio").Value);
                quote.PriceEpsEstimateCurrentYear = GetDecimal(q.Element("PriceEPSEstimateCurrentYear").Value);
                quote.PriceEpsEstimateNextYear = GetDecimal(q.Element("PriceEPSEstimateNextYear").Value);
                quote.ShortRatio = GetDecimal(q.Element("ShortRatio").Value);
                quote.OneYearPriceTarget = GetDecimal(q.Element("OneyrTargetPrice").Value);
                quote.Volume = GetDecimal(q.Element("Volume").Value);
                quote.StockExchange = q.Element("StockExchange").Value;

                quote.LastUpdate = DateTime.Now;
            }
        }

        private static decimal? GetDecimal(string input)
        {
            if (input == null) return null;

            input = input.Replace("%", "");

            decimal value;

            if (Decimal.TryParse(input, out value)) return value;
            return null;
        }

        private static DateTime? GetDateTime(string input)
        {
            if (input == null) return null;

            DateTime value;

            if (DateTime.TryParse(input, out value)) return value;
            return null;
        }



Thursday 24 May 2012

How to download Yahoo finance data for Amibroker



We can use the AmiQuote in order to obtain quotes from Yahoo finance data to Amibroker.Her I am going to explain how to use the AmiQuote application.
Yahoo provides data in "Historical" and "Current" modes of AmiQuote. Quote.com provides data in "Intraday" mode of AmiQuote.
First we need to prepare the ticker list for AmiQuote.This is nothing but .tls file where it is present in the AmiQuote installed folder.
Path  -->     AmiBroker installed folder/AmiQuote
TLS file or write completely new one all you need is plain text editor such as Notepad or any other plain ASCII editor (not MS Word!). All you have to do is to write tickers you want to import line by line (single ticker in single line) and save the file. Please make sure that you are saving the file with .TLS extension. Otherwise AmiQuote will not load this file.
Please note that also Yahoo and Quote.com use different symbols for indices. The main difference is that Yahoo uses ^ (dash) prefix and Quote.com uses $ (dollar) prefix.
For list of indices provided by Yahoo please click here.
Downloading data
From the file dialog please choose one .TLS file (for example DIJA.TLS) and click Openbutton. The you will see the main screen of AmiQuote filled with the list of tickers loaded, as show in picture below.

Choose appropriate Data Source
Yahoo Historical - allows you to download end-of-day histories upto current day (current day data appear few hours after session end)
Yahoo Current - allows you to download current day quotes (15-min delayed) during the trading session
After choosing correct options please click on green arrow (or use File -> Start Download menu). The download process will begin. AmiQuote will display progress messages and status information including number of completed downloads and number of files left. At anytime you can stop download process with "Stop" button (red box). After finishing the download AmiQuote will automatically update the quotes in AmiBroker (if only AmiBroker is running in parallel and "automatic import" box in AmiQuote is checked.

Wednesday 23 May 2012

Technical Analysis Tool : FCharts SE

FCharts SE is a free stock charting software program which will import price data from a wide range of sources, displaying as chart. It has a number of built-in indicators are available, and we can write our own  inbuilt formula by FL and display them as standalone charts or overlays. We can also draw trend lines.


Free Version is available with out saving option.

You can download the software here .

FCharts SE free charting software


                                 
                                 

Tuesday 22 May 2012

Real Time Data From Google Finanace


We can fetch real time intraday data from google(1min) finanace.
Following is the procedure for geeting the data.
Following is the Url for getting the realtime backfill data which most of the trading softwares are using as a source for realtime datafeed
q= stock symbol on Google finance
x= exchange symbol
i= interval (in secs)
p= no of period(here 5d denotes 5 days of data)
      year  -- > 5Y
      month --> 5M
     Minute --> 5m

f= parameters (day, close, open, high,low& Volume)
df= difference (cpct is may be in % change )
auto =1,
ts = time start… if you cut the last 4 digits…the rest gives the start day in seconds
you can choose your own set of value depending upon your need.
The following link gives the 1 min Realtime data for Nifty
Using the above procdure we can make any formats(1min,5min, 15min,hourly) of real time data and can be use as a backfill
to feed charting softwares like Amibroker, Metastock, Ninja Trader etc
Following is the C# code for make the above URL.
private const string BASE_URL = "http://www.google.com/finance/getprices";
public enum Interval { OneMin = 60, FiveMin = 300, OneDay = 3600 }
/// <summary>
        /// Returns a URI to invoke the getPrices method.
        /// </summary>
        public string getGetPricesUri(string StockExchange,string Symbol,Interval interval, string period)
        {
            if (String.IsNullOrEmpty(period))
                throw new ArgumentException("No 'period'.");
            string formatURI = BASE_URL + "?q={0}{1}&i={2}&p={3}&f=d,c,h,l,o,v";
            string exchangeString = string.Empty;
            if (!String.IsNullOrEmpty(StockExchange))
            {
                exchangeString = "&x=" + StockExchange;
            }
            int _interval = 3600;
            switch (interval)
            {
                case Interval.OneDay:
                    _interval = 3600;
                    break;
                case Interval.OneMin:
                    _interval = 60;
                    break;
                case Interval.FiveMin:
                    _interval = 300;
                    break;
            }
            return String.Format(formatURI, Symbol, exchangeString, _interval, period);
        }
        /// <summary>
        /// Method invoked by getGetPricesUriForRecentData().
        /// </summary>
        public string getPeriod(DateTime startDate, DateTime endDate)
        {
            if (endDate.Date < startDate.Date)
            {
                throw new ArgumentException("The ending date can't be lower than the starting date.");
            }
            if (endDate.Year > startDate.Year)
            { //More than a year.
                return (endDate.Year - startDate.Year + 1) + "Y";
            }
            TimeSpan span = endDate - startDate;
            if (span.Days > 50)
            { //Return months.
                return ((span.Days % 25) + 1) + "M";
            }
            else if(span.TotalHours > 20)
            { //Return days.
                return (span.Days + 1) + "d"; //+1 because, depending on the hour, no data might be retrieved (1d is for today).
            }
            else
            { //Return days.
                return (span.Minutes + 1) + "m"; //+1 because, depending on the hour, no data might be retrieved (1d is for today).
            }
        }
// call the function
getGetPricesUri("NSE","NSEI", Interval.OneMin,getPeriod(DateTime.Now.AddDays(-15), DateTime.Now));