Class Databank

  • All Implemented Interfaces:
    java.io.Serializable

    public class Databank
    extends java.lang.Object
    implements java.io.Serializable
    Databank is an object that stores generated strategies. This class provides databank management interface - methods to add/get strategies to/from databank,
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Databank​(java.lang.String projectName, java.lang.String databankName, java.lang.String databanksFilePath)
      Instantiates a new databank.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(ResultsGroup resultsGroup, boolean refreshGrid)
      Add ResultsGroup to the databank.
      boolean add​(ResultsGroup resultsGroup, boolean refreshGrid, boolean cleanupOptimizations)
      Adds the.
      void add​(StrategyBase strategy)
      create a ResultsGroup, add strategy into it and add it to the databank.
      void addExtraDatabankChange​(java.lang.String type, java.lang.String extraValue)
      Adds the extra databank change.
      void addListener​(com.strategyquant.tradinglib.databank.IDatabankListener listener)
      Adds the listener.
      void applyFilter​(com.strategyquant.tradinglib.databank.IDatabankFilter filter)
      Apply filter.
      void applyFilter​(com.strategyquant.tradinglib.databank.IDatabankFilter filter, com.strategyquant.tradinglib.databank.IProgressListener maxRecordsListener)
      Apply filter.
      void clearRecords​(boolean freeMemory, boolean sync)
      Clears the list of strategies and frees memory.
      void clearResultsData()
      Clear results data.
      void clearResultsData​(java.util.ArrayList<java.lang.String> strategies)
      Clear results data.
      boolean contains​(java.lang.String resultsName)
      Contains.
      void deleteResultsFile​(ResultsGroup resultsGroup)
      Delete results file.
      void destroyTimers()
      Destroy timers.
      void disableSynchronization()
      Disable synchronization.
      void enableSynchronization()
      Enable synchronization.
      java.util.ArrayList<java.lang.Object[]> getBufferData​(boolean first1000)
      Gets the buffer data.
      org.json.JSONArray getChanges()
      Gets the changes.
      org.jdom2.Element getConfig()
      Gets the config.
      java.lang.String getDatabankFolder()
      Gets the databank folder.
      static org.jdom2.Element getDefaultConfig()
      Gets the default config.
      static java.lang.String getDefaultSyncType()
      Gets the default sync type.
      com.strategyquant.tradinglib.databank.IDatabankFilter getFilter()
      Gets the filter.
      com.strategyquant.tradinglib.gp.FitnessCollectionData getFitnessData()
      Gets the fitness data.
      long getLastChangeTime()
      Gets the last change time.
      ResultsGroup getLocked​(java.lang.String resultsName, java.lang.String lockingTask)
      Gets the locked.
      java.lang.String getName()
      Gets the name.
      double getPercentLoaded()
      Gets the percent loaded.
      int getPosition()
      Gets the position.
      java.lang.String getProject()
      Gets the project.
      java.util.ArrayList<java.lang.String> getRecordKeys()
      Gets the record keys.
      java.util.ArrayList<java.lang.String> getRecordKeys​(java.lang.String baseName)  
      java.util.ArrayList<java.lang.String> getRecordKeysNoLock()
      Gets the record keys no lock.
      java.util.ArrayList<java.lang.String> getRecordKeysNoLock​(java.lang.String baseName)  
      java.util.ArrayList<ResultsGroup> getRecords()
      Gets the records.
      int getRecordsSizeNoLock()
      Gets the records size no lock.
      com.strategyquant.tradinglib.project.StrategySaver getReportSaver()
      Gets the report saver.
      java.lang.String getResultsFilePath​(ResultsGroup resultsGroup)
      Gets the results file path.
      java.lang.String getSyncType()
      Gets the sync type.
      ResultsGroup[] getTopResults()
      Gets the top results.
      com.strategyquant.tradinglib.databank.DatabankTableView getView()
      Gets the view.
      double getWorstFitness()
      Gets the worst fitness.
      boolean isDefault()
      Checks if is default.
      static boolean isDefault​(java.lang.String databankName)
      Checks if is default.
      boolean isFileBased()
      Checks if is file based.
      boolean isLoaded()
      Checks if is loaded.
      boolean isLoading()
      Checks if is loading.
      void loadStrategies​(com.strategyquant.tradinglib.databank.IProgressListener listener)
      Load strategies.
      boolean noActionRunning()
      No action running.
      void notifyListeners​(java.lang.String action)
      Notify listeners.
      void onResultChange​(ResultsGroup resultsGroup)
      On result change.
      void refreshGrid()
      Refresh grid.
      void remove​(java.lang.String resultsName, boolean freeMemory, boolean notifyListeners, boolean sendUIEvent, boolean refreshGrid, boolean removeStockChartsFile, java.lang.String lockingTask)
      Removes the.
      void remove​(java.lang.String resultsName, boolean freeMemory, boolean notifyListeners, boolean refreshGrid, boolean removeStockChartsFile, java.lang.String lockingTask)
      Removes the.
      void removeAll​(boolean freeMemory)
      removes all records from this databank and deletes files.
      void removeFilter()
      Removes the filter.
      void removeListener​(com.strategyquant.tradinglib.databank.IDatabankListener listener)
      Removes the listener.
      void removeNoLock​(java.lang.String resultsName, boolean freeMemory, boolean refreshGrid, boolean removeStockChartsFile, java.lang.String lockingTask)
      Removes the no lock.
      void removeNoLockNoException​(java.lang.String resultsName, boolean freeMemory, boolean refreshGrid, boolean removeStockChartsFile, java.lang.String lockingTask)
      Removes the no lock no exception.
      void rename​(java.lang.String newName)
      Rename.
      void setPosition​(int position)
      Sets the position.
      void setProjectName​(java.lang.String projectName)
      Sets the project name.
      void setSyncType​(java.lang.String type)
      Sets the sync type.
      void setView​(com.strategyquant.tradinglib.databank.DatabankTableView view)
      Sets the view.
      boolean setViewByName​(java.lang.String viewName)
      Sets the view by name.
      int size()
      Size.
      void synchronizeNow()
      Synchronize now.
      void synchronizeNow​(boolean waitUntilFinished)  
      void update​(java.lang.String resultsName, ResultsGroup resultsGroup, boolean refreshGrid, java.lang.String lockingTask)
      Update.
      void updateAllResults()
      Update all results.
      void updateBestResults()
      Update best results.
      void updateBestResults​(ResultsGroup rg)
      Update best results.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • Log

        public static final org.slf4j.Logger Log
        The Constant Log.
      • ACTION_RESULT_ADDED

        public static final java.lang.String ACTION_RESULT_ADDED
        The Constant ACTION_RESULT_ADDED.
        See Also:
        Constant Field Values
      • ACTION_RESULT_REMOVED

        public static final java.lang.String ACTION_RESULT_REMOVED
        The Constant ACTION_RESULT_REMOVED.
        See Also:
        Constant Field Values
      • ACTION_CLEARED

        public static final java.lang.String ACTION_CLEARED
        The Constant ACTION_CLEARED.
        See Also:
        Constant Field Values
      • ACTION_UPDATED

        public static final java.lang.String ACTION_UPDATED
        The Constant ACTION_UPDATED.
        See Also:
        Constant Field Values
      • DefaultMainViewName

        public static final java.lang.String DefaultMainViewName
        The Constant DefaultMainViewName.
        See Also:
        Constant Field Values
      • DefaultPortfolioViewName

        public static final java.lang.String DefaultPortfolioViewName
        The Constant DefaultPortfolioViewName.
        See Also:
        Constant Field Values
      • TIMER_TICKS_FREQUENCY

        public static final int TIMER_TICKS_FREQUENCY
        The Constant TIMER_TICKS_FREQUENCY.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Databank

        public Databank​(java.lang.String projectName,
                        java.lang.String databankName,
                        java.lang.String databanksFilePath)
        Instantiates a new databank.
        Parameters:
        projectName - the project name
        databankName - the databank name
        databanksFilePath - the databanks file path
    • Method Detail

      • getProject

        public java.lang.String getProject()
        Gets the project.
        Returns:
        the project
      • addListener

        public void addListener​(com.strategyquant.tradinglib.databank.IDatabankListener listener)
        Adds the listener.
        Parameters:
        listener - the listener
      • removeListener

        public void removeListener​(com.strategyquant.tradinglib.databank.IDatabankListener listener)
        Removes the listener.
        Parameters:
        listener - the listener
      • loadStrategies

        public void loadStrategies​(com.strategyquant.tradinglib.databank.IProgressListener listener)
                            throws java.lang.Exception
        Load strategies.
        Parameters:
        listener - the listener
        Throws:
        java.lang.Exception - the exception
      • add

        public void add​(StrategyBase strategy)
                 throws java.lang.Exception
        create a ResultsGroup, add strategy into it and add it to the databank.
        Parameters:
        strategy - the strategy
        Throws:
        java.lang.Exception - the exception
      • add

        public boolean add​(ResultsGroup resultsGroup,
                           boolean refreshGrid)
                    throws java.lang.Exception
        Add ResultsGroup to the databank. If max records count is set, ResultsGroup is added only if its rank value is better than the worst result's rank value.
        Parameters:
        resultsGroup - the results group
        refreshGrid - the refresh grid
        Returns:
        true if ResultsGroup was added
        Throws:
        java.lang.Exception - the exception
      • add

        public boolean add​(ResultsGroup resultsGroup,
                           boolean refreshGrid,
                           boolean cleanupOptimizations)
                    throws java.lang.Exception
        Adds the.
        Parameters:
        resultsGroup - the results group
        refreshGrid - the refresh grid
        cleanupOptimizations - the cleanup optimizations
        Returns:
        true, if successful
        Throws:
        java.lang.Exception - the exception
      • remove

        public void remove​(java.lang.String resultsName,
                           boolean freeMemory,
                           boolean notifyListeners,
                           boolean refreshGrid,
                           boolean removeStockChartsFile,
                           java.lang.String lockingTask)
                    throws java.lang.Exception
        Removes the.
        Parameters:
        resultsName - the results name
        freeMemory - the free memory
        notifyListeners - the notify listeners
        refreshGrid - the refresh grid
        removeStockChartsFile - the remove stock charts file
        lockingTask - the locking task
        Throws:
        java.lang.Exception - the exception
      • remove

        public void remove​(java.lang.String resultsName,
                           boolean freeMemory,
                           boolean notifyListeners,
                           boolean sendUIEvent,
                           boolean refreshGrid,
                           boolean removeStockChartsFile,
                           java.lang.String lockingTask)
                    throws java.lang.Exception
        Removes the.
        Parameters:
        resultsName - the results name
        freeMemory - the free memory
        notifyListeners - the notify listeners
        sendUIEvent - the send UI event
        refreshGrid - the refresh grid
        removeStockChartsFile - the remove stock charts file
        lockingTask - the locking task
        Throws:
        java.lang.Exception - the exception
      • removeNoLock

        public void removeNoLock​(java.lang.String resultsName,
                                 boolean freeMemory,
                                 boolean refreshGrid,
                                 boolean removeStockChartsFile,
                                 java.lang.String lockingTask)
                          throws java.lang.Exception
        Removes the no lock.
        Parameters:
        resultsName - the results name
        freeMemory - the free memory
        refreshGrid - the refresh grid
        removeStockChartsFile - the remove stock charts file
        lockingTask - the locking task
        Throws:
        java.lang.Exception - the exception
      • removeNoLockNoException

        public void removeNoLockNoException​(java.lang.String resultsName,
                                            boolean freeMemory,
                                            boolean refreshGrid,
                                            boolean removeStockChartsFile,
                                            java.lang.String lockingTask)
                                     throws java.lang.Exception
        Removes the no lock no exception.
        Parameters:
        resultsName - the results name
        freeMemory - the free memory
        refreshGrid - the refresh grid
        removeStockChartsFile - the remove stock charts file
        lockingTask - the locking task
        Throws:
        java.lang.Exception - the exception
      • update

        public void update​(java.lang.String resultsName,
                           ResultsGroup resultsGroup,
                           boolean refreshGrid,
                           java.lang.String lockingTask)
                    throws java.lang.Exception
        Update.
        Parameters:
        resultsName - the results name
        resultsGroup - the results group
        refreshGrid - the refresh grid
        lockingTask - the locking task
        Throws:
        java.lang.Exception - the exception
      • updateAllResults

        public void updateAllResults()
                              throws java.lang.Exception
        Update all results.
        Throws:
        java.lang.Exception - the exception
      • updateBestResults

        public void updateBestResults()
        Update best results.
      • updateBestResults

        public void updateBestResults​(ResultsGroup rg)
        Update best results.
        Parameters:
        rg - the rg
      • getLocked

        public ResultsGroup getLocked​(java.lang.String resultsName,
                                      java.lang.String lockingTask)
                               throws java.lang.Exception
        Gets the locked.
        Parameters:
        resultsName - the results name
        lockingTask - the locking task
        Returns:
        the locked
        Throws:
        java.lang.Exception - the exception
      • contains

        public boolean contains​(java.lang.String resultsName)
        Contains.
        Parameters:
        resultsName - the results name
        Returns:
        true, if successful
      • getRecords

        public java.util.ArrayList<ResultsGroup> getRecords()
        Gets the records.
        Returns:
        the records
      • getRecordsSizeNoLock

        public int getRecordsSizeNoLock()
        Gets the records size no lock.
        Returns:
        the records size no lock
      • getRecordKeys

        public java.util.ArrayList<java.lang.String> getRecordKeys()
        Gets the record keys.
        Returns:
        the record keys
      • getRecordKeysNoLock

        public java.util.ArrayList<java.lang.String> getRecordKeysNoLock()
        Gets the record keys no lock.
        Returns:
        the record keys no lock
      • getRecordKeysNoLock

        public java.util.ArrayList<java.lang.String> getRecordKeysNoLock​(java.lang.String baseName)
      • getRecordKeys

        public java.util.ArrayList<java.lang.String> getRecordKeys​(java.lang.String baseName)
      • onResultChange

        public void onResultChange​(ResultsGroup resultsGroup)
                            throws java.lang.Exception
        On result change.
        Parameters:
        resultsGroup - the results group
        Throws:
        java.lang.Exception - the exception
      • getResultsFilePath

        public java.lang.String getResultsFilePath​(ResultsGroup resultsGroup)
        Gets the results file path.
        Parameters:
        resultsGroup - the results group
        Returns:
        the results file path
      • deleteResultsFile

        public void deleteResultsFile​(ResultsGroup resultsGroup)
                               throws java.lang.Exception
        Delete results file.
        Parameters:
        resultsGroup - the results group
        Throws:
        java.lang.Exception - the exception
      • getConfig

        public org.jdom2.Element getConfig()
        Gets the config.
        Returns:
        the config
      • getDefaultConfig

        public static org.jdom2.Element getDefaultConfig()
        Gets the default config.
        Returns:
        the default config
      • setView

        public void setView​(com.strategyquant.tradinglib.databank.DatabankTableView view)
        Sets the view.
        Parameters:
        view - the new view
      • getView

        public com.strategyquant.tradinglib.databank.DatabankTableView getView()
        Gets the view.
        Returns:
        the view
      • getBufferData

        public java.util.ArrayList<java.lang.Object[]> getBufferData​(boolean first1000)
        Gets the buffer data.
        Parameters:
        first1000 - the first 1000
        Returns:
        the buffer data
      • removeAll

        public void removeAll​(boolean freeMemory)
                       throws java.lang.Exception
        removes all records from this databank and deletes files.
        Parameters:
        freeMemory - the free memory
        Throws:
        java.lang.Exception - the exception
      • clearRecords

        public void clearRecords​(boolean freeMemory,
                                 boolean sync)
                          throws java.lang.Exception
        Clears the list of strategies and frees memory. Strategy files remain in databank folder if databank type is set to file-based.
        Parameters:
        freeMemory - the free memory
        Throws:
        java.lang.Exception - the exception
      • setViewByName

        public boolean setViewByName​(java.lang.String viewName)
        Sets the view by name.
        Parameters:
        viewName - the view name
        Returns:
        true, if successful
      • noActionRunning

        public boolean noActionRunning()
        No action running.
        Returns:
        true, if successful
      • getName

        public java.lang.String getName()
        Gets the name.
        Returns:
        the name
      • isLoading

        public boolean isLoading()
        Checks if is loading.
        Returns:
        the loading
      • isLoaded

        public boolean isLoaded()
        Checks if is loaded.
        Returns:
        true, if is loaded
      • size

        public int size()
        Size.
        Returns:
        the int
      • getPercentLoaded

        public double getPercentLoaded()
        Gets the percent loaded.
        Returns:
        the percent loaded
      • notifyListeners

        public void notifyListeners​(java.lang.String action)
        Notify listeners.
        Parameters:
        action - the action
      • applyFilter

        public void applyFilter​(com.strategyquant.tradinglib.databank.IDatabankFilter filter)
                         throws java.lang.Exception
        Apply filter.
        Parameters:
        filter - the filter
        Throws:
        java.lang.Exception - the exception
      • applyFilter

        public void applyFilter​(com.strategyquant.tradinglib.databank.IDatabankFilter filter,
                                com.strategyquant.tradinglib.databank.IProgressListener maxRecordsListener)
                         throws java.lang.Exception
        Apply filter.
        Parameters:
        filter - the filter
        maxRecordsListener - the max records listener
        Throws:
        java.lang.Exception - the exception
      • removeFilter

        public void removeFilter()
        Removes the filter.
      • getFilter

        public com.strategyquant.tradinglib.databank.IDatabankFilter getFilter()
        Gets the filter.
        Returns:
        the filter
      • getWorstFitness

        public double getWorstFitness()
        Gets the worst fitness.
        Returns:
        the worst fitness
      • getChanges

        public org.json.JSONArray getChanges()
        Gets the changes.
        Returns:
        the changes
      • getReportSaver

        public com.strategyquant.tradinglib.project.StrategySaver getReportSaver()
        Gets the report saver.
        Returns:
        the report saver
      • getDatabankFolder

        public java.lang.String getDatabankFolder()
        Gets the databank folder.
        Returns:
        the databank folder
      • addExtraDatabankChange

        public void addExtraDatabankChange​(java.lang.String type,
                                           java.lang.String extraValue)
        Adds the extra databank change.
        Parameters:
        type - the type
        extraValue - the extra value
      • getTopResults

        public ResultsGroup[] getTopResults()
        Gets the top results.
        Returns:
        the top results
      • getFitnessData

        public com.strategyquant.tradinglib.gp.FitnessCollectionData getFitnessData()
        Gets the fitness data.
        Returns:
        the fitness data
      • isFileBased

        public boolean isFileBased()
        Checks if is file based.
        Returns:
        true, if is file based
      • getSyncType

        public java.lang.String getSyncType()
        Gets the sync type.
        Returns:
        the sync type
      • setSyncType

        public void setSyncType​(java.lang.String type)
        Sets the sync type.
        Parameters:
        type - the new sync type
      • synchronizeNow

        public void synchronizeNow()
        Synchronize now.
      • synchronizeNow

        public void synchronizeNow​(boolean waitUntilFinished)
      • getDefaultSyncType

        public static java.lang.String getDefaultSyncType()
        Gets the default sync type.
        Returns:
        the default sync type
      • refreshGrid

        public void refreshGrid()
        Refresh grid.
      • setProjectName

        public void setProjectName​(java.lang.String projectName)
        Sets the project name.
        Parameters:
        projectName - the new project name
      • getPosition

        public int getPosition()
        Gets the position.
        Returns:
        the position
      • setPosition

        public void setPosition​(int position)
        Sets the position.
        Parameters:
        position - the new position
      • isDefault

        public boolean isDefault()
        Checks if is default.
        Returns:
        true, if is default
      • isDefault

        public static boolean isDefault​(java.lang.String databankName)
        Checks if is default.
        Parameters:
        databankName - the databank name
        Returns:
        true, if is default
      • rename

        public void rename​(java.lang.String newName)
        Rename.
        Parameters:
        newName - the new name
      • destroyTimers

        public void destroyTimers()
        Destroy timers.
      • getLastChangeTime

        public long getLastChangeTime()
        Gets the last change time.
        Returns:
        the last change time
      • disableSynchronization

        public void disableSynchronization()
        Disable synchronization.
      • enableSynchronization

        public void enableSynchronization()
        Enable synchronization.
      • clearResultsData

        public void clearResultsData()
        Clear results data.
      • clearResultsData

        public void clearResultsData​(java.util.ArrayList<java.lang.String> strategies)
        Clear results data.
        Parameters:
        strategies - the strategies