YQL yahoo.finance.historicaldata EUR/USD - yahoo

Is it possible to get a EUR/USD currency pair from the YQL yahoo.finance.historicaldata? I managed to get the "EUR=x" (results in USD/EUR) but how can i get a EUR/USD price to avoid calculating every price/inverting it?
This works fine: select * from yahoo.finance.historicaldata where symbol = "EUR=x" and startDate = "2016-08-01" and endDate = "2016-08-04"
But not: select * from yahoo.finance.historicaldata where symbol = "EURUSD=x" and startDate = "2016-08-01" and endDate = "2016-08-04"
I found these two great list with all yahoo stock tickers:
http://investexcel.net/all-yahoo-finance-stock-tickers/
But it looks like the webservices do not offer the inverted price (EUR/USD) only the EUR=X (USD/EUR) ? Is this the case?
http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote
Many Thanks
Micke

Related

why does my pig query return the wrong values

I am trying to work with the following dataset in pig
https://www.kaggle.com/zynicide/wine-reviews/version/4?
I have been getting the wrong values from my querying the only reason I can think of is it is to do with missing data in the dataset
but I don't know if thats it or exactly why I get the wrong values
allWines = LOAD 'winemag-data_first150k.csv' USING PigStorage(',') AS (id:chararray, country:chararray, description:chararray, designation:chararray, points:chararray, price:chararray, province:chararray, region_2:chararray, region_1:chararray, variety:chararray, winery:chararray);
allWinesNotNull = FILTER allWines BY price is not null;
allWinesNotNull2 = FILTER allWinesNotNull BY points is not null;
allWinesPriceSorted = ORDER allWinesNotNull2 BY price;
allWinesPriceTop5Sorted = LIMIT allWinesPriceSorted 5;
allWinesPricePoints = FOREACH allWinesPriceTop5Sorted GENERATE id, price;
DUMP allWinesPricePoints;
DESCRIBE allWinesPricePoints;
The actual results I get are
(56203, buttered toast and spice flavors that are wrapped into a creamy texture. Should hold for a year or two.")
(61341, sweet tannins. The fresh acidity gives it an extra boost. Give it time. Best 2007–2012.")
(16417, Chardonnay is also known)
(115384, almonds and vanilla)
(136804, almonds and vanilla)
I think the output should be
(56203, 23)
(61341, 30)
(16417, 16)
(115384, 250)
(136804, 250)
I would have expected the second value to be numeric and in the price column
Proceed as follow:
allWines = LOAD 'winemag-data_first150k.csv' USING PigStorage(',') AS (id:chararray, country:chararray, description:chararray, designation:chararray, points:chararray, price:chararray, province:chararray, region_2:chararray, region_1:chararray, variety:chararray, winery:chararray);
--comments
--add below foreach to generate the values this will help you out to parse data correctly
--generate column in the same order as it is in the text file
allWines= FOREACH allWines GENERATE
id AS id,
country AS country,
description AS description,
designation AS designation,
points AS points,
price AS price,
province AS provience,
region_2 AS region_2,
region_1 AS region_1,
variety AS variety,
winery AS winery;
allWinesNotNull = FILTER allWines BY price is not null;
allWinesNotNull2 = FILTER allWinesNotNull BY points is not null;
allWinesPriceSorted = ORDER allWinesNotNull2 BY price;
allWinesPriceTop5Sorted = LIMIT allWinesPriceSorted 5;
allWinesPricePoints = FOREACH allWinesPriceTop5Sorted GENERATE id, price;
DUMP allWinesPricePoints;
DESCRIBE allWinesPricePoints;
Hope this will help you out.
let me know in case of any concern.

Office 365 dll querying Calendarview doesn't support StartDateTime or EndDateTime

Similar to this question
When querying CalendarView, it doesn't seem to support Start and End ( so they don't get translated into the correct values).
My code returns an error because i didn't include the parameters.
Is there any way to add these parameters through the OutlookServicesClient?
My current code looks like this:
Dim calendarView = exClient.Me.CalendarView
' For Each Attendee In AttendeesFilter.Split(New Char() {Char.Parse(";")}, StringSplitOptions.RemoveEmptyEntries)
' calendarView.Where(Function(dl) dl.Attendees.Any(Function(el) el.EmailAddress.Equals(Attendee)))
' Next 'Office365 doesnt seem to filter on attendees
startDate = DateTime.Now.AddMonths(-1)
endDateTime = DateTime.Now
If startDate.HasValue AndAlso endDateTime.HasValue Then
calendarView.Where(Function(dl) dl.Start.Value <= startDate.Value AndAlso dl.End.Value <= endDateTime.Value) 'doesnt seem to filter on dates
End If
The exact error i receive is :
Type: Microsoft.OData.Core.ODataErrorException
Message: This request requires a time window specified by the query string parameters startDateTime and endDateTime.
Although i can't seem to find a proper way on how to add the time window :s
There is a function:
exClient.Me.Calendar.GetCalendarView(startDateOffset, endDateOffset)
This filters between start and endDate instead of adding it to the Query
You can get a CalendarView as follows:
var eventResults = await exClient.Me.Calendar
.GetCalendarView(startDateTime,endDateTime)
.Take(10)
.ExecuteAsync();

How to query and calculate dates in the where clause of a LINQ statement?

I am having trouble with the following piece of code. Before I paste it, Let me give a bit of history on what should happen.
I have a model containing 2 fields of interest at the moment, which is the name of the order the customer placed, and the date at which he/she placed it. A pre-calculated date will be used to query the dateplaced field (and should only query the dates , and not the time). The query counts the amount of duplicates that occur in the MondayOrder field, and groups them together. Now , when I exclude the where clause which should query the dates, the query runs great. However, The goal of this query is to count the amount of orders for the following week based on the date the order has been placed.
List<string> returnlist = new List<string>();
DateTime dt = getNextWeekMondaysDate().Date;
switch (day)
{
case DayOfWeek.Monday:
{
var CountOrders =
from x in Data.EntityDB.Orders
group x by x.MondayOrder into m
let count = m.Count()
select new
{
MondayOrderItem = m.Key, Amount = count
};
foreach (var item in CountOrders)
{
returnlist.Add(item.MondayOrderItem + " : " +
item.Amount);
}
}
break;
The getNextWeekMondaysDate() method has an overload which I can use, where if I supply it a date, it will get the following Monday's date from the parameter given. The problem is though, LINQ does not accept queries such as the following:
var CountOrders =
from x in Data.EntityDB.Orders
where getNextWeekMondaysDate(x.DatePlaced.Value).Date == dt
group x by x.MondayOrder into m
let count = m.Count()
select new { MondayOrderItem = m.Key, Amount = count };
This is exactly what I must achieve. Is there any workaround for this situation?
UPDATE
Here is the exception I get when I try the 2nd query.
LINQ to Entities does not recognize the method 'System.DateTime getNextWeekMondaysDate(System.DateTime)' method, and this method cannot be translated into a store expression.
You cannot do this directly, as user-defined method calls cannot be translated to SQL by the EF query provider. The provider recognizes a limited set of .NET methods that can be translated to SQL and also a number of canonical functions as well. Anything that cannot be expressed using these methods only is off-limits unless you write your own query provider (which is only theoretically an option).
As a practical workaround, you can calculate an appropriate range for x.DatePlaced.Value in code before the query and then use specific DateTime values on the where clause.
As an intellectual exercise, note that this method is recognized by the query provider and can be used as part of the expression. So this abomination should work too:
var CountOrders =
from x in Data.EntityDB.Orders
where EntityFunctions.AddDays(
x.DatePlaced.Date.Value,
(9 - DateAndTime.DatePart(DateInterval.WeekDay, x.DatePlaced.Value)) % 7)
.Date == dt
group x by x.MondayOrder into m
let count = m.Count()
select new { MondayOrderItem = m.Key, Amount = count };
Linq to Entities doesn't know how to convert arbitrary C# methods into SQL - it's not possible in general.
So, you have to work with the methods it does understand.
In this case, you could do something like this:
DateTime weekBegin = CalculateWeekBegin( dt );
DateTime weekEnd = CalculateWeekEnd( dt );
var CountOrders =
from x in Data.EntityDB.Orders
where x.DatePlaced.Value >= weekBegin && x.DatePlaced.Value < weekEnd
group x by x.MondayOrder into m
let count = m.Count()
select new { MondayOrderItem = m.Key, Amount = count });

Linq get Date from DateTime nullable field

I have the following where I need to get only the Date (not datetime) from
ReqDate and RepDeclined which are both nullable datetime fields.
var info = from pr in db.Prog
join tf in db.In_Lens
on pr.PID equals tf.PID
select new
{ ReqDate = String.Format("{0:MM/dd/yyyy}",tf.ReqDate),
ReqDeclinedDate = tf.ReqDeclined.ToString("MM/dd/yyyy")
}).ToList()
It is not working as ReqDate and RepDeclined are both nullable datetime fields.
I also tried String.Format but no luck.
It says no overload for method.
You can try this, more elegant i think
var info = from pr in db.Prog
join tf in db.In_Lens
on pr.PID equals tf.PID
select new
{ ReqDate = !string.IsNullOrEmpty(tf.ReqDate) ? string.Format("{0:MM/dd/yyyy}",tf.ReqDate) : string.Empty(),
ReqDeclinedDate = !string.IsNullOrEmpty(tf.ReqDeclined) ? tf.ReqDeclined.ToString("MM/dd/yyyy") : string.Empty()
}).ToList()
I just way changed my answer.. basically.. you need to get back a couple datetimes in your new collection.. and then when you use those values, you can do the String.Format(). The reason is LINQ boils down to SQL, and there's no String.Format() converter (yet?).
so when you loop through the results, you can transform those results to display propertly (i.e. String.Format(...)).. but you will not be able to select out and convert the results in one linq statement, you might be able to do it LAMBDA (.ForEach()), which would be able to iterate through the results, however, it would just be a shorhtand way of doing what i described above..
...to the best of my knowledge

Linq to EF Expression Tree / Predicate int.Parse workaround

I have a linq Entity called Enquiry, which has a property: string DateSubmitted.
I'm writing an app where I need to return IQueryable for Enquiry that have a DateSubmitted within a particular date range.
Ideally I'd like to write something like
IQueryable<Enquiry> query = Context.EnquirySet.AsQueryable<Enquiry>();
int dateStart = int.Parse("20090729");
int dateEnd = int.Parse("20090930");
query = (from e in query
where(enq => int.Parse(enq.DateSubmitted) < dateEnd)
where(enq => int.Parse(enq.DateSubmitted) > dateStart)
select e);
Obviously Linq to EF doesn't recognise int.Parse, so I think I can achieve what I want with an Expression method that returns a predicate???
I've been playing around with PredicateBuilder and looking all over but I've successfully fried my brains trying to work this out. Sure I could add another property to my Entity and convert it there but I'd really like to understand this. Can anyone explain or give an example/link that doesn't fry my brains?
Thanks in advance
Mark
If you know your date strings are valid, and they're really in that order (which is a natural sort order) you might be able to get away with string comparisons:
IQueryable<Enquiry> query = Context.EnquirySet.AsQueryable<Enquiry>();
string dateStart ="20090729";
string dateEnd = "20090930";
query = (from e in query
where(enq => enq.DateSubmitted.CompareTo(dateEnd)) < 0)
where(enq => enq.DateSubmitted.CompareTo(dateStart)) > 0)
select e);

Resources