---
# System prepended metadata

title: Assetgroup sentiment calculation job

---

# Assetgroup sentiment calculation job


**READER :**

1. Create a new Reader which does the following:
- [ ] Takes AssetGroupID as Input (in bean config), Function ID as input, Frequency (DAILY, FIFTEEN_MIN, etc)
```
<bean id="analyticsReader" class="com.quanthawk.batch.jobs.NewReader" lazy-init="true">
    <constructor-arg type="java.lang.String" name="frequency" value="DAILY"/>
    <constructor-arg type="java.lang.Integer" name="assetGroupId" value="1"/>
    <constructor-arg type="java.lang.String" name="function1" value="SMA_100"/>
    <constructor-arg type="java.lang.String" name="function2" value="PRICE"/>
    <constructor-arg type="java.lang.String" name="NumOfRecords" value="10"/>
</bean>
```
- [ ] Reads the assets in the AssetGroupMapping table.
- [ ] Reads the values from AssetLevelDailyAnalytics (for daily) For each asset and Function and Frequency
- [ ] Returns the records which match the criteria passed to the reader



---

**PROCESSOR :**


**Different processor types :**

1. ***CompareFunctionsProcessor*** : Compares Function-1 vs Function-2. e.g. 
- SMA_100 > PRICE. 
- SMA_100 < SMA_50. 
- SMA_50 >= SMA_100_PREV. 

```
<bean id="AgSentimentProcessor" class="com.quanthawk.batch.jobs.CompareFunctionsProcessor" lazy-init="true">
    <constructor-arg type="java.lang.String" name="function1" value="SMA_100"/>
    <constructor-arg type="java.lang.String" name="function2" value="PRICE"/>
    <constructor-arg type="java.lang.String" name="condition" value=">"/>
</bean>

```
2. ***CompareThresholdProcessor*** : Compares Function-1 vs a Fixed number. e.g. 
- SMA_100 > 50. 
- SMA_50 < 80. 
- SMA_100 >= 30. 

```
<bean id="AgSentimentProcessor" class="com.quanthawk.batch.jobs.CompareThresholdProcessor" lazy-init="true">
    <constructor-arg type="java.lang.String" name="function1" value="SMA_100"/>
    <constructor-arg type="java.lang.Integer" name="threshold" value="50"/>
    <constructor-arg type="java.lang.String" name="condition" value=">"/>
</bean>

```

**Processor Logic :**

- [ ] Processor receives the Function values (could be one/two functions) for a number of assets (the assets in the AssetGroup that the reader passes)
- [ ] For **each date** in the input list, maintain counters for 1) number of assets that satisfy the processor condition 2) number of assets that fail the conditions 3) number of assets where the data is null for one of the functions and therefore the comparison did not happen 4) number of assets which have data for that date.
- [ ] Processor returns this information for each date.
- [ ] It is important that processor is very efficient. It should complete in one/two seconds ideally.


---

**WRITER :**

- [ ] SYSOUT the data for now. I will create a new table where the data should be inserted.


# -- 04th Aril - 2020

1. Change the reader to read the data of all dates in one shot or may be N (e.g. 100) dates at a time but for all Assets and all Functions. Basically read data in chunks to avoid consuming too much memory. The count N (e.g. 100) should be a parameter passed to the reader through batch job config XML.

2. The reader should return the data of all the dates to the processor in one shot (not one date at a time).

3. Implement the new processor com.quanthawk.batch.jobs.SentimentProcessor
- [ ] The new processor should read the table SentimentDefinition where IsActive = true
- [ ] For each SentimentId returned by the query, create an object of the ImplementationClass column and pass the parameters of the SentimentId to the constructor.
- [ ] Execute the process method of each processor/SentimentID in a loop. Collect the outputs of all the Sentiment processors and pass the map of maps (outer map key = SentimentId, Inner map key = date)
- [ ] The processor sould return the values as objects containing the four variables i.e. noOfAssetSatisfyingCondition, noOfAssetNotSatisfyingCondition, noOfTotalComparableAssets, noOfNonComparedAssets.

5.  The writer should loop over the two levels of map and print something like:

**Sentiment Id = 1 , Name = SMA(100) > SMA(50)**
    Date 1 : noOfAssetSatisfyingCondition = x, noOfAssetNotSatisfyingCondition = y, noOfTotalComparableAssets = z, noOfNonComparedAssets = m
    Date 2 : noOfAssetSatisfyingCondition = x, noOfAssetNotSatisfyingCondition = y, noOfTotalComparableAssets = z, noOfNonComparedAssets = m
    ...
    ...

**Sentiment Id = 1 , Name = SMA(100) > SMA(50)**
    Date 1 : noOfAssetSatisfyingCondition = x, noOfAssetNotSatisfyingCondition = y, noOfTotalComparableAssets = z, noOfNonComparedAssets = m
    Date 2 : noOfAssetSatisfyingCondition = x, noOfAssetNotSatisfyingCondition = y, noOfTotalComparableAssets = z, noOfNonComparedAssets = m
    ...
    ...
