Are there any simple HTTP APIs out there which will let me get the stock price for a symbol (such as GOOG) at a specific date and time?
Something like...
http://somewebsite.com/?
symbol=GOOG&
year=2010&
month=7&
day=30&
hour=4&
minute=00
Giving a response of $484.85
I'm hoping to have an end result of a haskell function whose type signature looks something like...
getQuote :: Symbol -> Date -> Time -> Price
I believe YQL with Yahoo finance can complete this task, they have data going back to 1996 looking on some stocks.
http://www.yqlblog.net/blog/2009/06/02/getting-stock-information-with-yql-and-open-data-tables/
http://www.gummy-stuff.org/Yahoo-data.htm
Here is an example on how to get the data in JSON-format from 2014-01-01 to 2015-01-01 for Apple stock (AAPL) via Yahoo Finance API using YQL.
The YQL query is URL-encoded:
select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%3D%22AAPL%22%20and%20startDate%3D%222014-01-01%22%20and%20endDate%3D%222015-01-01%22
So, if you decode it, you'll get:
select * from yahoo.finance.historicaldata where symbol="AAPL" and startDate="2014-01-01" and endDate="2015-01-01"
Just change the date values to ones you want and decode the whole thing back, for example using this URL-encoder: http://meyerweb.com/eric/tools/dencoder/
Then, put the whole thing together by adding the encoded query into the request URL:
http://query.yahooapis.com/v1/public/yql?q={ENTER_QUERY_HERE}&env=http://datatables.org/alltables.env&format=json
So, you end up with something like this:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%3D%22AAPL%22%20and%20startDate%3D%222014-01-01%22%20and%20endDate%3D%222015-01-01%22&env=http://datatables.org/alltables.env&format=json
Which will return you some fine JSON-formated data for the time period you've set.
Take a look at the Historical Securities Data API at http://www.mergent.com/servius - I don't think they'll have intraday data though...
You can find historic intraday data at http://www.myinvestorshub.com/historic_intraday_data.php ( for all countries)
Related
I have a list of unique customers who have made transactions over a year (Jan – Dec). They have bought products using 3 different methods (card, cash, check). My goal is to build a multi-classification model to predict the method pf payment.
To do this I am engineering some Recency and Frequency features into my training data, but am having trouble with the following frequency count because the only way I know how to do it is in Excel using the Countifs and SUMIFs functions, which are inhibitingly slow. If someone can help and/or suggest another solution, it would be very much appreciated:
So I have a data set with 3 columns (Customer ID, Purchase Date, and Payment Type) that is sorted by Purchase Date then Customer ID. How do I then get a prior frequency count of payment type by date that does not include the count of the current row transaction or any future transactions that are > the Purchase Date. So basically I want to do a running count of each payment option, based on a unique Customer ID, and a date range that is < purchase date of that training row. In my head I see it as “crawling” backwards through the transactions and counting. Simplified screenshot of data frame is below with the 3 prior count columns I am looking to generate programmatically.
Screenshot
This gives you the answer as a list of CustomerID, PurchaseDate, PaymentMethod and prior counts
SELECT CustomerID, PurchaseDate, PaymentMethod,
(
select count(CustomerID) from History T
where
T.CustomerID=History.CustomerID
and T.PaymentMethod=History.PaymentMethod
and T.PurchaseDate<History.PurchaseDate
)
AS PriorCount
FROM History;
You can save this query and use it as the source for a crosstab query to get the columnar format you want
Some notes:
I assumed "History" as the source table name - you can change the query above to use the correct source
To use this as a query, open a new query in design view. Close the window that asks what tables the query is to be built on. Open the SQL view of the query design - like design view, but it shows the SQL instead of the normal design interface. Copy the above into the SQL view.
You should now be able to switch to datasheet view and see the results
When the query is working to your satisfaction, save it with any appropriate name
Open a new query in design view
When you get the list of tables to include, switch to the list of queries and include the query you just saved
Change the query type to crosstab and update the query as needed to select rows, columns and values - look up "access crosstab queries" if you need more help.
Another tip to see what is happening here:
You can take the subquery - the parts inside the () above - and make
just that statement into it's own query, excluding the opening and closing (). Then you can look at it's design view to see what it does
Save it with an appropriate name and put it into the query above in place of the statement in () - then you can look at the design view.
Sometimes it's easier to visualize and learn from 2 queries strung together this way than to work with sub queries.
I am trying to implement AMTRAK Rail bookings using Sabre's RailShopRS.
I've been able to get a list of available journeys but now I'm struggling to figure out how I get a price for those journeys. It looks like the price should be part of the availability response but there never appears to be a price anywhere.
Is this something that should be part of the initial availability response or do I have to make a new request with details of the specific train and faretype?
Does this help?
http://files.developer.sabre.com/doc/providerdoc/rail/RailServicesDescription_v1.12.0.html#amtrak
Here are some sample request and responses:
http://files.developer.sabre.com/doc/providerdoc/rail/RS_Sample_RQ_RS_1_12_0.zip
There should be a list of 'Offers' within the response, with a reference to a JourneyId that can be used to match the fares with its corresponding journey/train option.
I am trying to find a way to get units with the data points when querying opentsdb. I have saved units of metrics in the metadata and can fetch it using the metadata query but that just makes me run an extra query to get it. I was wondering if there is a way to get units in the data that we get back from opentsdb when we make the query (/api/query).
I think you want to get the raw data you put in openTSDB back. If so, it is hard for openTSDB to do it. openTSDB always aggregate data points at the same timestamp.
If you really want that, you can try kariosDB (a fork of openTSDB ) or you can try elasticsearch (which I think can handle everything openTSDB can)
OpenTSDB is time-series database i.e. storing a value for a particular point in time.
It allows to put just one value per timestamp (smallest time interval: 1 second) and per row key (metric name, timestamp, tag=val).
Suggestion 1:
You can put/write the unit as tag value i.e. unit:
When you query (api/query endpoint), you'll get the complete data:
<metric name> <time stamp> <the value> tag1=val1 tag2=val2
For example:
db.bytes_sent 1287333217 6604859181710 unit=kB host=db1
db.bytes_received 1287333232 327812421706 unit=Mb host=db1
db.bytes_sent 1287333232 6604901075387 unit=MB host=db1
I am new to this forum so I hope I asking my question in the right place.
I have a problem inserting a datetime into a Google Spreadsheet from a form created in Appinventor2;
In app inventor2 I created a form that fills in a google spreadsheet. Basically I merged the Pizza Party example (http://appinventor.mit.edu/explore/ai2/pizzaparty.html) with this example http://puravidaapps.com/spreadsheet.php to use google spreadsheet instead of fusion table.
the user selects in how many minutes he wants his order and then sees all the orders in a table sorted by delivery time.
Problem A)
Firstly, i want to save the current datetime + the desired delay into the google spreadsheet and sort the table by this new datetime.
1) when i use the block "call clock format time" + "call clock addminutes" the spreadsheet is populated with a text, but then i can't sort the table by delivery datetime. in fact i believe the sorting is done on the number regardless of the am/pm or day of the month. so for example instead of having 4am, 6am, 2pm, 3pm i get : 2pm, 3pm, 4am, 6am.
2) I then tried to remove the block "call clock format time" and in the google form i kept the field format = text
but the google spreadsheet is populated with the following:
java.util.GregorianCalendar[time=1395531335908,areFieldsSet=true,lenient=true,zone=Europe/Dublin,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2014,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=35,SECOND=35,MILLISECOND=908,ZONE_OFFSET=0,DST_OFFSET=0]
3) I then tried to remove the block "call clock format time" and in the google form I changed the field format = time
but then the google spreadsheet isn't populated with anything.
4)I tried using the segment block, but after a while I realised the block "format time" actually returns this format: "hh:mm:ss AM/PM"
so selecting the 5 characters is not good enough because it does not take into account of the am/pm element as well as the day of the month.
5) I found a temp solution by defining the desired delivery time as a new global variable, and extracting a string in the format hh:mm by joining the blocks ".hour instant" and ".minute instant".
However this is not a final solution because what i extracted is of course a string of text and when sorting, 01:10 will be always considered smaller than 23:50 for example, regardless of the date.
So is there a way of actually saving in the google spreadsheet not a string of text, but actually the date and time?
Problem B)
Secondly, I would like to filter/show only the rows of the google spreadsheet have a delivery time expired by no more than 1 hour (as well as orders with delivery time in the future e.g. in 2 hours from now()).
I tried using some Google Visualization API Query Language commands, altering the url of the google spreadsheet (like WHERE "now() - Delivery Time < 60 mins)" (cannot remember the exact code I wrote) but unsucessfully.
Would anyone know how to filter my results?
thanks in advance
alterettore
So there's a few things to note.
If you're using Taifun's example as you mention, you'll notice that when you submit data to Google Spreadsheets using a form, the first column is always a timestamp, even if you're not submitting a date or time. Trying to send the current date/time is redundant - go ahead and make use of what Google provided.
Google Spreadsheets (and Excel) store Date/Time as a number. If you want to store a date in GS, the best way to do so is not formatted text, but by sending a number. Use AppInventor to calculate the number you need. For example, today (April 27) in GS is 41756. Noon today would be 41756.5
To generate this number, start with AI's Millisecond function. NOTE: Both GS and AI use milliseconds, but they have different 0 points, so you have to manipulate the result a bit. The formula I've used in AI in the past is this:
GS Date/Time = (Clock1.GetMillis(Clock1.Now) / 86400000) + 25569
Hope this helps!
I am using the gapi class to access analytics data. It works great and i have daily visits to my site. What I would like is to be able to get hourly visits over a date range, say from 11th Jan to 12th Jan (2 days) which would return me 48 data points, one for each hour in teh range. I'm sure this is simple but I cannot find how to do it anywhere. Presumably there is some setting in the metrics parameter of the requestReportData() method that allows this???
Any help gratefully received, thanks...
David
To do this, you'd need to set two dimensions
Dimensions: ga:hour, ga:date
Metric: ga:visits
You can test out this query on the Google Analytics API Query Explorer.
Untested, this should look like this with gapi.class.php:
$ga->requestReportData($profile_id,array('hour','date'),array('visits'), null, null, '2011-01-11', '2011-01-12', 1, 48);
You'll get data back that looks like this: