Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real time stock price R [closed]

I am trying to do some market analysis using R. Is there any way to get real time stock quotes at minutely intervals using a package? I am familiar with quantmod and have used the getSymbols() function, however, all data I am able to mine is 15 minutes old. Thank you.

like image 978
user3731327 Avatar asked Nov 19 '14 20:11

user3731327


People also ask

What is R value in stock market?

The risk/reward ratio helps investors manage their risk of losing money on trades. Even if a trader has some profitable trades, they will lose money over time if their win rate is below 50%. The risk/reward ratio measures the difference between a trade entry point to a stop-loss and a sell or take-profit order.

Can you get real-time stock quotes?

You can access Real-Time Quotes from anywhere on the Fidelity.com website. Quotes are available for stocks, mutual funds, Fidelity Select Portfolios ®, indexes, options, bonds, and annuities. Just enter the stock's symbol in the search field or you can look up stocks by company name.

Why does stock price change after close?

The development of after-hours trading (AHT) has had a major effect on the price of the stock between the closing and opening bells because it means that transactions are happening and shifting the prices of stocks even after-hours.

Can R be used in stock trading?

Whether you are doing high-frequency trading, day trading, swing trading, or even value investing, you can use R to build a trading robot that watches the market closely and trades the stocks or other financial instruments on your behalf.


2 Answers

My qmao package has getQuote "methods" for both BATS and google which are both near real time

Sys.time()
#[1] "2014-11-19 14:27:48.727988 CST"
getQuote("SPY", src="google")
#              TradeTime   Last Change PctChg Exchange GoogleID
#SPY 2014-11-19 15:27:00 205.17  -0.38  -0.18 NYSEARCA   700145
getQuote("SPY", src="bats", what="bbo")
#  TradeTime BidSize BidPrice AskPrice AskSize   Last LastSize row.names
#1  15:27:24   15000   205.16   205.17     300 205.17      300       SPY

getQuote.bats has a few options for how you want the data to print:

getQuote("SPY", src="bats", what="ladder")
#  SPDR S&P 500 ETF TR TR UNIT 
#  Time:    15:27:44 
#  Volume:  8779553 
#  Last: 300 @ 205.17
#
#+-------+--------+-------+
#|       | 205.21 | 16700 |
#+-------+--------+-------+
#|       | 205.2  | 21900 |
#+-------+--------+-------+
#|       | 205.19 | 17300 |
#+-------+--------+-------+
#|       | 205.18 | 5572  |
#+-------+--------+-------+
#|       | 205.17 |  300  |
#+-------+--------+-------+
#| 15000 | 205.16 |       |
#+-------+--------+-------+
#| 12100 | 205.15 |       |
#+-------+--------+-------+
#| 11300 | 205.14 |       |
#+-------+--------+-------+
#| 23900 | 205.13 |       |
#+-------+--------+-------+
#| 10600 | 205.12 |       |
#+-------+--------+-------+

getQuote("SPY", src="bats", what="depth")
#
#
# BidQty   BidPrice   AskPrice   AskQty 
#-------- ---------- ---------- --------
# 15000     205.16     205.17     300   
# 12100     205.15     205.18     5572  
# 11300     205.14     205.19    17300  
# 23900     205.13     205.2     21900  
# 10600     205.12     205.21    16700  

There are also plot methods

plot(getQuote("SPY", src="bats"))

enter image description here

plot(getQuote("SPY", src="bats", what="ladder"))

enter image description here

plot(getQuote("SPY", src="bats", what="depth"))

enter image description here


And, if you're still reading, there is a shiny app included in the package so you can make those "plots" update in real time. Just run this:

shinyBATS()
like image 85
GSee Avatar answered Sep 22 '22 03:09

GSee


IB would probably be best for real-time stock data. You won't need to pay for it (*), but last time I looked you will need to open an account with a minimum amount of real money.

There is an R package: http://cran.r-project.org/web/packages/IBrokers/index.html

There is a vignette on getting real-time data, but it was last updated in 2009, so I would go with the general vignette: http://cran.r-project.org/web/packages/IBrokers/vignettes/IBrokers.pdf which was last update sep 2014.

(*: Not strictly true: for some exchanges you will need to pay an extra exchange fee.)

like image 35
Darren Cook Avatar answered Sep 23 '22 03:09

Darren Cook