How to Transfer Cash Between Strategies

#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 DynamicAllocationAPI import *
from AssemblyDynamicAllocation_3000_ImportedScripts import *
# ---------------------------------------------------------------
#endregion

## <summary>
## Dynamic allocation scripts are used for systematically redistributing cash between desktop strategies based on their performance or some other heuristic.
## </summary>
class MyDynamicAllocation(ScriptCode.DynamicAllocationScriptBase): # 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 and can be selected for optimization.
    ## </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.

    ## --------------------------------------------------------------------------------------------------
    ## <param name="day" type="C_Weekday" default="SUNDAY">The day of the week the transfer will take place.</param>
    ## <param name="sourceStrategyNumber" type="Integer" default="0">The number of the strategy from which cash will be deducted. This strategy must be active.</param>
    ## <param name="destinationStrategyNumber" type="Integer" default="1">The number of the strategy that will receive the cash. This strategy must be active.</param>
    ## <param name="amount" type="Double" default="100">The amount of cash to transfer.</param>
    def OnInitialize(self,day,sourceStrategyNumber,destinationStrategyNumber,amount):
        # Set the script parameters.
        self._day = day
        self._sourceStrategyNumber = sourceStrategyNumber
        self._destinationStrategyNumber = destinationStrategyNumber
        self._amount = amount
        # Set time zone to local time zone.
        DateTimeSetLocalZone()
    #endregion

    #region OnDynamicAllocation
    ## <summary>
    ## This function is called daily at the desktop EOD time,
    ## at which point it may redistribute cash between desktop strategies (see the StrategyTransfer function).
    ## </summary>
    def OnDynamicAllocation(self):
        # Check whether this is the day for rebalancing.
        if DateTimeDayOfWeek(DateTimeCurrent()) == self._day:
            # Transfer the amount from the source strategy to the destination strategy.
            StrategyTransferCash(self._sourceStrategyNumber, self._destinationStrategyNumber, self._amount, "Transferring cash between strategies.")
    #endregion

    #region OnShutdown
    ## <summary>
    ## This function is called when the script is shutdown.
    ## </summary>
    def OnShutdown(self):
        # OnShutdown Content
        pass
    #endregion