HeaderSIS.jpg

Difference between revisions of "IS480 Team wiki: 2016T1 Charlies-Angels-Algorithm"

From IS480
Jump to navigation Jump to search
Line 93: Line 93:
 
<p>
 
<p>
 
On a particular date & time, cronjob (a process by Linux) will automatically execute a script file that contains a java command. The java command will run the class upon executing and the following code will run. <br/>
 
On a particular date & time, cronjob (a process by Linux) will automatically execute a script file that contains a java command. The java command will run the class upon executing and the following code will run. <br/>
<ol>
+
*Loop the list of symbols
<li>Loop the list of symbols </li>
+
*For each symbol, access the website URL
<li>For each symbol, access the website URL. </li>
+
**If unable to access website URL, use user agent/proxy
<li>Select the code pattern that we have identified to crawl. </li>
+
*Select the code pattern that we have identified to scrape
<li>Retrieve the texts that were retrieved. </li>
+
*Process the texts that were scrapped
<li>Initialize an object class that stores all the retrieved information. </li>
+
*If text is not what we wanted, ignore it.
<li>Add the object class into an array list. </li>
+
*If text is what we wanted,
<li>Pass the array list to a data access object class. </li>
+
**Initialise an object class that stores all the retrieved information
<li>Loop the array list and adds all the information into the database. </li>
+
**Add the object class into an array list
</ol>
+
**Pass the array list to a data access object class
 +
**Loop the array list and add all the information into the database
 
<br/>
 
<br/>
 
This pseudo code will run for each information that needs to be crawled/scraped off the website. <br/>
 
This pseudo code will run for each information that needs to be crawled/scraped off the website. <br/>

Revision as of 12:35, 28 September 2016


Charlies Angels Logo.png


Charlies Angels Home.png  HOME

 

Charlies Angels About Us.png  ABOUT US

 

Charlies Angels Project Overview.png  PROJECT OVERVIEW

 

Charlies Angels Project Management.png  PROJECT MANAGEMENT

 

Charlies Angels Project Documentation.png  DOCUMENTATION

 
X-Factor Project Description & Motivation Charlies Angels Current Stage.png Algorithm Scope Architecture & Technologies

Pseudo Codes

Pseudo Codes

The following CPF Calculations are a new feature that is a never before seen form of calculation in the industry, where we take into account CPF and Housing Loan information to better help the User plan its investment strategy in order to retire comfortably at his/her goals.

CPF Calculations

  • 1. Retrieve all variables from cpf.csv
  • 2. Loop through all the portfolio that the user has and calculate the dividend yield amount and realise profit for every year since the creation of each portfolio.
  • 3. Retrieve user’s CPF variables from database
  • 4. Calculate amount needed from current age to death age by looping current age to death age.
    • a. For each year, multiply inflation rate with target pension.
    • b. Sum them up and you get the amount needed from current to death age.
  • 5. Next, calculate the total amount of money in ordinary and special account when retirement account opens. This is done by looping from current age to open retirement account.
    • a. For each age, check if the age is below 35/45/50 and multiply by the respective percentage as different age has different contribution.
    • b. While looping, the amount of house loan needed to pay per month is subtracted from ordinary account.
    • c. In addition, ordinary, special and medisave accounts are multiplied by their respective interest rate.
    • d. As the amount of monthly salary that can be contributed to CPF is capped at 6000, a check has to be done to make sure that the maximum contribution to CPF is capped.
    • e. In the event that medisave hits the minimum cap needed, which is 49800 as of 2016, the rest of the contribution to medisave will be flowed over to special account. However, if the amount of money in special account has hit the FRS sum, which is 161000 as of 2016, the rest of the contribution to medisave will be flowed over to ordinary account.
  • 6. The user’s savings in bank is also looped from current age to retirement age to calculate the interest rate. The amount of money is multiplied by the bank’s interest rate each year.
  • 7. At age 55, retirement account is opened.
    • a. The amount of money in retirement account is calculated by adding the amount of money in special and ordinary account.
    • b. A condition is done to check if the user has hit the minimum amount of BRS/FRS in the retirement account.
      • i. If the user has enough money to hit BRS but not FRS, any amount more than BRS sum will be transferred over to his/her bank account.
      • ii. If the user has enough money to hit FRS, any amount more than FRS sum will be transferred over to his/her bank account.
      • iii. In the event that the user does not have enough money for both BRS/FRS, nothing will happen and life goes on.
  • 8. Next, a loop is used to calculate the amount of years that the user’s money in both CPF and bank account can last.
    • a. This is to calculate how many years the user’s money can last if he/she chose not to do anything about it besides working till retirement.
  • 9. Lastly, loop from open retirement account age to pay out age. This is to calculate the amount of money in retirement age with interest rate. It is done by multiplying the amount of money in retirement account with retirement account interest rate.
  • 10. After all the calculations, a crawling is done to obtain STI 10 years return.
    • a. The returns allow the user to know how much he/she has to invest in STI in order to achieve his/her retirement goals.

For more information such as the variables involved in these calculation, please view our document here: Pseudo Code for CPF Calculations


Scheduler (Data Crawling)

On a particular date & time, cronjob (a process by Linux) will automatically execute a script file that contains a java command. The java command will run the class upon executing and the following code will run.

  • Loop the list of symbols
  • For each symbol, access the website URL
    • If unable to access website URL, use user agent/proxy
  • Select the code pattern that we have identified to scrape
  • Process the texts that were scrapped
  • If text is not what we wanted, ignore it.
  • If text is what we wanted,
    • Initialise an object class that stores all the retrieved information
    • Add the object class into an array list
    • Pass the array list to a data access object class
    • Loop the array list and add all the information into the database

This pseudo code will run for each information that needs to be crawled/scraped off the website.
As we need to modify a file called crontab, the following statements have to be added into the file.
  1. 0 0 1 4 * XX (yearly task)
  2. */5 9-16 * * XX (five minutes’ task)
  3. 0 0 1 3/3 * XX (quarterly task)
  4. 0 5 * * * XX (daily task)

^ Where XX is the path/location of the script

For more information such as the pattern recognition that the system utilizies, please view our document here: Pseudo Code for Scheduler (Data Crawling)

Formula List

Formula List

During the course of development for this project, the team has been exposed to numerous formulas that are required for the calculations of certain attributes in a User's portfolio. The two highlights for us are:

  • Average Annual Return
  • Year to Date Return

The following sub-sections would explain on how we achieve the formula for the two:

Average Annual Return

[(Total Value Sold + Total Current Value – Total Value Bought/Total Value Bought +1) ^ 12/n-1] * 100
This formula represents the Average return of investment in a year. And the formula is calculated using Geometric Average.

Year to Date Return

Total Value of Stocks Sold + Total Current Value – Total Value of Stocks bought on first trading day of the year + sumOfYearToDateDividend / Total Value of Stocks bought on first trading day of the year * 100
YTD return refers to the amount of profit made by an investment since the first day of the calendar year.


More formulas and explanations can be found at this following document: Charlies Angels Formula List

Geometric Average

There is known to be two forms of calculation that can be taken into consideration which are namely Arithmetic Average and Geometric Average. Upon extensive research, for the goal of achieving accuracy so as to aid the user with making more informed choices. The team has decided to adopt Geometric Average for all of its calculations.

Explanation of Geometric Average is as follows:
Suppose you have invested your savings in the stock market for five years. If your returns each year were 90%, 10%, 20%, 30% and -90%, what would your average return be during this period? Well, taking the simple arithmetic average, you would get an answer of 12%. Not too shabby, you might think.

However, when it comes to annual investment returns, the numbers are not independent of each other. If you lose a ton of money one year, you have that much less capital to generate returns during the following years, and vice versa. Because of this reality, we need to calculate the geometric average of your investment returns in order to get an accurate measurement of what your actual average annual return over the five-year period is.

To do this, we simply add one to each number (to avoid any problems with negative percentages). Then, multiply all the numbers together, and raise their product to the power of one divided by the count of the numbers in the series. And you're finished - just don't forget to subtract one from the result!

That's quite a mouthful, but on paper it's actually not that complex. Returning to our example, let's calculate the geometric average: Our returns were 90%, 10%, 20%, 30% and -90%, so we plug them into the formula as [(1.9 x 1.1 x 1.2 x 1.3 x 0.1) ^ 1/5] - 1. This equals a geometric average annual return of -20.08%. That's a heck of a lot worse than the 12% arithmetic average we calculated earlier, and unfortunately it's also the number that represents reality in this case.