|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import plotly.express as px |
|
|
import numpy as np |
|
|
|
|
|
st.title('Gold Price Analysis') |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Gold Price CSV", type='csv') |
|
|
|
|
|
if uploaded_file is not None: |
|
|
df = pd.read_csv(uploaded_file) |
|
|
df['Date'] = pd.to_datetime(df['Date'], format='%Y%m%d') |
|
|
df = df.sort_values('Date') |
|
|
|
|
|
st.dataframe(df) |
|
|
|
|
|
|
|
|
fig1 = px.line(df, x='Date', y='Price', title='Gold Price over Time') |
|
|
st.plotly_chart(fig1) |
|
|
|
|
|
|
|
|
fig2 = px.line(df, x='Date', y='Return', title='Daily Return (Absolute Change)') |
|
|
st.plotly_chart(fig2) |
|
|
|
|
|
|
|
|
df['P_prev'] = df['Price'].shift(1) |
|
|
df['nominal_return'] = df['Return'] / df['P_prev'] |
|
|
i = 0.43 |
|
|
d = (1 + i)**(1/365) - 1 |
|
|
df['real_return'] = ((1 + df['nominal_return']) / (1 + d) - 1) * 100 |
|
|
|
|
|
|
|
|
fig3 = px.line(df, x='Date', y='real_return', title='Daily Real Return (%)') |
|
|
st.plotly_chart(fig3) |
|
|
else: |
|
|
st.write("Please upload a CSV file.") |