Tag Archives: #csharp

dot net framework array to r program code through the R CSharp package

Note: I really no longer support dot net framework array to r anymore. This means that I don’t support .NET nor Microsoft nor Windows anymore due to  back door security concerns I have with their product. I would strongly Python and other open source technologies over Microsoft product Also, this R posting is here as a courtesy due to R is still popular. Also remember this link recommended from my Academy section is from 2012 so it might no longer work.

Very Nice! My C# program calls R Code through the R.NET package. 

How to get R connect to NOSQL scalable database Redis with doRedis R package for parallelization

Whoa! I finally got this working with R.NET. I can get my C# appliction call directly R code which is very nice. There is a nasty bug on the search path of R so note at the beginning of the code as well. Get more info about R.Net package from http://rdotnet.codeplex.com/. Here is the C# code but don’t foret to add the.NET.DLL DLL reference in your Visual Studio:

Enjoy this C Sharp code

using System;
using System.Linq;
using RDotNet;

class Program
{
    static void Main(string[] args)
    {
        //code solution from http://stackoverflow.com/questions/7960738/importing-mgcv-fails-because-rlapack-dll-cannot-be-found
        string rhome = System.Environment.GetEnvironmentVariable(“R_HOME”);
        if (string.IsNullOrEmpty(rhome))
            rhome = @”C:Program FilesRR-2.15.0″;

        System.Environment.SetEnvironmentVariable(“R_HOME”, rhome);
        System.Environment.SetEnvironmentVariable(“PATH”, System.Environment.GetEnvironmentVariable(“PATH”) + “;” + rhome + @”bini386″);

        // Set the folder in which R.dll locates.
        //REngine.SetDllDirectory(@”C:Program FilesRR-2.12.0bini386″);
        REngine.SetDllDirectory(@”C:Program FilesRR-2.15.0bini386″);
        using (REngine engine = REngine.CreateInstance(“RDotNet”, new[] { “-q” }))  // quiet mode
        {
            foreach (string path in engine.EagerEvaluate(“.libPaths()”).AsCharacter())
            {
               Console.WriteLine(path);
            }
            //engine.EagerEvaluate(“.libPaths(“C:/Program Files/R/R-2.15.0/library”);

            // .NET Framework array to R vector.
            NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
            engine.SetSymbol(“group1”, group1);
            // Direct parsing from R script.
            NumericVector group2 = engine.EagerEvaluate(“group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)”).AsNumeric();

            // Test difference of mean and get the P-value.
            GenericVector testResult = engine.EagerEvaluate(“t.test(group1, group2)”).AsList();
            double p = testResult[“p.value”].AsNumeric().First();

            Console.WriteLine(“Group1: [{0}]”, string.Join(“, “, group1));
            Console.WriteLine(“Group2: [{0}]”, string.Join(“, “, group2));
            Console.WriteLine(“P-value = {0:0.000}”, p);
        }
    }
}

 

Here is an C# example:

using System;
using System.Linq;
using RDotNet;

class Program
{
    static void Main(string[] args)
    {
        //code solution from http://stackoverflow.com/questions/7960738/importing-mgcv-fails-because-rlapack-dll-cannot-be-found
        string rhome = System.Environment.GetEnvironmentVariable(“R_HOME”);
        if (string.IsNullOrEmpty(rhome))
            rhome = @”C:Program FilesRR-2.15.0″;

        System.Environment.SetEnvironmentVariable(“R_HOME”, rhome);
        System.Environment.SetEnvironmentVariable(“PATH”, System.Environment.GetEnvironmentVariable(“PATH”) + “;” + rhome + @”bini386″);

        // Set the folder in which R.dll locates.
        //REngine.SetDllDirectory(@”C:Program FilesRR-2.12.0bini386″);
        REngine.SetDllDirectory(@”C:Program FilesRR-2.15.0bini386″);
        using (REngine engine = REngine.CreateInstance(“RDotNet”, new[] { “-q” }))  // quiet mode
        {
            foreach (string path in engine.EagerEvaluate(“.libPaths()”).AsCharacter())
            {
               Console.WriteLine(path);
            }
            engine.EagerEvaluate(“.libPaths(“C:/Program Files/R/R-2.15.0/library”);

            // .NET Framework array to R vector.
            //NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
            //engine.SetSymbol(“group1”, group1);
            //// Direct parsing from R script.
            //NumericVector group2 = engine.EagerEvaluate(“group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)”).AsNumeric();

            //// Test difference of mean and get the P-value.
            //GenericVector testResult = engine.EagerEvaluate(“t.test(group1, group2)”).AsList();
            //double p = testResult[“p.value”].AsNumeric().First();

            //Console.WriteLine(“Group1: [{0}]”, string.Join(“, “, group1));
            //Console.WriteLine(“Group2: [{0}]”, string.Join(“, “, group2));
            //Console.WriteLine(“P-value = {0:0.000}”, p);

            //example to call complete R script from http://rdotnet.codeplex.com/discussions/262426
            //REngine R = REngine.GetInstanceFromID(“RDotNet”);
            //R.EagerEvaluate(“source(“MyRscript.r”)”);
            engine.EagerEvaluate(“source(“test.r”)”);
            Console.ReadLine();
        }
    }
}

Here is R script test.r which resides in the same Release directory as the C# program.

G<-c(1,2,3)
G
cat(‘hello from r’, G)

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

DotNET CSharp demo XLQ data server using IQFeed market data

DotNET CSharp demo XLQ data server using IQFeed market data

Here is a reasons why I am ‘stuck’ on Windows for now Get the source code project here

xlqtest

http://www.qmatix.com/XLQ.htm

Join my FREE newsletter here for other cool source projects for automated trading 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Is Java or DOTNET CSharp faster

Is Java or DOTNET CSharp faster

I cannot say myself but the better question is which one is more dangerous? Java is top platform to hackers. C# is based on an operating system from a vendor who does not publicly state they don’t install backdoors on the OS. Which one you feel safer on for live trading account? My answer: NEITHER. Just search this blog for either topic.

https://www.quora.com/Which-one-is-faster-JAVA-or-C

Join my FREE newsletter to learn more about which alternatives are better 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Video Demo of DotNET CSharp calling Matlab for trading chart

Video Demo of DotNET CSharp calling Matlab for trading chart

I also demo a Bollinger and Moving Average Charts from Matlab. All the code is 10% of usual of what I am used with .NET charting libraries.

This is source code for both Matlab and the Visual Studio Solution project at the  Quant Elite 

Join my FREE newsletter to learn more about how I plan to implement 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

CSharp call Matlab chart with options

CSharp call Matlab chart  with option

This is the best approach to call Matlab with various financial charting options

You can download the source code

 https://quantlabs.net/blog/2014/03/youtube-video-demo-of-dotnet-csharp-calling-a-matlab-plot-with-no-refresh-needed/

Join my FREE to see other options I will present for charting for financial applications 

Other financial chart from Matlab:

http://www.mathworks.com/help/finance/visualizing-financial-time-series-objects.html

http://www.mathworks.com/help/finance/charting-financial-data.html

http://www.mathworks.com/help/finance/visualizing-financial-time-series-objects.html

 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

How to have DotNET CSharp client call Matlab script

How to have DotNET CSharp client call Matlab script

Links are below for lessons mentioned in video

Join my FREE newsletter to learn more about this tech combo for automated trading 

C# Source code:

//mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html
//add MLApp.dll with stackoverflow.com/questions/9780805/where-is-matlab-application-type-library
//or use how-i-fixed-it.blogspot.ca/2013/05/matlab-application-type-library-mlapp.html
//How-i-fixed-it:
//1. Open a windows command prompt as administrator
//2. Navigate to your Matlab installation directory\bin
//3. matlab.exe /register
//4. In the matlab command windows enter: !matlab -regserver
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpCallMatlab
{
class Program
{
static void Main(string[] args)
{

// Create the MATLAB instance
MLApp.MLApp matlab = new MLApp.MLApp();

// Change to the directory where the function is located
matlab.Execute(@”cd C:\Users\Bryan\Documents\MATLAB\csharp”);

// Define the output
object result = null;

// Call the MATLAB function myfunc
matlab.Feval(“myfunc”, 2, out result, 3.14, 42.0, “world”);

// Display result
object[] res = result as object[];

Console.WriteLine(res[0]);
Console.WriteLine(res[1]);
Console.ReadLine();
}
}
}

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Walkthru of Karen Super Trader strategy with CSharp Postgres SQL IQFeed and IB

Walkthru of Karen Super Trader strategy with CSharp Postgres SQL IQFeed and Interactive Brokers

I have finally finished off the new Karen Super Trader strategy in .Net with IQFeed and Interactive Brokers connectivity I have completed an entire 45 minute walk through video of the entire code.

 

Go here to see the video

 

LIVE Q&A Meetup: Walkthru of Karen Super Trader strategy with source code

I will also be scheduling a LIVE Meetup event to handle all your questions and answers next Monday. This is the only time where I will be able to do it so please attend.  Do note that I will not be having any video playback at all which is exclusively only for my Quant Elite members.

 

Go here to see the details of this event online

 

Lastly, if you are interested in retrieving the code:

 

Go here for immediate access

 

If you’re not familiar with my Quant elite membership, go here for details and benefits

 

Thanks for reading

 

Bryan

 

PS. I just posted last night’s webinar on the tools that I use for both IQFeed and Interactive Brokers TWS

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!