Skip to content

A full stack Android personal finance and wealth management app built in Android Studio with Java, XML, Firebase Authentication and Realtime Database, Stanford CoreNLP, AnyChart JavaScript library, Google Cloud Functions written in Node.js, and the Plaid, Dialogflow, News, and Twitter (via Twitter4J) APIs.

Notifications You must be signed in to change notification settings

ramanv0/CapitalGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 

Repository files navigation

CapitalGuard

A full stack Android personal finance and wealth management app built in Android Studio with Java, XML, Firebase Authentication and Realtime Database, Stanford CoreNLP, AnyChart JavaScript library, Google Cloud Functions written in Node.js, and the Plaid, Dialogflow, News, and Twitter (via Twitter4J) APIs. CapitalGuard allows you to connect all of your financial accounts into one space to get a complete picture of your financial health, help you gain control of your spending, and track and optimize your investments.

Key Features

  • Email and password based authentication with custom UI using the Firebase Authentication SDK
  • Client-side integration to the Plaid API via Plaid Link that handles credential validation, authenticates users' bank account information, and connects users' financial accounts to Plaid
  • Alert users about suspicious activity or overspending if the transaction data retrieved using the Plaid API exceeds their spending limit
  • Data analysis and interactive visualization on users' spending data retrieved with the Plaid API using custom adapters, various UI layouts, and the AnyChart JavaScript library
  • Financial assistant chatbot with a custom chat UI built using the Dialogflow API and Google Cloud Functions written in Node.js that query users' financial data from the Plaid API stored in the Firebase database
  • Provide advice to users about potential investment opportunities based on sentiment analysis performed on news articles retrieved using the News API and Twitter tweets retrieved using the Twitter API (via the Twitter4J Java library) using the Stanford CoreNLP library

Technologies Used

Languages

  • Java
  • XML
  • JavaScript (Node.js)
  • Regex

Back end

  • Firebase Realtime Database
    • CapitalGuard uses Google's Firebase Realtime Database to store and sync user data as JSON in realtime. To use the Firebase Database, first add Firebase to your cloned version of CapitalGuard by following this guide. Then, install and setup the Realtime Database SDK using this reference.

APIs

  • Plaid API

    • The following Plaid API product endpoints were used to build CapitalGuard (Note: all Plaid API endpoint requests return standard JSON responses):
      • Institutions: retrieve data (e.g. the institution's id, name, supported Plaid products, logo, etc.) about supported financial institutions
      • Account: fetch account information (e.g. the accounts's id, name, balance, type, etc.) and schemas (the account, currency code, and investment transaction types and corresponding subtypes recognized by Plaid)
      • Token: obtain a link_token to initialize Plaid Link, which is the client-side component that the user interacts with in order to connect their financial accounts with the Plaid API. Once Link is initialized and the user has successfully created an Item (Note: Item is a Plaid term for a login at a financial institution), it will return a public_token through an onSuccess callback that can be exchanged for a Plaid API access_token. The access_token must be obtained in order to call Plaid API endpoints and retrieve information about an Item.
      • Transactions: receive paginated user-authorized transaction data for credit, depository, and loan-type accounts
      • Auth: retrieve and verify bank account and identification numbers (e.g. routing numbers), and high-level account auth data
      • Balance: obtain real-time balance data for each of an Item's financial accounts
      • Identity: retrieve and verify the user's identity (name, address, phone number, email) against obtained bank account information
      • Assets: access the user's financial information to create and retrieve Asset Reports that contain detailed information about the user's assets and transactions, which can be used for loan underwriting
      • Investments: get user-authorized stock position and transaction data from the user's investment accounts
    • To use the Plaid API in CapitalGuard, you will need to receive API keys by signing up here. Once you have signed up, you will have access to two API keys: client_id and secret. You can find your Plaid API keys here. Then, in MainActivityJava.java, you must set the value of clientUserId in the createLinkToken method to your client_id and insert your client_id and secret as the first and second arguments of clientIdAndSecret, respectively, in the createPlaidClient method. You will also see that there are three different environments in which you can use the Plaid API: Sandbox, Development, and Production. CapitalGuard was built in the Sandbox environment, which gives you access to test credentials and life-like data.
      • Sandbox environment simple test credentials -> username: user_good, password: pass_good, pin: credential_good (when required). You can learn more about Sandbox test credentials here.
    • The Plaid API was installed in CapitalGuard with the following Gradle dependencies:
    implementation 'com.plaid.link:sdk-core:3.2.6'
    
    implementation 'com.plaid:plaid-java:8.1.0'
    
  • Dialogflow API

    • CapitalGuard uses the Dialogflow API to build a personal finance assistant that is able to answer users' questions about their financial health based on their financial data retrieved via the Plaid API and stored in the Firebase database.
    • Since CapitalGuard uses a custom-built, in-app conversation platform, and not one of Dialogflow's integrations, I had to write code that directly interacts with the end-user. I also had to directly and asynchronously interact with the Dialogflow API for each conversational turn in order to send end-user expressions to Dialogflow and receive information about intent matches. You can learn more about the processing flow when interacting with the Dialogflow API here.
    • To use the Dialogflow API in CapitalGuard, you will need to set up a Google Cloud Platform (GCP) project and authentication. To do so, follow the steps in the GCP Setup quickstart: It will guide you through all of the steps required to start using the Dialogflow API, such as creating a Dialogflow project, GCP billing, enabling the Dialogflow API and audit logs, setting up authentication with service accounts and keys (for more information about authentication, you can also read this), initializing the Google Cloud SDK (the Cloud SDK provides many useful tools for managing resources hosted on Google Cloud), and installing the Dialogflow API client library.
      • CapitalGuard uses the most common option for calling GCP APIs (in this case, the Dialogflow API): Google supported client libraries. There are two other options for calling the Dialogflow API: REST and gRPC (you can read more about them here). The Dialogflow API client library was installed in CapitalGuard with the following Gradle dependencies:
      implementation platform('com.google.cloud:libraries-bom:20.8.0')
      
      implementation 'com.google.cloud:google-cloud-dialogflow'
      
      If you choose to setup your CapitalGuard project with Maven or sbt, you can learn how to install the Dialogflow API here.
    • After you setup your GCP project and authentication, you will need to build agents, which are virtual agents that are trained to handle expected conversations with end-users, using the Dialogflow Console. You can learn more about how Dialogflow agents work here.
      • To build an agent:
        1. Go to your Dialogflow Console and sign in
        2. Click "Create Agent" in the left sidebar menu
        3. Enter the requested information (agent's name, language, time zone)
        4. Select "Create a new Google project"
        5. Click "Create"
    • Once you created your agent, you will need to define and train intents to categorize end-user intentions for each conversation turn. The combined intents of a successful agent should be able to handle a complete conversation with the end-user. When the end-user writes a question to CapitalGuard's personal financial assistant bot, Dialogflow matches the question to the best intent in your agent.
      • To define a basic intent:

        1. Click the add intent button in the left sidebar menu
        2. Enter the name of your intent in the "Intent name" field
        3. Click "Add training phrases" in the "Training Phrases" section, and enter your training phrases
          • Training phrases are example phrases for what the end-user might ask. In the process of intent classification, Dialogflow matches the end-user's question to the intent whose training phrase(s) it most resembles. It is best that you define a handful (~10-20, depending on the complexity of your intent) of training phrases to improve the accuracy of the intent classification; however, Dialogflow utilizes machine learning to expand your list with other similar phrases.
        4. In the "Responses" section, enter the response you want your financial assistant bot to return to the end-user if the intent is matched in the Text Response section
          • Responses are not limited to text: You can have a speech or visual response, too.
          • Responses can provide the end-user with a one-time answer, ask for more information, or terminate the conversation.
        5. Click "Save" and wait until the agent training is complete
        6. Test your intent using the chatbot simulator in the right sidebar

        To learn more about Dialogflow intents (Action, Parameters, Contexts, and Events), go here.

  • News API

    • Note: requests to the REST News API return JSON search results for current and historic news articles
    • CapitalGuard uses the News API to retrieve news articles from sources and blogs across the web. Sentiment analysis is then performed on the articles to provide users with advice on potential investment opportunities.
    • To use the News API in CapitalGuard, you will need to register for a News API key, which are free while you are in development, here.
    • Once you are registered and have obtained a News API key, follow the Get started guide.
      • The News API offers two main endpoints:
        1. /everything: Search for articles on the web that mention a keyword or phrase
        2. /top-headlines: Get the current top headlines for a country, category, or publisher
      • CapitalGuard uses the /everything endpoint––endpoint (a)––in order to find news articles that mention the ticker symbol of the stock that the user is interested in buying and wants to receive advice for. To learn more about the request parameters and JSON response object of the /everything endpoint, you can read this.
    • To authenticate the News API in CapitalGuard, in the getNewsSentiment method in AdviceActivity.java, you need to set the apiKey constructor argument of the instantiated NewsApiClient object called newsApiClient to your News API key.
    • To make requests and receive responses from the News API, you need to install the News API Java client library (SDK), which allows CapitalGuard to use the News API without having to make HTTP requests directly.
      • The News API Java client library was installed in CapitalGuard by adding:
        1. The below JitPack repository to the project's root build.gradle file:
          allprojects {
            repositories {
               ...
               maven { url 'https://jitpack.io' }
            }
          }
          
        2. The below dependency to the project's Gradle dependencies:
          implementation 'com.github.KwabenBerko:News-API-Java:1.0.0'
          
    • To learn more about News API usage, you can go here.
  • Twitter API

    • CapitalGuard uses the Twitter API to programmatically retrieve tweets. Sentiment analysis is then performed on the tweets to provide users with advice on potential investment opportunities.
    • To get access to the Twitter API, you need to:
      1. Apply and receive approval for a developer account
        • The Twitter API offers two product tracks: Standard or Academic Research. CapitalGuard uses the Standard Twitter API product track, which is the default track for most developers. You can apply for the Standard product track here.
        • Once your developer account is approved, you can create a Standard project by following this guide and an associated developer App that will provide you a set of keys and tokens that you will use to authenticate all requests to the Twitter API.
      2. Save your developer App's keys and tokens
        • Within your developer App, you will be able to find or generate:
          • API Key: The "username" that will allow you to make Twitter API requests from CapitalGuard
          • API Secret (Key): The "password" that will allow you to make Twitter API requests from CapitalGuard
          • Access Token & Access Token Secret: Tokens that represent CapitalGuard's Twitter account and allow you to make Twitter API requests on behalf of the account
      3. Set up your Twitter API access
        • There are currently four Twitter API access methods (you can learn more about them here): CapitalGuard uses the Standard v1.1 access, which requires you to authenticate your Twitter API requests with keys and tokens from within the CapitalGuard developer app.
      4. Make requests to the Twitter API to retrieve tweets
        • Because CapitalGuard is built in Java, and the Twitter API currently maintains only JavaScript, Python, and Ruby official libraries and SDKs, I chose to use the Twitter4J community-supported Java library to integrate the Twitter API into CapitalGuard, as it implements all features of the Standard v1.1 API. Other community-supported Java libraries for the Twitter API include twitter-client and JTwitter. To learn more about how to make requests to and receive responses from the Twitter API via the Twitter4J library, go to the [Twitter4J section](TODO: Add link) of this README file.

Important Libraries

  • AnyChart JS

    • CapitalGuard uses the AnyChart JavaScript library to create interactive visualizations of users' spending data retrieved using the Plaid API, which help users gain a better understanding of their spending behavior.
    • The AnyChart library was installed in CapitalGuard with the following Gradle dependency:
    implementation 'com.github.AnyChart:AnyChart-Android:0.0.3'
    
    • Alternatively, you can download the latest AAR file and copy it into the libs folder of the CapitalGuard project. To learn how to do this in Android Studio, you can read the "JAR/ARR File" section of AnyChart's documentation here.
  • Stanford CoreNLP

    • CapitalGuard uses the Stanford CoreNLP library to perform sentiment analysis on news articles, retrieved using the News API, and Twitter tweets, retrieved using the Twitter API via the Twitter4J Java library, to provide users with advice on potential investment opportunities.
    • Specifically, CapitalGuard utilizes the following linguistic annotation capabilities of the CoreNLP pipeline, which is the centerpiece of CoreNLP that takes in raw text, runs a series of NLP annotators on the raw text, and outputs full annotation objects:
      • Tokenization
        • Tokenization is the process of splitting raw text into smaller units called tokens, which are defined by an elaborate collection of rules (based on UD 2.0 specifications). In general, however, CoreNLP tokens represent individual words. For example, "CapitalGuard is a personal finance app" would be tokenized into "CapitalGuard", "is", "a", "personal", "finance", "app", ".".
      • Sentence splitting
        • Sentence splitting is the process of separating text into sentences based on a set of rules, which you can learn more about here.
      • Parts of speech (POS)
        • POS tagging assigns part-of-speech labels to tokens (e.g. whether they are verbs or nouns). For example, in the sentence "CapitalGuard helps its users save money", "CapitalGuard" would be assigned the NNP (Proper noun, singular) tag, "helps" would be assigned the VBZ (Verb, present tense, third person singular) tag, "its" would be assigned the PRP$ (Possessive pronoun, also PP$) tag, "users" would be assigned the NNS (Noun, plural) tag, "save" would be assigned the VB (Verb, base form) tag, and "money" would be assigned the NN (Noun, singular) tag. To learn more about POS tag sets, you can go here.
      • Constituency and dependency parsing
        • Constituency parsing provides a full syntactic analysis and phrase-structure tree parse of sentences, which is saved in TreeAnnotation as binary parse trees. Since a conversion from constituency parses to dependency parses is available in CoreNLP for the English language, a dependency representation is also created by the constituency conversion. Dependency parsing in CoreNLP produce three types of outputs: Basic dependencies (saved in BasicDependenciesAnnotation), enhanced dependencies (saved in EnhancedDependenciesAnnotation), and enhanced++ dependencies (saved in EnhancedPlusPlusDependenciesAnnotation).
      • Sentiment
        • The CoreNLP library provides a sentiment tool that implements Socher et al’s sentiment analysis model. The sentiment tool attaches the analyzed sentence's binarized tree (created with the parsing annotator) to the CoreMap: This process adds annotations from RNNCoreAnnotations, which indicate the predicted class and sentiment scores for each subtree, to the nodes of the tree. You can learn more about Stanford CoreNLP's sentiment tool here.
    • The Stanford CoreNLP library was installed in CapitalGuard with the following Gradle dependencies:
    implementation ('edu.stanford.nlp:stanford-corenlp:4.2.2')
    
    implementation ('edu.stanford.nlp:stanford-corenlp:4.2.2:models')
    
  • Twitter4J

    • CapitalGuard uses the Twitter4J library to integrate CapitalGuard with the Standard v1.1 Twitter API in order to programmatically retrieve tweets.

    • To use the Twitter API via Twitter4J in CapitalGuard, in the getTweetSentiment method in AdviceActivity.java, you will need to set the argument of:

      • setOAuthConsumerKey method to your Twitter API Key
      • setOAuthConsumerSecret method to your Twitter API Secret (Key)
      • setOAuthAccessToken method to your Access Token
      • setOAuthAccessTokenSecret method to your Access Token Secret

      (Note: If you are unsure about where to find the above Twitter API keys and tokens, make sure you read the Twitter API section of this README file.)

    • The Twitter4J library was installed in CapitalGuard with the following Gradle dependency:

    implementation 'org.twitter4j:twitter4j-core:4.0.7'
    
    • Alternatively, I could have downloaded and added the twitter4j-core-4.0.7.jar file to CapitalGuard's classpath.
    • To learn more about how the Twitter4J library implements Standard v1.1 Twitter API features, you can go here.
  • Material Design Components (MDC)

    • CapitalGuard uses Google's MDC library for Android to access Material Components––such as buttons, date pickers, and dialogs––which help build an intuitive UI.

    • The MDC library for Android was installed in CapitalGuard by adding:

      1. Google's Maven Repository to CapitalGuard's build.gradle with google()
        allprojects {
          repositories {
            google()
            ...
          }
        }
      
      1. The following Gradle dependency:
      implementation 'com.google.android.material:material:<version>'
      

      Note: Make sure that you are using AppCompatActivity; otherwise, your Material Components will not work correctly.

    • To get access to the latest component styles and theme-level attributes, CapitalGuard's app theme inherits from the following Material Components theme:

    android:theme="@style/Theme.MaterialComponents.NoActionBar"
    
    • You can find the full list of Material Component themes here.

API and Library Diagram

CapitalGuardDiagram

Installation

Clone this repository and import it into Android Studio:

git clone [email protected]:ramanv0/CapitalGuard.git

Running CapitalGuard

In Android Studio:

  1. Select Run -> Run 'app' (or Debug 'app') from the menu bar
  2. Select the device you wish to run the app on and click 'OK'

About

A full stack Android personal finance and wealth management app built in Android Studio with Java, XML, Firebase Authentication and Realtime Database, Stanford CoreNLP, AnyChart JavaScript library, Google Cloud Functions written in Node.js, and the Plaid, Dialogflow, News, and Twitter (via Twitter4J) APIs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published