a
To upload files, please first save the app
import streamlit as st
from datetime import datetime
st.title("Gold Investment Calculator")
# Get user input for investment date
st.header("Investment Details")
investment_date = st.date_input("Date of Gold Investment", datetime.now())
gold_rate_on_investment = st.number_input("Gold Rate per Tola on Investment Date (PKR)", min_value=0.0, value=150000.0)
amount_spent = st.number_input("Amount of Money Spent on Gold (PKR)", min_value=0.0, value=100000.0)
# Calculate tola bought
tola_bought = amount_spent / gold_rate_on_investment
# Get user input for today's date and gold rate
st.header("Today's Details")
today_date = st.date_input("Today's Date", datetime.now())
current_gold_rate = st.number_input("Current Gold Rate per Tola (PKR)", min_value=0.0, value=200000.0)
# Calculate current value of gold
current_value_of_gold = tola_bought * current_gold_rate
# Calculate total profit earned till date
total_profit_till_date = current_value_of_gold - amount_spent
# Calculate daily profit (assuming investment was made at least one day ago for calculation)
# This is a simplified daily profit, a more robust solution would consider fractional days or specific market hours.
if today_date > investment_date:
days_since_investment = (today_date - investment_date).days
if days_since_investment > 0:
daily_profit = total_profit_till_date / days_since_investment
else:
daily_profit = 0.0 # If investment date is today, no daily profit yet
else:
daily_profit = 0.0 # If today's date is before or same as investment date, no daily profit
st.write("---")
st.write("### Investment Summary")
st.write(f"Investment Date: {investment_date.strftime('%Y-%m-%d')}")
st.write(f"Gold Rate on Investment Date: PKR {gold_rate_on_investment:,.2f} per Tola")
st.write(f"Amount Spent on Gold: PKR {amount_spent:,.2f}")
st.write(f"Gold Purchased: {tola_bought:,.4f} Tola(s)")
st.write("---")
st.write("### Current Value and Profit")
st.write(f"Today's Date: {today_date.strftime('%Y-%m-%d')}")
st.write(f"Current Gold Rate: PKR {current_gold_rate:,.2f} per Tola")
st.write(f"Current Value of Your Gold: PKR {current_value_of_gold:,.2f}")
st.write(f"**Total Profit Earned Till Date: PKR {total_profit_till_date:,.2f}**")
st.write(f"**Daily Profit Earned (Approx.): PKR {daily_profit:,.2f}**")
st.write("---")
st.write("### How it works")
st.write("""
This calculator helps you track your gold investment:
- It first calculates the amount of gold (in Tola) you purchased based on your investment amount and the gold rate on that day.
- Then, it determines the current value of your gold using the current gold rate.
- **Total Profit Earned Till Date** is the difference between the current value of your gold and the initial amount you spent.
- **Daily Profit Earned** is an approximate calculation of your total profit divided by the number of days since your investment.
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?