From a32e9ee9df9dfc4c9a5504644db541f807394dcb Mon Sep 17 00:00:00 2001 From: Martin-Molinero Date: Tue, 1 Jun 2021 18:23:15 -0300 Subject: [PATCH] Initial Commit --- .gitignore | 279 ++++++++++++++++++++++++++++++++ BashConverterScript.sh | 0 CSharpConverterNotebook.ipynb | 0 DataLibrary.sln | 31 ++++ DataLibrary/DataLibrary.csproj | 14 ++ DataLibrary/MyCustomDataType.cs | 142 ++++++++++++++++ PythonConverterNotebook.ipynb | 0 PythonConverterScript.py | 0 README.md | 28 +++- Tests/CustomDataAlgorithm.cs | 55 +++++++ Tests/MyCustomDataTypeTests.cs | 36 +++++ Tests/Tests.csproj | 19 +++ 12 files changed, 603 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 BashConverterScript.sh create mode 100644 CSharpConverterNotebook.ipynb create mode 100644 DataLibrary.sln create mode 100644 DataLibrary/DataLibrary.csproj create mode 100644 DataLibrary/MyCustomDataType.cs create mode 100644 PythonConverterNotebook.ipynb create mode 100644 PythonConverterScript.py create mode 100644 Tests/CustomDataAlgorithm.cs create mode 100644 Tests/MyCustomDataTypeTests.cs create mode 100644 Tests/Tests.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..866dd07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,279 @@ +# Object files +*.o +*.ko +*.obj +*.elf +*.pyc + +# Visual Studio Project Items: +*.suo + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +#*.dll +*.so +*.so.* +*.dylib + +# Executables +*/bin/*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# QC Cloud Setup Bash Files +*.sh +# Include docker launch scripts for Mac/Linux +!run_docker.sh +!research/run_docker_notebook.sh + +# QC Config Files: +# config.json + +# QC-C-Specific +*Engine/bin/Debug/cache/data/*.zip +*/obj/* +*/bin/* +*Data/* +*Docker/* +*/Docker/* +*Algorithm.Python/Lib/* +*/[Ee]xtensions/* +!**/Libraries/* + +# C Debug Binaries +*.pdb + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +.vs/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# JetBrains Rider +.idea/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +!LocalPackages/* +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# If using the old MSBuild-Integrated Package Restore, uncomment this: +#!**/packages/repositories.config +# ignore sln level nuget +.nuget/ +!.nuget/NuGet.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Test Runner +testrunner/ + +# Meld original diff files +*.orig + +# Output chart data +Charts/ + +# NCrunch files +*.ncrunchsolution +*.ncrunchproject + +# QuantConnect plugin files +QuantConnectProjects.xml +Launcher/Plugins/* +/ApiPython/dist +/ApiPython/quantconnect.egg-info +/ApiPython/quantconnect.egg-info/* + +QuantConnect.Lean.sln.DotSettings* + +#User notebook files +Research/Notebooks + +#Docker result files +Results/ \ No newline at end of file diff --git a/BashConverterScript.sh b/BashConverterScript.sh new file mode 100644 index 0000000..e69de29 diff --git a/CSharpConverterNotebook.ipynb b/CSharpConverterNotebook.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/DataLibrary.sln b/DataLibrary.sln new file mode 100644 index 0000000..9290c71 --- /dev/null +++ b/DataLibrary.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataLibrary", "DataLibrary\DataLibrary.csproj", "{68E7301F-DEA2-4688-B519-DE5E59F6F252}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{46223B6F-6400-4C76-9066-441E8ACB6A21}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {68E7301F-DEA2-4688-B519-DE5E59F6F252}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68E7301F-DEA2-4688-B519-DE5E59F6F252}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68E7301F-DEA2-4688-B519-DE5E59F6F252}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68E7301F-DEA2-4688-B519-DE5E59F6F252}.Release|Any CPU.Build.0 = Release|Any CPU + {46223B6F-6400-4C76-9066-441E8ACB6A21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46223B6F-6400-4C76-9066-441E8ACB6A21}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46223B6F-6400-4C76-9066-441E8ACB6A21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46223B6F-6400-4C76-9066-441E8ACB6A21}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31C08380-AE42-4398-A61D-B9BC9434B48C} + EndGlobalSection +EndGlobal diff --git a/DataLibrary/DataLibrary.csproj b/DataLibrary/DataLibrary.csproj new file mode 100644 index 0000000..017230c --- /dev/null +++ b/DataLibrary/DataLibrary.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + + + + + + + + + + diff --git a/DataLibrary/MyCustomDataType.cs b/DataLibrary/MyCustomDataType.cs new file mode 100644 index 0000000..700f7a4 --- /dev/null +++ b/DataLibrary/MyCustomDataType.cs @@ -0,0 +1,142 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +using System; +using NodaTime; +using System.IO; +using QuantConnect; +using QuantConnect.Data; +using System.Collections.Generic; + +namespace DataLibrary +{ + /// + /// + /// + public class MyCustomDataType : BaseData + { + /// + /// Return the URL string source of the file. This will be converted to a stream + /// + /// Configuration object + /// Date of this source file + /// true if we're in live mode, false for backtesting mode + /// String URL of source file. + public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) + { + return new SubscriptionDataSource( + Path.Combine( + Globals.DataFolder, + "alternative", + "mycustomdatatype", + $"{config.Symbol.Value.ToLowerInvariant()}.csv" + ), + SubscriptionTransportMedium.LocalFile + ); + } + + /// + /// Parses the data from the line provided and loads it into LEAN + /// + /// Subscription configuration + /// Line of data + /// Date + /// Is live mode + /// New instance + public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) + { + var csv = line.Split(','); + + var parsedDate = Parse.DateTimeExact(csv[0], "yyyyMMdd"); + return new MyCustomDataType + { + Symbol = config.Symbol, + Value = Parse.Decimal(csv[1]), + Time = parsedDate, + EndTime = parsedDate + TimeSpan.FromDays(1) + }; + } + + /// + /// Clones the data + /// + /// A clone of the object + public override BaseData Clone() + { + return new MyCustomDataType + { + Symbol = Symbol, + Value = Value, + Time = Time, + EndTime = EndTime + }; + } + + /// + /// Indicates whether the data source is tied + /// to an underlying symbol and requires that corporate + /// events be applied to it as well, such as renames and delistings + /// + /// false + public override bool RequiresMapping() + { + return false; + } + + /// + /// Indicates whether the data is sparse. + /// If true, we disable logging for missing files + /// + /// true + public override bool IsSparseData() + { + return true; + } + + /// + /// Converts the instance to string + /// + public override string ToString() + { + return $"{Symbol} - {Value}"; + } + + /// + /// Gets the default resolution for this data and security type + /// + public override Resolution DefaultResolution() + { + return Resolution.Daily; + } + + /// + /// Gets the supported resolution for this data and security type + /// + public override List SupportedResolutions() + { + return DailyResolution; + } + + /// + /// Specifies the data time zone for this data type. This is useful for custom data types + /// + /// The of this data type + public override DateTimeZone DataTimeZone() + { + return DateTimeZone.Utc; + } + } +} diff --git a/PythonConverterNotebook.ipynb b/PythonConverterNotebook.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/PythonConverterScript.py b/PythonConverterScript.py new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 5cfc3e8..50aee43 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# LeanData \ No newline at end of file +# LeanData + +Lean custom data template repository + +### Getting started + +#### Introduction + + + +### User guide + +### Tutorial + +#### Create Data Type + +#### Create Algorithm + +#### Create Data Converters + +##### Python Notebook +##### CSharp Notebook +##### Python Script +##### Bash Script + +### Api reference + diff --git a/Tests/CustomDataAlgorithm.cs b/Tests/CustomDataAlgorithm.cs new file mode 100644 index 0000000..3390177 --- /dev/null +++ b/Tests/CustomDataAlgorithm.cs @@ -0,0 +1,55 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +using DataLibrary; +using QuantConnect.Algorithm; +using QuantConnect.Data; +using QuantConnect.Orders; + +namespace Tests +{ + /// + /// Example algorithm using the custom data type + /// + public class CustomDataAlgorithm : QCAlgorithm + { + /// + /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. + /// + public override void Initialize() + { + AddData("SPY"); + } + + /// + /// + /// + /// + public override void OnData(Slice slice) + { + + } + + /// + /// + /// + /// + public override void OnOrderEvent(OrderEvent orderEvent) + { + + } + } +} diff --git a/Tests/MyCustomDataTypeTests.cs b/Tests/MyCustomDataTypeTests.cs new file mode 100644 index 0000000..2098cd7 --- /dev/null +++ b/Tests/MyCustomDataTypeTests.cs @@ -0,0 +1,36 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +using NUnit.Framework; + +namespace Tests +{ + [TestFixture] + public class MyCustomDataTypeTests + { + [Test] + public void JsonRoundTrip() + { + + } + + [Test] + public void ProtobufRoundTrip() + { + + } + } +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 0000000..43eeb29 --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,19 @@ + + + net5.0 + + + + + + + all + + + + + + + + +