On September 14th, 2017, we published revised versions of our Privacy Policy, Terms of Service and Website Use Policy and published a Cookie Policy. Your continued use of Lynda.com means you agree to these revised documents, so please take a few minutes to read and understand them.

Develop the chart generator

- [Instructor] And returning to Visual Studio,I'm going to add a new project.This is going to be once again a Library.It's going to be called Visualisation.Again delete the scaffold.And I've pasted some code there.You'll see we've got a bunch of red squiggliesaround the opens.So we are going to install some references via NuGet.And we want something that's sponsoredby BlueMountain Capital called Rprovider.

Highest dependencies.Install.And we just rename the library.And we're also going to install something called Deedle,which gives us a way of kind of mirroringthe way that R likes to stall and manipulate data sets.Again that's via NuGet.And then go for Deedle.RPlugin.And you'll see I'm getting an error around System.Data.That's because I need to manually adda reference to System.Data.

Not via NuGet but just via the built-in Visual Studio stuff.And also references to StockChartBot.Data and ROP.Those are project references.Okay that's the donkey work done.I'll just talk you very brieflythrough this helper function here,because we're going to need R to or ggplot2to render to a file.We're going to need to have a wayof making temporary files and that is this.It just uses the built-in Windows functionalityfor making a temporary file.

It generates a suitable name for the filebecause we're going to attach PNG files to our Twitter repliesbecause that's the kind of graphicswhich Twitter likes to attach.And we're going to rename the generated temporary filewith that extension.And then we're going to return the renamed fileName.Okay a little more pasted code.This code, by the way, comes from the blogof someone called Evelina Gabasova.She's a very expert data scientistwho is very active in the F# and ggplot2 and R community.

I will place the link to her blogin the source code examples.And I very much urge you,once you finish watching this course,to go and look at the stuff she's done,if you're interested in visualisation.So just to reiterate, lots of this codeis adapted from stuff that Evelina's done.So here, we're making ourself a little operatorthat can take two SymbolicExpression objects,which are part of the R ecosystem,and combine them using the R plus operator.R has this concept, or ggplot2 has this concept,of combining elements of a chartby adding them together.

And this gives us an operator to do that.And then this function here,is a way of standardizing R fontSettings,again, by doing R calls and adding them togetherusing the operator we just defined.And a third piece of pasted code.This is going to take a Prices object,which you're familiar with from the previous section,and it's going to generate a visualisation of those Pricesand return, actually, the fileNamewhere that visualisation has been rendered to.

And the way we do that is in the try with block.So that we can handle failures using R Choice.fail model.Here, we're instantiating a Deedle data frame.And Deedle has a way of takinga high numerable ofRecords typesand producing a dataFramewith all the kind of named columns,which things like R like to have.So that's kind of built in using ofRecords.Then here's where the type provider stuff comes in.Because we've got a name space called R,and within R, you've got access to all sorts of things,which R provides.

Basically all of R's functions.So there's a massive list of all R's built-in,and, indeed, extension librariesand that kind of thing.Among those are ggplot2.So it can call ggplot.And because R has a very different wayof providing function parameters,we need to insert a reference tothis helper object namedParams,which is basically producing a dictionaryof parameter names to parameter values.

So we're saying here that the data I want you to plotis in this dataFrame we generated here.Because of the slight differencein the way types are handled,we need to box, or produce really, a pointerto that dataFrame.So all the values on the right-hand side of these pairs,you'll see, have all had box applied to them.There's a mapping parameter,which is going to do things to allow usto label our axes Date and Close.And then we're going to call an R function called geom_line,which let's us set the size, again using box,of the line, the color, and forestgreen isa built-in kind of default color name.

And we're also going to plus in a callto these standard font settings,which are going to give us sensible font sizesfor the chart we're going to attach to our tweet.And then, because we're actually,we don't need to preserve the results for all those callsbecause R has a kind of state of its own,so we don't need to keep track of it,we're actually going to ignore the results of all that.Then we're going to do a makeFile,using that function I outlined earlier.And we're going to do an R.ggsave using that fileName,setting some size parameters in centimeters.

And, again, ignoring the result,because R is keeping track of its own state.And then we're returning that fileNamewrapped in a succeed instance.

Resume Transcript Auto-Scroll

Author

Released

12/20/2016

F# is a functional-first programming language developed by Microsoft and used extensively in financial analysis and financial applications. F# expert developer Kit Eason steps you through the process of developing a simple F# financial application: a Twitter bot that charts stock price changes and respond to tweets with some simple descriptors of the stock performance, including gain/loss and highs/lows. Along the way, you'll learn the basics of F# syntax, including values, arrays, functions, and expressions, and how to test your code, analyze and chart third-party data. The lessons also provide a primer to concepts like test-driven development and railway-oriented programming—best practices for any F# development workflow.