Skip to content

Commit

Permalink
Added Java Support
Browse files Browse the repository at this point in the history
Added Java Support for QuantConnect
  • Loading branch information
craig-stevenson committed Jun 28, 2015
1 parent 6f4b12f commit 88b93b1
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Algorithm.Java/BasicTemplateAlgorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package QuantConnect;
import cli.QuantConnect.Resolution;
import cli.QuantConnect.SecurityType;
import cli.QuantConnect.Algorithm.QCAlgorithm;
import cli.QuantConnect.Data.Market.TradeBars;

public class BasicTemplateAlgorithm extends QCAlgorithm{
public void Initialize()
{
SetStartDate(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.wrap(SecurityType.Equity), "SPY", Resolution.wrap(Resolution.Second),true,false);
}

public void OnData(TradeBars data)
{
if (!get_Portfolio().get_Invested())
{
SetHoldings("SPY", 1, false);
Debug("Hello From Java");
}
}
}
36 changes: 36 additions & 0 deletions Algorithm.Java/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("QuantConnect.Algorithm.Java")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuantConnect.Algorithm.Java")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("aa1e3c97-ec2f-447d-b3a7-a129fb6035ed")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
185 changes: 185 additions & 0 deletions Algorithm.Java/QuantConnect.Algorithm.Java.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{61097E9E-EB20-4677-B394-CE0682B9D610}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>QuantConnect.Algorithm.Java</RootNamespace>
<AssemblyName>QuantConnect.Algorithm.Java</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="ikvm">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\ikvm.exe</HintPath>
</Reference>
<Reference Include="IKVM.AWT.WinForms">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.AWT.WinForms.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Beans">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Beans.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Charsets">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Charsets.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Corba">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Corba.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Core">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Core.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Jdbc">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Jdbc.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Management">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Management.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Media">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Media.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Misc">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Misc.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Naming">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Naming.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Remoting">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Remoting.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Security">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Security.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.SwingAWT">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.SwingAWT.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Text">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Text.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Tools">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Tools.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Util">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.Util.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.API">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.API.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.Bind">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.Bind.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.Crypto">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.Crypto.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.Parse">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.Parse.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.Transform">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.Transform.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.WebServices">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.WebServices.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.XML.XPath">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.OpenJDK.XML.XPath.dll</HintPath>
</Reference>
<Reference Include="IKVM.Reflection">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.Reflection.dll</HintPath>
</Reference>
<Reference Include="IKVM.Runtime">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.Runtime.dll</HintPath>
</Reference>
<Reference Include="IKVM.Runtime.JNI">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\IKVM.Runtime.JNI.dll</HintPath>
</Reference>
<Reference Include="ikvmc">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\ikvmc.exe</HintPath>
</Reference>
<Reference Include="ikvmstub">
<HintPath>..\packages\IKVM-WithExes.7.3.4830.1\tools\ikvmstub.exe</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="build.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="build.sh" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
<Project>{3240aca4-bdd4-4d24-ac36-bbb651c39212}</Project>
<Name>QuantConnect.Algorithm</Name>
</ProjectReference>
<ProjectReference Include="..\Common\QuantConnect.csproj">
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
<Name>QuantConnect</Name>
</ProjectReference>
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
<Name>QuantConnect.Indicators</Name>
</ProjectReference>
<ProjectReference Include="..\Interfaces\QuantConnect.Interfaces.csproj">
<Project>{338f614c-4cd7-418a-bd31-8c6a8690cfbf}</Project>
<Name>QuantConnect.Interfaces</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="BasicTemplateAlgorithm.java">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">
build
</PostBuildEvent>
<PostBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
chmod 755 build.sh
./build.sh
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
7 changes: 7 additions & 0 deletions Algorithm.Java/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SET dotnet_framework="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5"
ikvmstub -nostdlib %dotnet_framework%\mscorlib.dll
ikvmstub -nostdlib -r:%dotnet_framework%\mscorlib.dll QuantConnect.Algorithm.dll
ikvmstub -nostdlib -r:%dotnet_framework%\mscorlib.dll QuantConnect.Interfaces.dll
ikvmstub -nostdlib -r:%dotnet_framework%\mscorlib.dll -r:%dotnet_framework%\System.dll -r:%dotnet_framework%\System.Core.dll -r:%dotnet_framework%\System.Xml.Linq.dll QuantConnect.Common.dll
javac -cp QuantConnect.Algorithm.jar;QuantConnect.Interfaces.jar;mscorlib.jar;QuantConnect.common.jar *.java
ikvmc -debug -target:library -out:QuantConnect.Algorithm.Java.dll -nostdlib -r:QuantConnect.Common.dll -r:QuantConnect.Indicators.dll -r:QuantConnect.Algorithm.dll -r:QuantConnect.Interfaces.dll -r:Newtonsoft.json.dll -r:%dotnet_framework%\mscorlib.dll -r:%dotnet_framework%\System.dll -r:%dotnet_framework%\System.Core.dll -r:%dotnet_framework%\System.Xml.Linq.dll *.class
5 changes: 5 additions & 0 deletions Algorithm.Java/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IKVM-WithExes" version="7.3.4830.1" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>
4 changes: 4 additions & 0 deletions Engine/QuantConnect.Lean.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
<Project>{7702711a-0c09-40d4-b151-e308d1520738}</Project>
<Name>QuantConnect.Algorithm.FSharp</Name>
</ProjectReference>
<ProjectReference Include="..\Algorithm.Java\QuantConnect.Algorithm.Java.csproj">
<Project>{61097e9e-eb20-4677-b394-ce0682b9d610}</Project>
<Name>QuantConnect.Algorithm.Java</Name>
</ProjectReference>
<ProjectReference Include="..\AlgorithmFactory\QuantConnect.AlgorithmFactory.csproj">
<Project>{e99d056a-b6fb-48d2-9f7c-683c54cebbf9}</Project>
<Name>QuantConnect.AlgorithmFactory</Name>
Expand Down
3 changes: 2 additions & 1 deletion Engine/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

// algorithm selector
"algorithm-type-name": "BasicTemplateAlgorithm",
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
"algorithm-location": "QuantConnect.Algorithm.Java.dll",
//"algorithm-location": "QuantConnect.Algorithm.CSharp.dll"
//"algorithm-location": "QuantConnect.Algorithm.FSharp.dll",
//"algorithm-location": "QuantConnect.Algorithm.VisualBasic.dll",

Expand Down
16 changes: 15 additions & 1 deletion QuantConnect.Lean.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.Lean.Engine", "Engine\QuantConnect.Lean.Engine.csproj", "{12156F46-D07E-4E3D-AD2B-7409E82AB62F}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -49,6 +49,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "QuantConnect.Algorithm.Visu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.Algorithm.Python", "Algorithm.Python\QuantConnect.Algorithm.Python.csproj", "{48289996-CE56-4EDF-B451-4A2B1519EBC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.Algorithm.Java", "Algorithm.Java\QuantConnect.Algorithm.Java.csproj", "{61097E9E-EB20-4677-B394-CE0682B9D610}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -304,6 +306,18 @@ Global
{48289996-CE56-4EDF-B451-4A2B1519EBC3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{48289996-CE56-4EDF-B451-4A2B1519EBC3}.Release|x64.ActiveCfg = Release|Any CPU
{48289996-CE56-4EDF-B451-4A2B1519EBC3}.Release|x86.ActiveCfg = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|x64.ActiveCfg = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Debug|x86.ActiveCfg = Debug|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|Any CPU.Build.0 = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|x64.ActiveCfg = Release|Any CPU
{61097E9E-EB20-4677-B394-CE0682B9D610}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 88b93b1

Please sign in to comment.