In the Crypto Tax Chatbot post, I talked about the volatility of the trading market. To address the issue of effectively mitigating volatility, below is an app built on the efficient frontier concept introduced in a post last November.
YouTube Tutorial
The video that goes through the below content in streaming format is as follows:
Below is the file structure for this app with the file relationships on the right.
The stock data for this app is from Alpha Vantage API as shown below:
FileImport.kt - import component
Allows users to input ticker symbols, start, and end dates for data to be fetched
Uses SharedViewModel to share data identified by a Uniform Resource Identifier
Uses file_input.xml as the layout for importing files
FilePreview.kt - preview component
Receive and display selected ticker symbol’s data from Uniform Resource Identifier from SharedViewModel and plot efficient frontier
Uses file_preview.xml for layout for the preview
VolatilityFragment.kt - volatility and portfolio holdings picker component
Allows users to pick a desired volatility level and return a specific portfolio composition with the chosen volatility that maximizes return
Uses data from SharedViewModel to handle slider input, portfolio weight calculation, as well as indication of chosen portfolio’s volatility and return on the efficient frontier
Uses fragment_chat.xml as layout for the chat window
file_input.xml
Layout for FileImport.kt fragment
file_preview.xml
Layout for FilePreview.kt
fragment_volatility.xml
Layout for VolatilityFragment.kt including efficient frontier plot with marker to highlight volatility and return of chosen portfolio composition
StockDataResponse.kt
Defines data classes to represent the response from the stock data API
AggregatedStockData.kt
Defines data classes that includes aggregated stock data for a specific date with the date itself and the prices of different stocks on that date.
SectionsPagerAdapter.kt
Adapter for swiping page function in MainActivity
Create the functionalities of ‘FileImport’, ‘FilePreview’, and ‘VolatilityFragment’ based on the selected tab.
SharedViewModel.kt
The view model that’s shared across FileImport, FilePreview, and VolatilityFragment
Manage data related to stock symbol, stock data, efficient frontier, and portfolio holdings weights.
MainActivity.kt
Main activity of the app
Uses activity_main.xml as the main layout for the activity
Uses SectionsPagerAdapter to provide the fragments for different sections of the user interface
Communicates with SharedViewModel to share data across fragments
activity_main.xml
Layout for MainActivity.kt, including ViewPager2 for the app’s swiping pages and the tabs on the top of the app
Below is the apk file for this app for anyone interested in giving it a try.
One of the innate characteristics of numbers is that they stick firmly in the brain like they’ve been superglued. And certain numbers lodge in your memory and remain there forever. If you’re over 30, there’s a good chance that you still remember the telephone number of your childhood home. Or the license plate number on your first car. Certain numbers sail into the brain and anchor; others glide past unnoticed. Numbers also sneak unnoticed into the judgements you make every day. they become a yardstick, whether you want them or not.