Commit Graph

83 Commits

Author SHA1 Message Date
Michael Handschuh 27b34a4274 Add IAlgorithm.OnEndOfTimeStep to batch universe changes
We had an issue with the data feed picking up universe/security changes
too quickly, thereby preventing user code from being able to configure the
security object properly. Specifically, users were having an issue setting
the data normalization mode of options and underlying equity securities. By
the time the user code had set the data mode, the data feed had already
created a subscription and began processing it, so the changes were never
seen in the data feed.

This change moves all security/universe changes into pending lists and at
the end of the time step applies those changes. Security objects are still
added directly to the SecurityManager for instance access, but we delay in
adding the security to the universe and the universe to the UniverseManager.
Once added to the universe manager, an event is fired and the data feed will
process the new subscriptions.
2018-03-20 10:10:29 -04:00
AlexCatarino d5deabcb29 Fixes AlgorithmPythonWrapper.InsightsGenerated
This event was not properly wrapped.
When `IAlgorithm.InsightsGenerated` is set in `IAlphaHandler`, it should be directed to the base algorithm, whereas it was set to a null variable.
2018-03-19 11:15:57 +00:00
AlexCatarino 4e3577939d Refactors AlgorithmPythonWrapper
Move the logic of importing the module into AlgorithmPythonWrapper where it is wrapped.
Throws an exception if the script does not have a class that inherits from either QCAlgorithm not QCAlgorithmFramework.
Adds a check for OnData being defined in the module. If not, OnData from the base class will not be called (it causes stack overflow otherwise)
2018-03-12 23:36:39 +00:00
Michael Handschuh 6b239674e2 Renames Alpha -> Insight
The term 'alpha' is used to describe the entire algorithm. Therefore, 'alpha'
produces insights. From this we have things like IAlphaModel, which is the model
defining how insights are produced. We have IAlphaHandler, which defines how the
insights from a single 'alpha' (the algorithm) are managed, analyzed, and stored.
Types closer to the individual prediction level, such as InsightDirection, or
InsightScore relate directly to exactly 1 insight. The distinction between the
two became more clear as we developed the insights API, and from that effort it
was decided to harmonize alpha/insight terminology across the various QC systems.
2018-03-09 16:12:56 -05:00
AlexCatarino 1e594749a9 Fixes multiple OnEndOfDay error message
The error message it was used to bypass the the error logging has been changed from `takes exactly x arguments (y given)` to `takes x positional argument but y were given`.
2018-03-02 18:37:12 +00:00
AlexCatarino 9dfc8ee3a0 Adds PythonSlice static constructor
With this constructor, SetConverter method, that was not respecting Lean pattern, is removed. The initialization of _converter field is done once the type is loaded.
2018-02-12 16:23:23 +00:00
AlexCatarino cff1243b86 Creates wrapper for Slice (python custom data)
Python algorithms with custom data requires an operation that converts a dictionary key into a attribute. In the current implementation the Slice object was converted into a python dictionary. This was not optimal, since we just need to make this conversion when the value of a key in the Slice is accessed.
This implementation proposes a wrapper for the Slice object, PythonSlice, that would just perform the operation described above when needed.
2018-02-12 15:49:09 +00:00
AlexCatarino 2cfe77d10e Fixes OnWarmupFinished not firing in python algorithms 2018-01-15 18:43:38 +00:00
Stefano Raggi 89a59351cd Add OnWarmupFinished method to QCAlgorithm
This method is being added to allow algorithms to complete initialization tasks that cannot be executed during Initialize, such as cancelling existing open orders in live trading.
This method will be called only once, when the warmup task is complete.

Closes #1043
2018-01-15 13:46:30 +01:00
Michael Handschuh b4b3aae112 Rename Signal -> Alpha
Whoa... I think I got everything :)
2017-12-15 18:24:58 -05:00
Michael Handschuh d8ef289c9b Add IAlgorithm.IsFrameworkAlgorithm and BacktestingResut.IsFrameworkAlgorithm
Flag indicates whether or not the algorithm is a framework algorithm.
2017-12-14 19:43:26 -05:00
Michael Handschuh c879f4ee83 Chart average signal scores daily 2017-12-12 15:57:00 -05:00
Michael Handschuh 39f5080a40 Rename framework events to OnFramework<Event>
This more closely follows existing conventions.
2017-12-08 12:04:53 -05:00
Michael Handschuh c093b45319 Add IAlgorithm.SignalsGenerated event
This event will fire each time step that generates signals and will
include all signals generated by the algorithm at that time step.
2017-12-08 10:07:54 -05:00
Michael Handschuh 14a2a09581 Add explicit methods for updating framework models
IAlgorithm.FrameworkOnData is used to pulse models with new data each time step
IAlgorithm.FrameworkOnSecuritiesChanged is used to pulse models with security changes

These two functions need to be separate to ensure that if we add an indicator during
the securities changed event that it will get the data from the current time step.
This forces us to call the securities changed event before we invoke the consolidators
for the current time step.
2017-12-08 10:07:54 -05:00
AlexCatarino 70d67e3fb3 Fixes OnEndOfDay exceptions in python algorithms
The engine creates schedule events that call OnEndOfDay() and OnEndOdDay(Symbol) for every security. If just one of these method overloads is defined in the python script, the call of the other will throw a exception due different parameter count.
In this case, we will disregard this exception and throw those that may happen in the method implementation body.
2017-12-06 18:43:23 +00:00
AlexCatarino fb12e79a1c Changes PandasConverter accessibility levels
Private field PandasConverter _converter is now public property PandasConverter.
With this change, we will be able to use it in QuantBook.
2017-12-04 21:38:39 +00:00
AlexCatarino dfffbd6953 Adds IFutureChainProvider interface with base implementations
- Move BacktestingFutureChainProvider provider to Lean.Engine.DataFeeds along with its options equivalent.

- EmptyFutureChainProvider: provider that returns an empty list of symbols
- CachingFutureChainProvider: implements caching by date
- BacktestingFutureChainProvider: provider that gets chain from local files
- LiveFutureChainProvider: provider that gets chain from external source (empty list of symbols for now)
2017-12-04 14:16:59 +00:00
AlexCatarino 2ff636869c Fixes summary of members in python wrapper classes
Summary of members in python wrapper classes where pointing to other methods for reference when they should have a meaningful description to be used in documentation
2017-11-16 14:00:22 +00:00
AlexCatarino 96fee374fb Fixes OnMarginCall runtime error in python
After we included the method name in the error message, OnMarginCall method was throwing a runtime error when that method was not defined in the script where it sould simply be directed to the method in the base class.
2017-10-09 11:35:44 +01:00
Michael Handschuh 7c0a0c4698 Set algorithm name in setup handler
When using the console setup handler, the algorithm's type name
will be used as an identifier.
2017-10-06 16:23:38 -04:00
Michael Handschuh ecd92462da Clean white space 2017-10-06 16:23:37 -04:00
AlexCatarino 6624e18f08 Fixes OnMarginCall for python algorithms
Due to pythonnet limitations, the list of SubmitOrderRequest could not be modified by OnMarginCall event handler. We now get a new list from that method and update the list in the wrapper.
2017-09-22 20:50:49 +01:00
Stefano Raggi e379457757 Refactor option chain providers
- Moved provider implementations out of brokerages into their own classes
- Removed DefaultOptionChainProvider
- Added BacktestingOptionChainProvider and LiveOptionChainProvider
- Moved SetOptionChainProvider call from Engine to setup handlers
2017-08-02 22:43:15 +02:00
Stefano Raggi 8fdb79e578 Add OptionChainProvider to IAlgorithm/QCAlgorithm
- SetOptionChainProvider method
- OptionChainProvider property
2017-08-02 22:43:12 +02:00
AlexCatarino 46ead54f79 Implements Quandl support for Python
Implements Quandl support for Python.
It was not possible to derive from Quandl in order to select the column. If the data did not have "close", it would thrown an exception since it would look for this work in a dictionary.
It is now possible to select the column.
See example QuandFuturesDataAlgorithm.py
2017-07-27 00:18:08 +01:00
Stefano Raggi e7172a6841 Update QCAlgorithm.RuntimeStatistics to be a ConcurrentDictionary
This change enables SetRuntimeStatistics to be called from event handlers fired by other threads (for example in the OnOrderEvent with IB)
2017-07-20 20:39:51 +02:00
AlexCatarino 3c23759efd Implements History Requests returning pandas.DataFrame
Algorithms written in python can access to new overloads for the QCAlgorithm.History method that returns a dictionary with pandas.DataFrame
2017-07-06 15:09:59 +01:00
AlexCatarino 6242706342 Modifies python example algorithms to show implicit convertion benefits 2017-06-15 18:40:34 +01:00
AlexCatarino 0c28813e43 Fixes exception at OnMarginCall in Python
When OnMarginCall is not defined at the python script, pythonnet cannot find the method in the base class.
Instead of throwing the exception and exiting, we direct the event to the method in the base class.
2017-06-13 18:27:11 +01:00
AlexCatarino 919e0225aa Removes Impromptu.ActLike call at the python wrapper
Calling Impromptu.ActLike<IAlgorithm> to make the python object acts like a IAlgorithm caused multiple AlgorithmPythonWrapper objects running in parallel to hold the same python object. That call was removed and instead we access the python object directly.

- Removes AlgorithmPythonUtil.py and add its code directly in AlgorithmPythonWrapper.cs

- Clean up: removes all references to IronPython and ImpromptuInterface
2017-06-02 17:54:54 +01:00
Stefano Raggi 6d47ab94b8 Add AlgorithmSettings class and IAlgorithm.Settings property 2017-05-22 20:50:23 +02:00
Stefano Raggi b657c0d663 Fix speed issue in AlgorithmPythonWrapper 2017-05-21 22:40:55 +02:00