GithubHelp home page GithubHelp logo

fbertram / turingtrader Goto Github PK

View Code? Open in Web Editor NEW
436.0 28.0 106.0 79.96 MB

The Open-Source Backtesting Engine/ Trading Simulator by Bertram Solutions.

Home Page: https://www.turingtrader.org/

License: GNU Affero General Public License v3.0

C# 99.65% R 0.18% Batchfile 0.18%
backtesting stocks options portfolios trading trading-algorithms trading-platform trading-strategies trading-bot c-sharp

turingtrader's Introduction

TuringTrader

GNU Affero General Public License

An open-source backtesting engine/ trading simulator, licensed under AGPL 3.0.

For news, updates, and more information about the project, please visit our website at https://www.turingtrader.org/.

Installing

To install TuringTrader, download the setup file from https://www.turingtrader.org/download/.

Documentation

Find the TuringTrader documentation at https://www.turingtrader.org/documentation/.

Building from Source

Prerequisites

  • Microsoft Visual Studio Community 2022
    • installation must include Workloads for .NET desktop development and Universal Windows Platform development
  • .NET 6.0 SDK
  • DocFX toolset version 2.62.2
  • WiX Toolset v4 (FireGiant's HeatWave Community Edition)

Build Steps

Here are the individual steps to build TuringTrader from source:

  • Install TuringTrader from binary distribution
  • Open TuringTrader solution in Visual Studio
  • Build release version of TuringTrader project
  • Publish TuringTrader application
  • Build BooksAndPubs project (linked against the binary version installed)
  • Build setup project
  • Build documentation

The project also contains a script for a single-click build of the installer. See SINGLE_CLICK_BUILD.bat at the repository root!

Happy coding!

Felix Bertram [email protected]

turingtrader's People

Contributors

fbertram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

turingtrader's Issues

FRED DataSource problem

Hello

When I try Keller's LAA strategy, I've got this error on the log, when I debug the program, the source from fred seems to download, and is stored on the cache directory. I don't understand what the problem ?.

running algorithm Keller's LAA
DataSourceYahoo: retrieving meta for IWD
DataSourceFred: retrieving meta for fred:UNRATE
DataSourceYahoo: loading data for IWD... finished after 0,9 seconds
DataSourceFred: loading data for fred:UNRATE... finished after 0,4 seconds
EXCEPTION: DataSourceFred: failed to load quotes for fred:UNRATE, Object reference not set to an instance of an object. at TuringTrader.Simulator.DataSourceCollection.DataSourceFred.LoadData(DateTime startTime, DateTime endTime) in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\DataSources\DataSourceFred.cs:line 367
at TuringTrader.Simulator.SimulatorCore.get_SimTimes()+MoveNext() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\Core\SimulatorCore.cs:line 420
at TuringTrader.BooksAndPubs.Keller_LAA_Core.Run()
at TuringTrader.MainWindow.<>c__DisplayClass35_0.<RunButton_Click>g__uiThread|1() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 540
finished algorithm Keller's LAA after 3,4 seconds
EXCEPTION: Plotter: no data to plot at TuringTrader.Simulator.Plotter.OpenWith(String pathToTemplateFile) in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\Core\Plotter.cs:line 239
at TuringTrader.BooksAndPubs.Keller_LAA_Core.Report()
at TuringTrader.MainWindow.<ReportButton_Click>b__36_0() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 593

Missing Invariant culture in CSV Double parser

Hi,

Thank you for the great software you made available. It is real help in quick testing some tactical trading ideas.

I've found a bug in the CSV that you may not be aware of because you have in system "." as decimal separator, but in Poland where I live it is ",", so Double parser throws an error and all read values end up beeing zeros.

The bug is in line

and simple adding Invariant configuration helps.

Regards,
Rafal

How do you close an option position before expiry?

I cannot seem to close out an option position? The behavior seems strange. For example if I open a LEAP call position 2 years out:

_incomePosition.Trade(_incomecurrentlots, OrderType.openNextBar)
        .Comment = "LEAP income position open";

Then try to close it 1 year before expiration:

_incomePosition.Trade(_incomecurrentlots, OrderType.closeThisBar)
         .Comment = "income position close";

It does not appear to close the position.

01/11/2010, Enhanced Buy and Hold: Buy 908x SPY
01/11/2010, Enhanced Buy and Hold: Buy 9x SPY121221C00090000 <------- this is the first LEAP call open
01/10/2011, Enhanced Buy and Hold: Buy 9x SPY121221C00090000 <------- This is the attempted close 1 year before expiration
01/10/2011, Enhanced Buy and Hold: Buy 47x SPY
01/10/2011, Enhanced Buy and Hold: Buy 9x SPY131220C00100000
01/09/2012, Enhanced Buy and Hold: Buy 9x SPY131220C00100000
.
.
.
12/31/2019, Enhanced Buy and Hold: Sell -1445x SPY <---- The only time I actually see a sell on the option contracts is at the end of the simulation when all positions get closed out.

btw, this is with the v1 simulator.

Any advise here Felix?

Thanks,
-Frank

Some showcase algorithms don't work

Version: Latest binary distribution

As an example, trying to run Clenow's Stocks on the Move (v2) from TuringTrader results in the following output:

EXCEPTION: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Failed to load data for Yahoo:BRK.B: One or more errors occurred. (Response status code does not indicate success: 404 (Not Found).)))))   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at TuringTrader.SimulatorV2.TimeSeries`1.get_Data() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\TimeSeries.cs:line 222
   at TuringTrader.SimulatorV2.TimeSeries`1.get_Item(Int32 offset) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\TimeSeries.cs:line 233
   at TuringTrader.BooksAndPubsV2.Clenow_StocksOnTheMove.<Run>b__51_1(String name)
   at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
   at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
   at System.Linq.OrderedEnumerable`1.ToList()
   at TuringTrader.BooksAndPubsV2.Clenow_StocksOnTheMove.<Run>b__51_0()
   at TuringTrader.SimulatorV2.Algorithm.<>c__DisplayClass71_0.<SimLoop>b__0() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 277
   at TuringTrader.SimulatorV2.Algorithm._simLoop(Func`2 innerBarFun, Double init) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 233
   at TuringTrader.SimulatorV2.Algorithm._simLoopOuter(Func`1 innerBarFun) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 247
   at TuringTrader.SimulatorV2.Algorithm.SimLoop(Action barFun) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 274
   at TuringTrader.BooksAndPubsV2.Clenow_StocksOnTheMove.Run()
   at TuringTrader.MainWindow.<>c__DisplayClass38_0.<RunButton_Click>g__uiThread|1() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 640
finished algorithm Clenow's Stocks on the Move after 1,2 seconds
EXCEPTION: Plotter: no data to plot   at TuringTrader.Simulator.Plotter.OpenWith(String pathToTemplateFile) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v1\Core\Plotter.cs:line 237
   at TuringTrader.SimulatorV2.Algorithm.Report() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 451
   at TuringTrader.MainWindow.<ReportButton_Click>b__39_0() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 693

Modifying showcase algorithms

Hi, I copied the Bensdorp file script in the Documents\TuringTrader\BooksAndPubs folder, and pasted it in the \Algorithms folder, to be able to modify it. Unfortunately, I get the error message below (I cut it short since it lists pretty much . What am I doing wrong?

Also, it seems that some scripts, such as LI_UniversalInvestment, are showing in the Turing Trader dropdown menu, but are not in the \BooksAndPubs folder. Are the showcase alogirthms hardcoded into the software?

I also notice some references in the \BooksAndPubs algos, like "Globals", that I could not find a reference to in the TuringTrader.org documentation. Can you provide some explanation on this?

Line 34: CS0234 - The type or namespace name 'Algorithms' does not exist in the namespace 'TuringTrader' (are you missing an assembly reference?)
Line 543: CS0246 - The type or namespace name 'LazyPortfolio' could not be found (are you missing a using directive or an assembly reference?)
Line 559: CS0246 - The type or namespace name 'LazyPortfolio' could not be found (are you missing a using directive or an assembly reference?)
Line 43: CS0246 - The type or namespace name 'AlgorithmPlusGlue' could not be found (are you missing a using directive or an assembly reference?)
Line 561: CS0115 - 'Bensdorp_30MinStockTrader_MRL_MRS_Combo.Name': no suitable method found to override
Line 563: CS0115 - 'Bensdorp_30MinStockTrader_MRL_MRS_Combo.ALLOCATION': no suitable method found to override
Line 568: CS0115 - 'Bensdorp_30MinStockTrader_MRL_MRS_Combo.BENCH': no suitable method found to override
...
Line 59: CS0103 - The name 'Assets' does not exist in the current context
Line 48: CS0103 - The name 'Universes' does not exist in the current context
Line 554: CS0103 - The name 'Globals' does not exist in the current context
...

Demo03_Portfolio - Can't load Yahoo data

The following message pops up when I run the script Demo03 on my computer:

EXCEPTION: DataSourceYahoo: failed to load quotes for XLY, No such host is known. No such host is known. at TuringTrader.Simulator.DataSourceCollection.DataSourceYahoo.LoadData(DateTime startTime, DateTime endTime) in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\DataSources\DataSourceYahoo.cs:line 421
at TuringTrader.Simulator.SimulatorCore.get_SimTimes()+MoveNext() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\Core\SimulatorCore.cs:line 446
at TuringTrader.Demos.Demo03_Portfolio.Run() in C:\Users\Matcha\Documents\TuringTrader\Algorithms\Demo Algorithms\Demo03_Portfolio.cs:line 75
at TuringTrader.MainWindow.<>c__DisplayClass35_0.<RunButton_Click>g__uiThread|1() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 540
finished algorithm Demo03_Portfolio after 4.2 seconds
EXCEPTION: Plotter: no data to plot at TuringTrader.Simulator.Plotter.OpenWith(String pathToTemplateFile) in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader.Simulator\Core\Plotter.cs:line 239
at TuringTrader.Demos.Demo03_Portfolio.Report() in C:\Users\Matcha\Documents\TuringTrader\Algorithms\Demo Algorithms\Demo03_Portfolio.cs:line 161
at TuringTrader.MainWindow.<ReportButton_Click>b__36_0() in C:\Users\Felix\Documents\Trading\TuringTrader\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 593

Issues with Datasource tiingo

Hi all!

When I get the stock data from tiingo, if I change later the date of the global variable "END_TIME" to get the last data of the current week, it doesn't download the new data, so the stock is noted as "delisted". How to tell turingtrader to update correctly the data, I have to delete the data from the cache everyweek to update the full data.

How to enable IntelliSense for algorithms?

When choosing "Edit -> Algorithm Source..." to edit an algorithm, IntelliSense doesn't work because the files are not part of the source solution. (i.e. the Demo scripts)

It's impractical to not have autocomplete or not to be able to go to a method's definition when editing scripts.

What's the recommended way to enable IntelliSense for algorithm scripts?

Trailing stop order?

Did a quick grep, but didn't find Trailing stop orders.

Just wondering can this be added?

Thanks.

asset.Monthly().Open and asset.Monthly().Close does not work the way you would think

I found something strange in the TuringTrader.org. I am using the latest version,
I am not sure if this is a bug in the API or a problem with my understanding.
Whenever you have some time, if you would please let me know your thoughts, I would appreciate it!

var asset = Asset(ETF.SPY);

On SimDate of Jan 31, 2020, if I do
asset.Monthly().Open[0] I get 309.3909221661874
asset.Monthly().Close[0] I get 304.40472412109375
I thought that using asset.Monthly().Open[0], I would get the opening price of the month January, 2020 (306.1172745036964) instead of 309.3909221661874

If I print the daily Open and Close each of the month of Jan, 2020 I get this

1-2-2020 daily open=306.1172745036964 daily close=307.3756408691406
1-3-2020 daily open=303.8654391035394 daily close=305.0481262207031
1-6-2020 daily open=303.2316099598491 daily close=306.2120056152344
1-7-2020 daily open=305.625314816108 daily close=305.3509521484375
1-8-2020 daily open=305.5496066207918 daily close=306.9783020019531
1-9-2020 daily open=308.59624078058306 daily close=309.0598449707031
1-10-2020 daily open=309.6653735147707 daily close=308.1704406738281
1-13-2020 daily open=308.81386449573563 daily close=310.28985595703125
1-14-2020 daily open=309.8357155822098 daily close=309.8168029785156
1-15-2020 daily open=309.7220834882384 daily close=310.516845703125
1-16-2020 daily open=311.9456106028352 daily close=313.09991455078125
1-17-2020 daily open=313.83783393783926 daily close=314.0743713378906
1-21-2020 daily open=313.080927001925 daily close=313.4593811035156
1-22-2020 daily open=314.3488436155879 daily close=313.497314453125
1-23-2020 daily open=312.8254812932716 daily close=313.8567810058594
1-24-2020 daily open=314.5380256021345 daily close=311.0656433105469
1-27-2020 daily open=305.6347152551311 daily close=306.07940673828125
1-28-2020 daily open=307.5554559419741 daily close=309.28692626953125
1-29-2020 daily open=310.6966045755457 daily close=309.0313720703125
1-30-2020 daily open=306.8931082857648 daily close=310.0343322753906
1-31-2020 daily open=309.3909221661874 daily close=304.40472412109375

Unable to run most algos

Hello, I was trying to use the new preview version of Turning and ran into some issues trying to run the v2 Algos.

  1. Showcase Algo v2 - Seems like only the 60/40 will run under showcase algov2. Here is an example of error from BAA-G4, same or similar error to all others in that folder.

running algorithm Keller's Bold Asset Allocation (BAA-G4)
EXCEPTION: One or more errors occurred. (AlgorithmLoader: algorithm Benchmark_60_40 is ambiguous) at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result()
at TuringTrader.SimulatorV2.TimeSeriesAsset.get_Meta() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\TimeSeries.cs:line 388
at TuringTrader.SimulatorV2.TimeSeriesAsset.get_Description() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\TimeSeries.cs:line 393
at TuringTrader.BooksAndPubsV2.Keller_BAA_Core.b__39_0()
at TuringTrader.SimulatorV2.Algorithm.<>c__DisplayClass71_0.b__0() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 255
at TuringTrader.SimulatorV2.Algorithm.<>c__DisplayClass70_0.<_simLoopOuter>b__0(Double prev) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 226
at TuringTrader.SimulatorV2.Algorithm._simLoop(Func2 innerBarFun, Double init) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 212 at TuringTrader.SimulatorV2.Algorithm._simLoopOuter(Func1 innerBarFun) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 226
at TuringTrader.SimulatorV2.Algorithm.SimLoop(Action barFun) in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader.Simulator\Simulator\v2\Core\Algorithm.cs:line 253
at TuringTrader.BooksAndPubsV2.Keller_BAA_Core.Run()
at TuringTrader.MainWindow.<>c__DisplayClass35_0.<RunButton_Click>g__uiThread|1() in C:\Users\fbert\OneDrive\Documents\TuringTrader\TuringTrader\MainWindow.xaml.cs:line 554
finished algorithm Keller's Bold Asset Allocation (BAA-G4) after 2.5 seconds

  1. Showcase Algo v2 - running Stocks on the Move, just freeze and you have to exit the program and open up again.
  2. Showcase Algo (not v2) - not sure if these are supposed to be backwards compatible, but get the following error when I attempt to run them:

failed to instantiate TuringTrader.Simulator.AlgorithmInfo

  1. Most of the V2 Demo Algos work, but "Portfolios" and Stocks gives this error
    Line 128: CS0103 - The name 'AlgorithmConstants' does not exist in the current context
    Line 129: CS0103 - The name 'AlgorithmConstants' does not exist in the current context
    Line 134: CS0103 - The name 'AlgorithmConstants' does not exist in the current context

  2. WalkforwardOptimizations gives the following error

Line 39: CS0246 - The type or namespace name 'OptimizerParamAttribute' could not be found (are you missing a using directive or an assembly reference?)
Line 39: CS0246 - The type or namespace name 'OptimizerParam' could not be found (are you missing a using directive or an assembly reference?)
Line 58: CS0246 - The type or namespace name 'OptimizerGrid' could not be found (are you missing a using directive or an assembly reference?)

where to see the raw log?

Hi, in my algorithm,

I want to print out some debug info, similar to this one:

Output.WriteLine("Idle Cash = {0:P2}", Cash);

but where I can see the raw log file?

Thanks for the great library!

Build fails

I am trying to build
"Build BooksAndPubs project (will link against the binary version installed)"

And I have the following issues:
Restore completed in 128.29 ms for C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj.
C:\Program Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "TuringTrader.Simulator". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj]
Aeromir_ParkingTrade.cs(56,20): error CS0234: The type or namespace name 'Indicators' does not exist in the namespace 'TuringTrader' (are you missing an assembly reference?) [C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj]
Aeromir_ParkingTrade.cs(57,20): error CS0234: The type or namespace name 'Simulator' does not exist in the namespace 'TuringTrader' (are you missing an assembly reference?) [C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj]
Alvarez_EtfSectorRotation.cs(29,20): error CS0234: The type or namespace name 'Indicators' does not exist in the namespace 'TuringTrader' (are you missing an assembly reference?) [C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj]
Alvarez_EtfSectorRotation.cs(30,20): error CS0234: The type or namespace name 'Simulator' does not exist in the namespace 'TuringTrader' (are you missing an assembly reference?) [C:\Users\TuringTrader\BooksAndPubs\BooksAndPubs.csproj]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.