You decided to start a FinTech consultancy firm, and you want to make a difference by working on projects with high social impact in local communities. They want to create a tool that helps their members enhance their financial health. The Chief Technology Officer (CTO) of the credit union asked you to develop a prototype application to demo in the next credit union assembly.
The credit union board wants to allow the union's members to assess their monthly personal finances, and also be able to forecast a reasonably good retirement plan based on cryptocurrencies, stocks, and bonds.
In this project I focused on using APIs as part of the technical solution - to create two financial analysis tools.
The first will be a personal finance planner that will allow users to visualize their savings composed by investments in shares and cryptocurrencies to assess if they have enough money as an emergency fund.
The second tool will be a retirement planning tool that will use the Alpaca API to fetch historical closing prices for a retirement portfolio composed of stocks and bonds, then run Monte Carlo simulations to project the portfolio performance at 30 years. You will then use the Monte Carlo data to calculate the expected portfolio returns given a specific initial investment amount.
This project will utilize two APIs:
-
The Alpaca Markets API will be used to pull historical stocks and bonds information.
-
The Alternative Free Crypto API will be used to retrieve Bitcoin and Ethereum prices.
In this portion of the project I created a personal finance planner application, under the following assumptions:
-
The average household income for each member of the credit union is $12,000.
-
Every union member has a savings portfolio composed of cryptocurrencies, stocks and bonds:
-
Assume the following amount of crypto assets:
1.2
BTC and5.3
ETH. -
Assume the following amount of shares in stocks and bonds:
50
SPY (stocks) and200
AGG (bonds).
-
-
Create two variables called
my_btc
andmy_eth
. Set them equal to1.2
and5.3
, respectively. -
Use the
requests
library to fetch the current price in US dollars of bitcoin (BTC
) and ethereum (ETH
) using the Alternative Free Crypto API endpoints provided in the starter notebook. -
Parse the API JSON response to select only the crypto prices and store each price in a variable.
-
Compute the portfolio value of cryptocurrencies and print the results
The current value of your 1.2 BTC is $31254.00 The current value of your 5.0 ETH is $1820.98
-
Create two variables named
my_agg
andmy_spy
and set them equal to200
and50
, respectively. -
Set the Alpaca API key and secret key variables, then create the Alpaca API object using the
tradeapi.REST
function from the Alpaca SDK. -
Format the current date as ISO format. You may change the date set in the starter code to the current date.
-
Get the current closing prices for
SPY
andAGG
using Alpaca'sget_barset()
function -
Pick the
SPY
andAGG
close prices from the Alpaca'sget_barset()
DataFrame response and store them as Python variables -
Compute the value in dollars of the current amount of shares and print the results
The current AGG closing price is: $107.1 The current SPY closing price is $452.11
In this section, I assessed the financial health of the credit union's members.
-
Create a variable called
monthly_income
and set its value to12000
. -
To analyze savings health, create a DataFrame called
df_savings
with two rows. Store the total value in dollars of the crypto assets in the first row and the total value of the shares in the second row. -
Use the
df_savings
DataFrame to plot a pie chart to visualize the composition of personal savings.
- Use
if
conditional statements to validate if the current savings are enough for an emergency fund. An ideal emergency fund should be equal to three times your monthly income.
In this section, I used the Alpaca API to fetch historical closing prices for a retirement portfolio and then used the MCForecastTools toolkit to create Monte Carlo simulations to project the portfolio performance at 30
years.
-
Use the Alpaca API to fetch five years historical closing prices for a traditional
40/60
portfolio using theSPY
andAGG
tickers to represent the60%
stocks (SPY
) and40%
bonds (AGG
) composition of the portfolio. -
Configure and execute a Monte Carlo Simulation of
500
runs and30
years for the40/60
portfolio. -
Plot the simulation results and the probability distribution/confidence intervals.
-
Fetch the summary statistics from the Monte Carlo simulation results
-
Given an initial investment of
$20,000
, calculate the expected portfolio return in dollars at the95%
lower and upper confidence intervals.
There is a 95% chance that an initial investment of $20000 in the portfolio over the next 30 years will end within in the range of $62784.26 and $792020.15
- Calculate the expected portfolio return at the
95%
lower and upper confidence intervals based on a50%
increase in the initial investment.
There is a 95% chance that an initial investment of $45000.0 in the portfolio over the next 30 years will end within in the range of $141264.59 and $1782045.33