Showing posts with label Stock Data and Excel Modeling. Show all posts
Showing posts with label Stock Data and Excel Modeling. Show all posts

Wednesday, February 1, 2017

Query to Import Financial Statement in Excel



 Web Query to Import Financial Statement and Stock Data with Stock Quote { All Financial Statements in one sheet from -}

 

Method-1

http://www.advfn.com/stock-market/NYSE/IBM/financials?btn=annual_reports&mode=company_data


Sub Macro1()
'
' Macro1 Macro
'

'
SE = Range("SE").Value
SS = Range("SS").Value
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.advfn.com/stock-market/" & SE & "/" & SS & "/financials?btn=annual_reports&mode=company_data" _
        , Destination:=Range("$A$2"))
     
        .Name = "financials?btn=annual_reports&mode=company_data"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = True
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 60
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
  
End Sub

Method-2

Importing Financial Statements in Excel Web Query

An Excel Web query allows you to import data from a Web site into an Excel worksheet. We're going to work through a basic example by taking TCS to import financial statements (Balance Sheet, Income Statement and Cash Flow) in excel  from economic times.
A query has two parts- Static and Dynamic.
In this tutorial we will import the financial statements by copy and pasting dynamic part of the query every time we have to import statements of company.
Required URL-
1-     Go to economic times.
2-     Add the stock symbol or company name in the right end of the page. In our case Tata Consultancy Services Ltd.
3-     Than go to financial tab. Profit & Loss or income statement will be displayed in the bottom of the page under heading-
Profit & Loss - Tata Consultancy Services Ltd.

Importing Statements-
First Step – Is same for all the three statements-
In this tutorial I will explain how to import income statement rest will be imported in the same manner by adding the specific URL.
 ‘Go to Data’– ‘From Web’ – ‘Paste the URL (a) ‘
Click Go 
(Select the required data as shown, select cell as in this case $A$1 is selected-

Go to properties- select refresh every (SELECT TIME) and refresh data when opening the file.
Click ok
Then click ok-
Selected data will get import-

This process is very time consuming every time you need to import the statement.

Retrieving statement by query-

Here are the steps to retrieve data every time you want to import statement of other company with the help of query.
In the query –
Bold part in red is static and remaining blue is dynamic.
By adding the dynamic part every time we refresh the given statement we can import the financial statement of any company

Select the data imported’ – ‘Right Click’ – ‘Edit Query’ – ‘Check the data to be imported is selected’ – ‘Click on save query “(Let it to be saved in the default location as in Local Disk C in the example)”’- ‘Name the query as in example named as tcs companyid-8345  – ‘Click Save’.

Close the window.
Got to the location where query had been saved
Right click and select Edit with Notepad -

Do the changes as shown below-
Save the query.
How this works-
Go to sheet- Paste the dynamic part of the URL of the company whose financial statements is to be imported in any cell of the sheet.
Now we will import Income Statement or Profit & Loss statement of Infosys.
The URL of profit and loss statement of Infosys is-
We have to copy and paste the highlighted part i.e. the dynamic part of the URL only.


Importing Statement-
o   Select the whole imported data, delete it.
o   Select existing connections-
o   go to the query, in e.g. it’s by the name tcs companyid-8345 
o   open-
o   select the cell where you want to import the financial statement-
o   Then select the cell where you pasted the dynamic part of the URL of company Income statement to be imported.
In our example J3- static part of the company in this case Infosys-
o   Click ok- Income statement of Infosys will be imported.


Screen Shots of the steps-
Existing connections




This window will prompt –
Select the cell where you want to import data. As in the example $A$1 is selected-

After clicking ok- This window will prompt-
Select the cell where you entered the static part of the querry-
Click  Ok.
The income statement will get imported


For Balance Sheet after saving query change-
For Cash flow after saving query change-


Please let me know if you have any questions.
Thanks.






Importing Stock Data with Stock Symbol Web Query



Importing Stock Data with Stock Symbol Web Query


·    Method-1-
First record macro and import Income statement.
-       Than type symbol in cell A1 as shown.
-       Change A1 to Tcker as shown below.
-       Stop recording macro.
-       Go to VBA and update the code by-
Sub Macro2()
'
' Macro2 Macro
'

' Define Ticker
Ticker = Range("Ticker").Value

   
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://finance.yahoo.com/q/is?s=" & Ticker & "+Income+Statement&annual", _
        Destination:=Range("$A$9"))
        .Name = "is?s=" & Ticker & "+Income+Statement&annual"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = True
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        'Change savedata to false
        .SaveData = False
        .AdjustColumnWidth = True
        .RefreshPeriod = 60
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "9"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub



·        Method-2
An Excel Web query allows you to import data from a Web site into an Excel worksheet. We're going to work through a basic example by taking TCS to get a feel for how Web queries operate. 
Required URL-
·        Stock Data.
Yahoo Finance- Enter Stock SymbolGet the URLCopy the URL (a)
e.g.- https://in.finance.yahoo.com/q?s=TCS.NS&ql=1
1-     Getting Stock Data-
‘Go to Data’– ‘From Web’ – ‘Paste the URL (a) ‘https://in.finance.yahoo.com/q?s=TCS.NS&ql=1 – Click Go 
(Select the required data as shown, select cell as in this case $A$1 is selected-

Go to properties- select refresh every (SELECT TIME) and refresh data when opening the file.
Click ok
Then click ok-
Selected data will get import-


Retrieving Data by stock symbol-

This process is very time consuming every time you need to retrieve stock data.
Here are the steps to retrieve data every time you change the symbol.
‘Select the data imported’ – ‘Right Click’ – ‘Edit Query’ – ‘Check the data to be imported is selected’ – ‘Click on save query “(Let it to be saved in the default location as in Local Disk C in the example)”’- ‘Name the query as in example named as Stock Data’ – ‘Click Save’.
Close the window.
Got to the location where query had been saved
Right click and select Edit with Notepad -

Do the changes as shown below-
Save the query.
How this works-
Go to sheet- Type the ticket symbol of any company in any cell of the sheet accept where data is or where you want to import data.
e.g. TATAMOTORS.BO
Select existing connections- go to the query – click open.

This window will prompt –
Select the cell where you want to import data. As in the example $G$1 is selected-

After clicking ok- This window will prompt-
Select the cell where you entered the stock ticket-
Click on Ok.
The data will get imported
If you want to import it to the same destination first delete the data. Than go to Existing Connections – select query – open – destination ($A$1) – Symbol - Ok





https://drive.google.com/file/d/0Bx3mfFH5R-y3U3VTbEJxRFdJZWM/view?usp=sharing

R3 chase - Pursuit

Change Point Detection Time Series

  Change Point Detection Methods Kernel Change Point Detection: Kernel change point detection method detects changes in the distribution of ...