Integrated Mobile Application Based on Machine Learning for East Africa Stock Market

Regional Integration refers to the process of states coming together to sign agreements where they agree to cooperate in certain areas common to them. The East African Community (EAC) which was founded on November 30, 1999, identified three integration pillars; common Market protocol, customs union and political federation. In attempt to achieve the named pillars, financial markets have been identified as a key driver for common market and customs union. The challenge however is that the East African countries run the most expensive stocks on the African Continent and this has greatly influenced trade volumes and investor appetite. When these markets are integrated it allows collective bargaining thereby increasing their market share across the region other than a given country running its own exchange. This paper presents a software platform that will enable an investor to purchase and sell stocks irrespective of any location in the East African Region thus spur the development of stock market in terms of volume and competitiveness.


INTRODUCTION
The African Union recognizes the East African community as one of the seven regional economic communities in Africa. The 3 pillars of the East African Community are regarded by the partner states as ways to achieve regional development and capital movement among themselves. Reith (2011) point out that EAC is strong on paper but weak in implementation of decisions and policies. This has attracted development partners such as GIZ and World Bank to support the implementation the integration agenda. For example, the World Bank together with the East African community secretariat are implementing a Capital Markets Infrastructure Technology (CMI) that seeks to link the trading platforms of the National Securities Exchange (NSE) that is, Uganda Securities Exchange, Dar es Salaam Stock Exchange and Rwanda Stock Exchange so that they run as a single market in real time (Amb, 2010). Masafumi (2012) denotes the importance of developing stock markets and how wellfunctioning capital markets can accelerate economic growth and alleviate poverty; according to his paper, capital markets promote growth by mobilizing domestic savings and investments through allocating mobilized resources to local companies. More so, deep and liquid local capital markets can lessen vulnerability of an economy to external shocks, by reducing currency and duration mismatches in raising funds. Onyango (2017) also explored how capital markets are a source of finance and have ability to diversify and mitigate moral hazards, spur innovation and usage in employment contracts.

The State of Capital Markets in the Region
The East African countries boasts a total of 110 companies listed on the various stock exchanges across the region, and are the most expensive stocks on the African continent (Goussard, 2018). Critics argue that stock market might not perform well in developing countries and that it might not be feasible for all African countries to promote stock market given the huge costs and poor financial structures (Singh, 1999).
However, a regional market which is the idea of integration expands the scale of and opportunities for financial intermediation. Larger markets make it more cost effective to improve aspects of aspects of financial infrastructure, such as payment systems, regulation and supervisory regimes, introduction of efficiency in financial markets, more so, regional markets are better in terms of coping up with risk; they allow greater diversification of assets and markets for individual investors, compel greater accountability and transparency on the part of the national monetary authorities and finally can lead to harmonization of business practices, laws and institutions, closer to those prevailing in the most developed member states (Itungu, 2012).
In a bid to promote capital markets in the EAC region, there is an already CMI software, also known as the smart routing system that links the clearing and settlements systems of securities trade among the EAC states (Matu, 2020). Much as there are national applications for trading, there is no mobile application at the regional level which allows trade among member states.
The internet penetration in the EAC region has grown tremendously, Sub-Saharan Africa has the fastest growing region, with a Compound Annual Growth Rate (CAGR) of 4.6 % and there has been an additional 167 million subscribers over the period to 2025, there is thus a need for implementing mobile based solutions in the region. A report by Sida (2010) shows that mobile phones in East Africa support bottom-up economic development encourage entrepreneurship and give the poor a voice (Sida, 2010). This paper presents an android application which allows anyone with a mobile phone to purchase the stocks thus enabling even the poor to have shares in companies, and also companies to diversify trading of their stocks among the member states.

RELATED WORK
Millions of applications for stock market exist and support user in multiple ways, e.g., for business planning purposes and even for controlling whole business processes, and creating mobile apps for stock prediction analysis using robust algorithm could be an innovation (Izzah, 2017). Many research groups are exploring stock market trend prediction using social media analytics. Considering the volatility of stock markets, building accurate models for social media is difficult since variation in price depends on multiple factors such as news, social media data, and fundamentals, production of the company, government bonds, historical price and country's economics (Kumar, 2016). Kumar (2016) therefore, attempted to build a model that predicts the future trends of stock market for the next day. This model predicts stock trend movement (trend will be up or down) using historical data and social media data. (Sadhu, 2014). He explored how fuzzy logic, coupled with an android application, and Artificial Intelligence Techniques to predict the stock market movement can be very effective in some case. Izzah (2017) building on the work of Bini (2016) for using data mining techniques (regression and classification) to predict stock market, developed a mobile app for stock prediction using improved multiple linear regression. This paper is an attempt to develop a mobile app for stock prediction using LSTM model.

METHODOLOGY
This section explores the various techniques of developing the platform; in next sections, the paper presents android application development methodology, mobile payments, the payment flow, and how stock prediction was done.

Android Application
Android is a software stack for mobile devices that includes an Operating System (OS), middleware and key applications (Ahmad, 2012). Android application development is the process by which new applications are created for the Android OS (Mukherjee, 2015).

Android is defined as an open, free model and developer's complete platform for the following reasons;
Open Source Platform: This is the competitive advantage Android has over other platforms. Android OS accounts for 84% of the Africa's mobile OS Market (O'Dea, 2021). Thus, the open source nature of Android OS makes it easily accessible by mobile phone manufacturers (Lee, 2011).

Free model Platform:
This is the competitive advantage Android has over other platforms. Android OS accounts for 84% of the Africa's mobile OS Market (O'Dea, 2021). Thus, the open source nature of Android OS makes it easily accessible by mobile phone manufacturers (Lee, 2011).

Developer's complete platform:
Android is a platform that is easier to master for developers having wide-ranging skill levels. App development facilities can utilize Android platform since it uses Java which is a programming language that most developers are intimately familiar with (Lee, 2011).
Android application can either be written in Kotlin or Java languages using the Android Software Development Kit (SDK). The initial SDK was released soon after the open handset alliance in 2008 (Rubin, 2020). Android is based on a modified version of the Linux kernel which consists of a software stack of different layers. Each layer contains a group of various program components. The architecture components work in a way that each underneath layer provides services to the layer just above it as shown in Figure 1.
EA-Trader is a native Android App in the application layer of android architecture; it uses Activity manager that controls different functionalities of the App in Application Framework layer. The App accesses the HttpClient, HttpCore, AndroidAsyncHttp libraries in the Libraries layer to connect to the remote database. In Linux kernel layer, EA-Trader App accesses the Display driver for displaying the application, Process Management and Memory Management for application execution.
For this paper, an android based mobile application was developed using the android studio Integrated Development environment (IDE). The application we came up with has the following modules: Login Module: This consists of the login and the createaccount page along with the database connectivity of both pages. The create-account page is used to create the username and password along with specifying the contacts such as the phone number and email which are used later for the further processes. The login page will verify the entered credentials with the database if matched.
Profile Module: After login, user will come across the profile page; this page will retrieve the list of all shares bought by user from the companies identified within the stock market. At the beginning, user will have no shares listed to this page however, once bought from the companies listed in the market, then they will be displayed.

Stock Market:
Under stock market user will see the list of companies which sell their shares at a specified price, also the user will see the status of each company's shares as compared to previous days. The status is categorized as upward green arrow which stands for rise in price per share, in addition there is red downward arrow status which stands for the fall for the price per share and last but not list is rightward yellow arrow which also stands for the no change in price per share as compared to previous displayed price. User is advised to view the stock market status before buying shares.
Stock Prediction: On this section, user will actually see the projection of each company's price per share. This information will empower user to make decision of which company to invest prior buying shares.

Buy Shares Module:
Here, the user will be enabled to buy shares from companies for investment. Moreover, Airtel Telecom Company (mobile money) is used to improve the transaction process. In addition, the implementation is done through the free API of a company called easy pay. User will be required to use a phone number account with mobile money credit for the purchase of shares.

Sell Shares Module:
On sell shares module, users will be permitted to sell their own shares to companies for profit. Also, a phone number is required while selling the shares.

Mobile Payments
In the payments model, we integrated our application with a Fintech (EasyPay) which has integrations with all the mobile money telecom service providers in Uganda. EasyPay has an online tool that enables account creation; it also offers an Application Program Interface (API) document with valid and working APIs which are used to make payment requests (Muhindo, 2019). I order to integrate EasyPay in the East African member states; the telecom companies only require integration with the EasyPay API (Muhindo, 2019).
The choice of using EasyPay depends on the availability of the open source API and other requirements needed by other telecom companies such as a large amount of Know Your Customer (KYC), Memorandum of Understanding (MoU), and huge amount of float required. There are different ways of integrating payments into mobile applications and using different payment channels such as VISA card, bank transactions and mobile network operators. The East African countries have the highest per capita registered and active mobile money accounts, volume of mobile money transactions and agent network (Groothuizen, 2019). In fact most East Africans use mobile money for most of their online money transfers. We therefore chose to use the mobile telecoms for the payments. The East African region is comprised of several telecom companies that offer mobile money transfers such as MTN, Airtel, Tigo, Safaricom, Vodacom, and many others. There is an existing integration between the different telecommunication companies in the region for instance MTN operates in Uganda and Rwanda, Airtel operates in Uganda, Kenya and Tanzania. Tigo is in Tanzania and Rwanda (Anyanzwa, 2019). This paper explores the possibility for someone to quickly transfer money from their mobile account at the telecom to our platform (EA Trader). The developed platform allows the customer to initialize payment process, and the money reaches our account at the telecoms or aggregator as shown in Figure  3.

The Payments Flow
When making a payment, the application initiates a request in the database using the "initiate EasyPay.php" script to send the data to the database. The data sent includes the  (Smyth, 2020) customer phone number, the numbers of shares, the selected company, and the customer account ID. This transaction gets loaded in the database with a pending status.
The application then loads the receipt page of the app, which shows the customer details of the transaction he/ she intends to make. After the customer is confident with the data displayed then they confirm the payment. The data is sent through a json request to the EasyPay application program interface.
The sample json request object is shown in Table 1.   The response from the API is captured and the status is updated in the database if the transaction is successful. Table  2 shows a sample response from the EasyPay API on a successful transaction.
After the request is sent to the EasyPay API, the EasyPay system logs the transaction on their system and then forwards it to the corresponding telecom company. The telecom company sends a pin prompt to the customer's phone number waiting for them to input their pin code. Once the customer in puts the pin, and the data is received back at the telecom, the telecom will transfer the money from the customer's account and place it on the easy pay account and send a notification back to EasyPay about the transaction.
Thereafter, if EasyPay receives a successful response from the telecom, it then sends a successful response back to our application from the api then we update the status in the database as successful.

Prediction
The aim of this is to predict the future prices of the stocks basing on some history. The dataset being utilised is got from the Nasdaq Stock Market. The data reflected the open, close, high, low, volume and prices of Microsoft, Apple, Facebook, Amazon and Alibaba. The purpose of using Machine learning is due to the nature of our data set which is unstructured in nature, and the traditional methods of analysis like using excel and stata cannot handle this kind of analysis. For the purpose of simulation and analysis, only one company was considered. All the data files was available in a CSV file format which was first read and transformed into a data frame using the pandas library in Python. Analysis was conducted using Jupyter notebook.
Standardization which is a common way of doing scaling was performed by subtracting the mean and dividing by the standard deviation of each feature.30% of the data set was kept for testing, while 70% for training.
There are a number of algorithms designed to perform stock prediction. The most common techniques used for data mining of stock market are clustering and regression (Bini, 2016). Volatility and non-stationarity of stocks determine which type of model is feasible in a time series environment, Ariyo (2014) applied autoregressive integrated moving average (ARIMA) to stock market and the results of the study indicated that ARIMA has a strong potential for short-term prediction and can compete favorably with existing techniques for stock price prediction (Zhan, 2018). However, using ARIMA for long term capability is limited by this volatility and nonstationarity behavior. Current studies now focus on using of Artificial Neural Networks (ANN) to fully model complex realworld data by extracting robust features that capture the relevant information (Zhan, 2018).
Long Short Term Memory (LSTM) which is a variant of RNN was first proposed by (Hochreiter, 1997). Akita (2016) adopted it to predict prices with historical numerical and textual data (Zhan, 2018). LSTM proves to be demonstrating good performances in time series learning as LSTM can maintain contextual information as well as temporal behaviors of events (Q. Zhuge L, 2017). For this study we used LSTM to predict the future price. The developed model was deployed on the mobile app built using android.

RESULTS AND DISCUSSION
The developed RNN model was trained and tested over the data set and it yielded results in Figure 4.
The Model prediction point is the result as predicted by the model, and the true future is the true price value. The proximity of these points tells us how efficient the LSTM is.
The android application with all the combined features was developed and the flow was as shown in Figure 5.
The developed platform (EA-Trader) has a registration page which enables a user to open up an account on the system. The system also has a login page which enables the customer to login in their account on the application and can log out once required. This is necessary for security purposes as user's information regarding their transactions should be kept private. Once a user has logged in, they can buy or sell shares on the platform.
In this paper the alphavantage API, which is an open source API was used by the android application to send data request to the stock market.
When the customer wants to buy shares in a company, the customer goes to the buy shares page, enters their phone number, selects the company from drop-down list and proceeds to the payments mode page where they select the payments mode. A receipt is displayed to the customer and they can go ahead to confirm the payment if they are okay with their selected information.
For a customer to sell shares, they enter their phone number, select company and number of shares and submit on the sale shares page. The share price on the stock market at that time in captured and payment is initiated and stored in the database. The customer views a receipt and once is confident with their selected information they can go ahead to  For the customer to use the prediction functionality, they select the prediction button on their profile page. The prediction model is called from the assets folder in the android system and used to predict the price of the next day.
The application tracks the user's session on login; it also personalizes the displayed data on the customer's profile page. The profile page displays the customer previous transactions. There is also an account page which shows the customers details. The application has a stock market page which shows the current stock market price at that time as of the API. The application also allows the user to change password if they do wish to. The application also has a news page for news on the different stock markets as well as the contact us page which gives information on how to contact support team.

CONCLUSION
This paper was an attempt to improve competitiveness of the East African Stock market by providing a mobile platform which supports cross boarder trader and secondly determining future prices of the stock market. Both the techniques proved to be a potential for the implementation of the EAC integration agenda and development of the stock market with in the region.
In future sentimental analysis could be explored to determine the effect of news on the EAC stock market. Also, a web based platform could be developed as an alternative to cater for all market segments.