#region Namespaces
# ---------- DON'T REMOVE OR EDIT THESE LINES -------------------
# These lines are required for integrating Python with our .NET platform.
import clr
clr.AddReference("Tickblaze.Model")
import ScriptCode
from OptimizationAlgorithmAPI import *
from AssemblyOptimizationAlgorithm_3000_ImportedScripts import *
# ---------------------------------------------------------------
#endregion
## <summary>
## Optimization Algorithm scripts are used to control the optimization process.
## During optimization the desktop and its strategies will be backtested repeatedly with different optimization vectors (script parameter values) as selected by the Optimization Algorithm script.
## </summary>
class MyOptimizationAlgorithm(ScriptCode.OptimizationAlgorithmScriptBase): # NEVER CHANGE THE CLASS NAME
#region Variables
# Variables Content
#endregion
#region OnInitialize
## <summary>
## This function is used for accepting the script parameters and for initializing the script prior to all other function calls.
## Once the script is assigned to a desktop, its parameter values can be specified by the user.
## </summary>
## --------------------------------------------------------------------------------------------------
## INSTRUCTIONS - PLEASE READ CAREFULLY
## --------------------------------------------------------------------------------------------------
## YOU MUST SET A PARAM TAG FOR EACH PARAMETER ACCEPTED BY THIS FUNCTION.
## ALL PARAM TAGS SHOULD BE SET IN THE 'OnInitialize' REGION, RIGHT ABOVE THE 'OnInitialize' FUNCTION.
## THE ORDER OF THE TAGS MUST MATCH THE ORDER OF THE ACTUAL PARAMETERS.
## REQUIRED ATTRIBUTES:
## (1) name: The exact parameter name.
## (2) type: The type of data to collect from the user:
## Set to "Integer" when the data type is 'int'
## Set to "IntegerArray" when the data type is 'int[]'
## Set to "DateTime" when the data type is 'long' (The 'long' data type can only be used for date/time representation)
## Set to "DateTimeArray" when the data type is 'long[]' (The 'long' data type can only be used for date/time representation)
## Set to "Boolean" when the data type is 'bool'
## Set to "BooleanArray" when the data type is 'bool[]'
## Set to "Double" when the data type is 'double'
## Set to "DoubleArray" when the data type is 'double[]'
## Set to "String" when the data type is 'string'
## Set to "StringArray" when the data type is 'string[]'
## OPTIONAL ATTRIBUTES:
## (3) default: The default parameter value is only valid when the type is Integer, Boolean, Double, String or an API Type.
## (4) min: The minimum parameter value is only valid when the type is Integer or Double.
## (5) max: The maximum parameter value is only valid when the type is Integer or Double.
## EXAMPLE: <param name="" type="" default="" min="" max="">Enter the parameter description here.</param>
## --------------------------------------------------------------------------------------------------
def OnInitialize(self):
# OnInitialize Content
pass
#endregion
#region OnSelectNextOptimizationVectors
## <summary>
## This function is called in order to select the next optimization vectors to be processed.
## The function may be called multiple times in a row before the OnUpdateOptimizationVector function is called.
## </summary>
## <returns type="IntegerArray">The indexes of the next optimization vectors to process.</returns>
def OnSelectNextOptimizationVectors(self):
# Create a list to hold the indexes of the next optimization vectors to process.
optimizationVectors = []
# Iterate through all optimization vector indexes.
for optimizationVectorIndex in range(OptimizationVectorCount()):
# Check to ensure the optimization vector index has not already been processed.
if not OptimizationVectorIsProcessed(optimizationVectorIndex):
# Add the current optimization vector index to the list of optimization vectors that need to be processed.
optimizationVectors.append(optimizationVectorIndex)
# Return the list of optimization vectors that need to be processed.
return optimizationVectors
#endregion
#region OnGetMaxVectors
## <summary>
## This function is called to get the number of optimization vectors that the algorithm will
## select and run if the optimization process runs to completion.
## </summary>
## <returns type="Integer">The maximum number of optimization vectors to be run.</returns>
def OnGetMaxVectors(self):
# Return the total number of optimization vector indexes.
return OptimizationVectorCount()
#endregion
#region OnUpdateOptimizationVector
## <summary>
## This function is called to notify the optimization algorithm that a vector has been processed.
## </summary>
## <param name="vectorIndex" type="Integer">The vector index of the optimization vector that has been processed</param>
def OnUpdateOptimizationVector(self, vectorIndex):
# OnUpdateOptimizationVector Content
pass
#endregion
#region OnShutdown
## <summary>
## This function is called when the script is shutdown.
## </summary>
def OnShutdown(self):
# OnShutdown Content
pass
#endregion