3
$\begingroup$

We have an IEnumerable Objects in C# that we want to import into the Wolfram Financial Platform. In the current C# API, we use LINQ queries to select from the Objects the specific Object that we need. In Wolfram Financial Platform we can import the IEnumerable Objects through NET/Link (More info: http://reference.wolfram.com/language/NETLink/tutorial/Overview.html)

Once the object is imported, there does not seem to be a way to use LINQ queries even after importing the LINQ library. Additionally, lambda expressions used in the LINQ queries do not have a clear replacement in Wolfram Financial Platform.

Examples

C#

Object.Where(x => x.Property == Target).FirstOrDefault();

Wolfram

???[# == #.Property &, Object]`FirstOrDefault[];

Current Attempt + Error

C#

Option call = optionChain.Options
                                  .Where(x => (x.Expiration - DateTime.Today).TotalDays > 7 && (x.Expiration - DateTime.Today).TotalDays < 45 && x.PutCall == PutCall.Call && x.Class.Settlement == null)
                                  .OrderBy(x => Math.Abs(msft.Trade.Last - x.Strike)).FirstOrDefault();

Wolfram (baby steps version)

call = optionChain@Options`FirstOrDefault[];

Error

"No public instance method named "FirstOrDefault" exists for the .NET type "Core.Data.MarketData.OptionChain".

Also tried using First[optionChain@Options]; and got the non-atomic error. Found that could mean an infinite loop or non-existent variable. Checked that optionChain@Options exists by outputting it through NETConsole, which makes me think that NETObjects won't work with First[] (?)

End Goal

Import specific values from a C# API with LINQ queries, or equivalent, intact into Wolfram Financial Platform for the purpose of writing a program in the Wolfram Financial Platform language (not allowed to do it the other way around, as much as I want to).

Originally posted this on StackExchange, but it looks like it is pending removal due to being "off-topic"

$\endgroup$
7
  • $\begingroup$ Does optionChain@Options give a Wolfram list of option objects? If so have you tried Select? Something like Select[DateDifference[#`Expiration - Today, "Day"] > Quantity[7, "Days"] &]@(optionChain@Options). Elements of Lists guide $\endgroup$
    – Edmund
    Commented Mar 22, 2016 at 17:06
  • $\begingroup$ optionChain@Options returns a System.Collections.Generic.List`1[Core.Data.Securities.Option] object, which gives a non-atomic exception when using Select. $\endgroup$ Commented Mar 22, 2016 at 17:37
  • $\begingroup$ Add @ToArray[] immediately after Options inside of the bracket. This will convert it into a Wolfram list. Then the Select should be happy. Well the only part I am unsure about is the #`Expiration bit. $\endgroup$
    – Edmund
    Commented Mar 22, 2016 at 17:44
  • $\begingroup$ Sorry, the - in DateDifference should be a ,. $\endgroup$
    – Edmund
    Commented Mar 22, 2016 at 17:49
  • $\begingroup$ Alright, cooking with gas, now. The DateDifference is having difficulties with the Expiration's .NETDateTime object, but now Select, First, etc. work with the Options object. $\endgroup$ Commented Mar 22, 2016 at 18:36

1 Answer 1

2
$\begingroup$

A solution to this is to convert the .Net collection into a Wolfram List and then use Select. ToArray can be called on Options for this conversion.

Also (from our chat), since Expiration is not static in C# then @ can be used instead of `. Combining these we get:

Select[DateDifference[DateObject[#@Expiration /@ {Year, Month, Day}], 
     Today, "Day"] < Quantity[15, "Days"] &]@
 (optionChain @ Options @ ToArray[])

The components of Expiration are taken into a Wolfram DateObject specification by #@Expiration /@ {Year, Month, Day}

Additional conditions can be added to Select.

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.